(feat): remove file store-link function override (#1155)

Previously we had overwritten the Org's store link function for files,
to create IDs if the point was under the headline. This has several
issues:

1. It becomes impossible to store a link to the file using `org-store-link`
2. This override is global across Org, although we had a guard in
`org-roam-store-link`
3. IDs are created during an org-capture, because org-capture calls `org-store-link`

This is unnecessary. Org provides `org-id-store-link` instead for this
purpose. Instead, we advice `org-id-new`, to queue the file for a DB
update if an ID was created.
This commit is contained in:
Jethro Kuan
2020-09-30 15:27:25 +08:00
committed by GitHub
parent 30d52e5508
commit 93d8c477fe
2 changed files with 27 additions and 32 deletions

View File

@ -456,18 +456,21 @@ 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)
(org-roam--with-temp-buffer file-path
(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))))))
(if (not (file-exists-p file-path))
(org-roam-db--clear-file file-path)
;; save the file before performing a database update
(when-let ((buf (find-buffer-visiting file-path)))
(with-current-buffer buf
(save-buffer)))
(org-roam--with-temp-buffer file-path
(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'.