branch: externals/denote commit 90875d5419f27117ccd4a165dd536410e31ef541 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Sort backlinks from oldest to newest I think we do not need a user option for this, as too many options make it difficult to understand what is really needed to get started. Though the 'denote-link-backlinks-sort' variable can be set to t to reverse the order. --- denote-link.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/denote-link.el b/denote-link.el index bdb4263d92..8176ebd5a6 100644 --- a/denote-link.el +++ b/denote-link.el @@ -215,11 +215,17 @@ format is always [[denote:IDENTIFIER]]." buf `(,@denote-link-backlinks-display-buffer-action))) +;; NOTE 2022-06-17: This is a `defvar' on purpose, like +;; `denote-link-add-links'. Read its comment. +(defvar denote-link-backlinks-sort nil + "Add REVERSE to `sort-lines' of `denote-link-backlinks' when t.") + (defun denote-link--prepare-backlinks (id files &optional title) "Create backlinks' buffer for ID including FILES. Use optional TITLE for a prettier heading." (let ((inhibit-read-only t) - (buf (format "*denote-backlinks to %s*" id))) + (buf (format "*denote-backlinks to %s*" id)) + start) (with-current-buffer (get-buffer-create buf) (erase-buffer) (special-mode) @@ -228,11 +234,13 @@ Use optional TITLE for a prettier heading." (heading (format "Backlinks to %S (%s)" title id)) (l (length heading))) (insert (format "%s\n%s\n\n" heading (make-string l ?-)))) + (setq start (point)) (mapc (lambda (f) (insert (file-name-nondirectory f)) (make-button (point-at-bol) (point-at-eol) :type 'denote-link-find-file) (newline)) files) + (sort-lines denote-link-backlinks-sort start (point)) (goto-char (point-min)) ;; NOTE 2022-06-15: Technically this is not Dired. Maybe we ;; should abstract the fontification into a general purpose