(feat): rename file on title change (#1073)

Adds `org-roam-title-change-hook`. This now contains two functions:

1. `org-roam--update-links-on-title-change`: updates the link
description of all files that link to the current file.
2. `org-roam--update-file-name-on-title-change`: updates the current
buffer's filename to reflect the updated title.
This commit is contained in:
Jethro Kuan
2020-08-27 22:13:23 +08:00
committed by GitHub
parent f8c8fcee6b
commit a6aabf4038
3 changed files with 82 additions and 38 deletions

View File

@ -461,22 +461,24 @@ connections, nil is returned."
(org-roam-db--insert-headlines headlines))))
(defun org-roam-db--update-file (&optional file-path)
"Update Org-roam cache for FILE-PATH."
(when (org-roam--org-roam-file-p file-path)
(let ((buf (or (and file-path
(find-file-noselect file-path t))
(current-buffer))))
(with-current-buffer buf
(org-with-wide-buffer
(emacsql-with-transaction (org-roam-db)
(org-roam-db--update-meta)
(org-roam-db--update-tags)
(org-roam-db--update-titles)
(org-roam-db--update-refs)
(when org-roam-enable-headline-linking
(org-roam-db--update-headlines))
(org-roam-db--update-links)))
(org-roam-buffer--update-maybe :redisplay t)))))
"Update Org-roam cache for FILE-PATH.
If the file does not exist anymore, remove it from the cache.
If the file exists, update the cache with information."
(setq file-path (or file-path
(buffer-file-name (buffer-base-buffer))))
(cond ((not (file-exists-p file-path))
(org-roam-db--clear-file file-path))
((org-roam--org-roam-file-p file-path)
(with-current-buffer (find-file-noselect file-path t)
(org-with-wide-buffer
(emacsql-with-transaction (org-roam-db)
(org-roam-db--update-meta)
(org-roam-db--update-tags)
(org-roam-db--update-titles)
(org-roam-db--update-refs)
(when org-roam-enable-headline-linking
(org-roam-db--update-headlines))
(org-roam-db--update-links)))))))
(defun org-roam-db-build-cache (&optional force)
"Build the cache for `org-roam-directory'.