Make 'denote-add-links' always read the dir-local variables

We do this by expanding the lists without using an intermediate
buffer. The previous approach was not working as intended in a silo,
because the dir-local value of 'denote-directory' was not present.

Thanks to yetanotherfossman for reporting the problem with
'denote-add-links' when used in a silo and for figuring out that the
temporary buffer was part of the problem. This was done in issue 386:
<https://github.com/protesilaos/denote/issues/386>.
This commit is contained in:
Protesilaos Stavrou 2024-07-01 13:54:46 +03:00
parent 67f5a7bcea
commit d942333980
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 15 additions and 20 deletions

View file

@ -5741,7 +5741,7 @@ Denote is meant to be a collective effort. Every bit of help matters.
Vick (VicZz), Viktor Haag, Wade Mealing, Yi Liu, Ypot, atanasj,
azegas, babusri, doolio, duli, drcxd, elge70, fingerknight,
hpgisler, mentalisttraceur, pRot0ta1p, rbenit68, relict007, sienic,
sundar bp, zadca123
sundar bp, yetanotherfossman, zadca123
Special thanks to Peter Povinec who helped refine the file-naming
scheme, which is the cornerstone of this project.

View file

@ -4404,10 +4404,7 @@ Place the buffer below the current window or wherever the user option
(defvar denote-link--prepare-links-format "- %s\n"
"Format specifiers for `denote-link-add-links'.")
;; NOTE 2022-06-16: There is no need to overwhelm the user with options,
;; though I expect someone to want to change the sort order.
(defvar denote-link-add-links-sort nil
"When t, add REVERSE to `sort-lines' of `denote-link-add-links'.")
(make-obsolete-variable 'denote-link-add-links-sort nil "3.1.0")
(defun denote-link--prepare-links (files current-file-type id-only &optional no-sort)
"Prepare links to FILES from CURRENT-FILE-TYPE.
@ -4415,18 +4412,15 @@ When ID-ONLY is non-nil, use a generic link format.
With optional NO-SORT do not try to sort the inserted lines.
Otherwise sort lines while accounting for `denote-link-add-links-sort'."
(with-temp-buffer
(mapc
(lambda (file)
(let ((description (denote--link-get-description file)))
(insert
(format
denote-link--prepare-links-format
(denote-format-link file description current-file-type id-only)))))
files)
(unless no-sort
(sort-lines denote-link-add-links-sort (point-min) (point-max)))
(buffer-string)))
(let ((links))
(dolist (file files)
(let* ((description (denote--link-get-description file))
(link (denote-format-link file description current-file-type id-only))
(link-as-list-item (format denote-link--prepare-links-format link)))
(push link-as-list-item links)))
(if no-sort
(nreverse links)
(sort links #'string-collate-lessp))))
(defun denote-link--insert-links (files current-file-type &optional id-only no-sort)
"Insert at point a typographic list of links matching FILES.
@ -4440,7 +4434,9 @@ With ID-ONLY as a non-nil value, produce links that consist only
of the identifier, thus deviating from CURRENT-FILE-TYPE.
Optional NO-SORT is passed to `denote-link--prepare-links'."
(insert (denote-link--prepare-links files current-file-type id-only no-sort)))
(when-let ((links (denote-link--prepare-links files current-file-type id-only no-sort)))
(dolist (link links)
(insert link))))
;;;###autoload
(defun denote-add-links (regexp &optional id-only)
@ -4459,8 +4455,7 @@ inserts links with just the identifier."
(and buffer-file-name (denote-file-has-supported-extension-p buffer-file-name)))
(user-error "The current file type is not recognized by Denote"))
(let ((file-type (denote-filetype-heuristics (buffer-file-name))))
(if-let ((files (denote-directory-files regexp :omit-current))
(beg (point)))
(if-let ((files (denote-directory-files regexp :omit-current)))
(denote-link--insert-links files file-type id-only)
(message "No links matching `%s'" regexp))))