Update org-roam-find-file to use title

This commit is contained in:
Jethro Kuan
2020-02-10 14:03:24 +08:00
parent bfc8bef7f6
commit bb85ad1976

View File

@ -192,14 +192,17 @@ If `ABSOLUTE', return the absolute file-path. Else, return the relative file-pat
(concat org-roam-zettel-indicator id))))) (concat org-roam-zettel-indicator id)))))
;;; Finding org-roam files ;;; Finding org-roam files
(defun org-roam-find-file (id) (defun org-roam-find-file ()
"Find and open file with id `ID'." "Find and open an org-roam file."
(interactive (list (completing-read "File: " (interactive)
(mapcar #'org-roam--get-id (let* ((completions (mapcar (lambda (file)
(org-roam--find-all-files))))) (list (org-roam--get-title-or-id file) file))
(let ((file-path (org-roam--get-file-path id t))) (org-roam--find-all-files)))
(unless (file-exists-p file-path) (title-or-id (completing-read "File: " completions))
(make-empty-file file-path)) (file-path (cadr (assoc title-or-id completions))))
(unless file-path
(let ((id (read-string "Enter new file id: ")))
(setq file-path (org-roam--get-file-path id t))))
(find-file file-path))) (find-file file-path)))
;;; Building the org-roam cache (asynchronously) ;;; Building the org-roam cache (asynchronously)
@ -544,6 +547,7 @@ This needs to be quick/infrequent, because this is run at
(with-current-buffer (window-buffer) (with-current-buffer (window-buffer)
(when (and (get-buffer org-roam-buffer) (when (and (get-buffer org-roam-buffer)
(buffer-file-name (current-buffer)) (buffer-file-name (current-buffer))
(file-exists-p (file-truename (buffer-file-name (current-buffer))))
(not (string= org-roam-current-file (not (string= org-roam-current-file
(file-truename (buffer-file-name (current-buffer)))))) (file-truename (buffer-file-name (current-buffer))))))
(org-roam-update (file-truename (buffer-file-name (window-buffer))))))) (org-roam-update (file-truename (buffer-file-name (window-buffer)))))))