(fix): Fix chronology issue between renaming notes and updating links (#1517)

This commit is contained in:
Leo Vivier
2021-05-12 09:06:11 +02:00
committed by GitHub
parent 02e35e3b01
commit f754160402
5 changed files with 31 additions and 10 deletions

View File

@ -227,7 +227,8 @@ Template string :\n%v")
:head "#+title: ${title}\n#+roam_key: ${ref}"
:unnarrowed t))
"The Org-roam templates used during a capture from the roam-ref protocol.
Details on how to specify for the template is given in `org-roam-capture-templates'."
Details on how to specify for the template is given in
`org-roam-capture-templates'."
:group 'org-roam
;; Adapted from `org-capture-templates'
:type

View File

@ -101,7 +101,8 @@ so that multi-directories are updated.")
Update the database immediately upon file changes.
`idle-timer'
Updates the database if dirty, if Emacs idles for `org-roam-db-update-idle-seconds'."
Updates the database if dirty, if Emacs idles for
`org-roam-db-update-idle-seconds'."
:type '(choice (const :tag "idle-timer" idle-timer)
(const :tag "immediate" immediate))
:group 'org-roam)

View File

@ -67,7 +67,7 @@ during an `org-roam-capture'."
(defface org-roam-dailies-calendar-note
'((t :inherit (org-roam-link) :underline nil))
"Face for dates with a daily-note in the calendar"
"Face for dates with a daily-note in the calendar."
:group 'org-roam-faces)
;;; _

View File

@ -48,7 +48,7 @@
(declare-function org-roam-format-link "org-roam")
(defcustom org-roam-link-auto-replace t
"When non-nil, replace Org-roam's roam links with file or id links whenever possible."
"When non-nil, replace Org-roam's roam links with file/id equivalents."
:group 'org-roam
:type 'boolean)

View File

@ -259,7 +259,8 @@ Function should return a filename string based on title."
)
"Characters to trim from Unicode normalization for slug.
By default, the characters are specified to remove Diacritical Marks from the Latin alphabet."
By default, the characters are specified to remove Diacritical
Marks from the Latin alphabet."
:type '(repeat character)
:group 'org-roam)
@ -305,7 +306,9 @@ The currently supported symbols are:
:group 'org-roam)
(defcustom org-roam-enable-headline-linking t
"Enable linking to headlines, which includes automatic :ID: creation and scanning of :ID:s for org-roam database."
"Enable linking to headlines.
This includes automatic :ID: creation and scanning of :ID:s for
org-roam database."
:type 'boolean
:group 'org-roam)
@ -994,13 +997,28 @@ Return nil if the file does not exist."
(file (plist-get (cdr (assoc ref completions)) :path)))
(org-roam--find-file file)))
(defun org-roam--org-roam-buffer-p (&optional buffer)
"Return t if BUFFER is accessing a part of Org-roam system.
If BUFFER is not specified, use the current buffer."
(let ((buffer (or buffer (current-buffer)))
path)
(with-current-buffer buffer
(and (derived-mode-p 'org-mode)
(setq path (buffer-file-name (buffer-base-buffer)))
(org-roam--org-roam-file-p path)))))
(defun org-roam--get-roam-buffers ()
"Return a list of buffers that are Org-roam files."
(--filter (and (with-current-buffer it (derived-mode-p 'org-mode))
(buffer-file-name it)
(org-roam--org-roam-file-p (buffer-file-name it)))
(--filter (org-roam--org-roam-buffer-p it)
(buffer-list)))
(defun org-roam--save-buffers (&optional ask update)
"Save all Org-roam buffers.
When ASK is non-nil, ask whether the buffers should be saved.
When UPDATE is non-nil, update the database after."
(save-some-buffers (not ask) #'org-roam--org-roam-buffer-p)
(when update (org-roam-db-update)))
;;; org-roam-backlinks-mode
(define-minor-mode org-roam-backlinks-mode
"Minor mode for the `org-roam-buffer'.
@ -1390,7 +1408,7 @@ OLD-TITLE, and replace the link descriptions with the NEW-TITLE
if applicable.
To be added to `org-roam-title-change-hook'."
(let* ((current-path (buffer-file-name))
(let* ((current-path (buffer-file-name (buffer-base-buffer)))
(files-affected (org-roam-db-query [:select :distinct [source]
:from links
:where (= dest $s1)]
@ -1407,6 +1425,7 @@ current filename, the new slug is computed with NEW-TITLE, and
that portion of the filename is renamed.
To be added to `org-roam-title-change-hook'."
(org-roam--save-buffers)
(when org-roam-rename-file-on-title-change
(let* ((old-slug (funcall org-roam-title-to-slug-function old-title))
(file (buffer-file-name (buffer-base-buffer)))