第一个函数是搜索文件夹下特定标题的文件,第二个函数为什么获取不到callback里的page值?
(defun gk-roam--search-title (dir regexp callback)
(let* ((name (generate-new-buffer-name " *gk-roam-rg*"))
(process (start-process
name name "rg" "-l"
regexp
(expand-file-name dir)
"-g" "!index.org*"))
(sentinal
(lambda (process event)
(if (string-match-p (rx (or "finished" "exited"))
event)
(if-let ((buf (process-buffer process)))
(with-current-buffer buf
(let ((results (split-string (buffer-string) "\n\n")))
(funcall callback (remove "" results))))
(error "Gk-roam’s rg process’ buffer is killed"))
(error "Gk-roam’s rg process failed with signal: %s"
event)))))
(set-process-sentinel process sentinal)))
(defun gk-roam--get-page (title)
"Get page accroding to title."
(unless (executable-find "rg")
(user-error "Cannot find program rg"))
(let (page)
(gk-roam--search-title
gk-roam-root-dir
(format "^ *#\\+TITLE: *%s *$" title)
(lambda (file)
(setq page (string-trim (file-name-nondirectory (car file)) nil "\n"))))
page))