Make denote-link-add-links use id: when necessary

This will account for the target file.  So if we insert files matching a
regexp, we get the appropriate link type per file.

If it is Org and 'denote-link-use-org-id' is non-nil, then the link type
is 'id:'.

If it is another file type the link is 'denote:'.

If 'denote-link-use-org-id' is nil, the link is also 'denote:'.
This commit is contained in:
Protesilaos Stavrou 2022-06-24 06:07:05 +03:00
parent 0fac78ada3
commit b14b5e201e
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -475,14 +475,19 @@ default, it will show up below the current window."
(defvar denote-link-add-links-sort nil
"Add REVERSE to `sort-lines' of `denote-link-add-links' when t.")
(defun denote-link--prepare-links (files ext)
"Prepare links to FILES using format of EXT."
(defun denote-link--prepare-links (files current-file id-only)
"Prepare links to FILES from CURRENT-FILE.
When ID-ONLY is non-nil, use a generic link format. See
`denote-link--file-type-format'."
(setq denote-link--links-to-files
(with-temp-buffer
(mapc (lambda (f)
(mapc (lambda (file)
(insert
(format denote-link--prepare-links-format
(denote-link--format-link f ext))))
(format
denote-link--prepare-links-format
(denote-link--format-link
file
(denote-link--file-type-format current-file file id-only)))))
files)
(sort-lines denote-link-add-links-sort (point-min) (point-max))
(buffer-string))))
@ -504,10 +509,10 @@ inserts links with just the identifier."
(read-regexp "Insert links matching REGEX: " nil 'denote-link--add-links-history)
current-prefix-arg))
(let* ((default-directory (denote-directory))
(ext (denote-link--extension-format-or-id id-only)))
(current-file (buffer-file-name)))
(if-let ((files (denote--directory-files-matching-regexp regexp)))
(let ((beg (point)))
(insert (denote-link--prepare-links files ext))
(insert (denote-link--prepare-links files current-file id-only))
(unless (derived-mode-p 'org-mode)
(denote-link-buttonize-buffer beg (point))))
(user-error "No links matching `%s'" regexp))))