Authentication-Results: mail-b.sr.ht; dkim=none Received: from outbound.soverin.net (outbound.soverin.net [185.233.34.20]) by mail-b.sr.ht (Postfix) with ESMTPS id 097A911EE06 for <~protesilaos/denote@lists.sr.ht>; Wed, 26 Oct 2022 16:45:57 +0000 (UTC) Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4MyF775M8zz6r; Wed, 26 Oct 2022 16:45:55 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4MyF7732CszH8; Wed, 26 Oct 2022 16:45:55 +0000 (UTC) X-Soverin-Authenticated: true From: Noboru Ota To: ~protesilaos/denote@lists.sr.ht Cc: Protesilaos Stavrou Subject: Re: [PATCH] Display context of identifier in backlinks buffer with xref In-Reply-To: <87o7tzl1zv.fsf@protesilaos.com> Date: Wed, 26 Oct 2022 18:45:54 +0200 Message-ID: <86lep24jp9.fsf@nobiot.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi Prot, Sorry, again I could not reply to the list. How do you do it? Thank you for merging. I've creted two patches (attached as separate files). More coming. Replying to your comments: > Some comments about the patch: > 1. Yes, I like the option to re-use the backlinks buffer. This can > probably be combined with the aforementioned display buffer action > to make the buffer dedicated to its window. Patch '0002-Add-user-option-to-use-original-backlinks-buffer-or-.patch' addresses this. > 2. I am not familiar with xref--xref-buffer-mode, though deriving the > 'denote-backlinks-mode' from it feels wrong because it is a private > form. Is this change away from special-mode necessary? Do we have > another option? We can go back to special-mode. No problem. Derivation from that mode was mostly for convenience to use the same keybindings in 'denote-backlinks-mode' as in the xref mode. Let me work on the patch right after this email. > 3. We need to find a workaround for 'xref--apply-truncation' so that > we can continue to depend on Emacs 27.2. I will install 27.2 and see issues myself. > 4. Perhaps we can prettify the backlinks' buffer further by adding > more space and/or faces to it. Any recommendation? I will add a blank space. I'm not good at faces (neither design and implemenation). Perhpas you have a good idea? Thanks! nobiot --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-denote-link-find-backlink.patch Content-Description: patch 1 From 085706c3954f932ba874879b7754a9d70ba3e28c Mon Sep 17 00:00:00 2001 From: Noboru Ota Date: Wed, 26 Oct 2022 18:07:08 +0200 Subject: [PATCH] Fix 'denote-link-find-backlink' Commit fcefc1d broke 'denote-link-find-backlink' as 'denote--retrieve-process-grep' was refactored to retrieve xrefs-alist. This change fixes that. * denote.el (denote--retrieve-files-in-xrefs): Revert commit 3b9bc00 (denote-link-find-backlink): Refactor to work as expected as before fcefc1d --- denote.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/denote.el b/denote.el index 79e9ddf..7bce009 100644 --- a/denote.el +++ b/denote.el @@ -1139,6 +1139,13 @@ The xrefs are returned as an alist." (lambda (x) (xref-location-group (xref-item-location x))))) +(defun denote--retrieve-files-in-xrefs (xrefs-alist) + "Return sorted file names sans directory from XREFS. +Parse `denote--retrieve-xrefs'." + (sort + (delete-dups (mapcar #'car xrefs-alist)) + #'string-lessp)) + (defun denote--retrieve-process-grep (identifier) "Process lines matching IDENTIFIER and return list of xrefs-alist." (assoc-delete-all (buffer-file-name) @@ -2432,7 +2439,8 @@ Like `denote-link-find-file', but select backlink to follow." (interactive) (when-let* ((file (buffer-file-name)) (id (denote-retrieve-filename-identifier file)) - (files (denote--retrieve-process-grep id))) + (files (denote--retrieve-files-in-xrefs + (denote--retrieve-process-grep id)))) (find-file (denote-get-path-by-id (denote-extract-id-from-string -- 2.34.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Add-user-option-to-use-original-backlinks-buffer-or-.patch Content-Description: patch 2 From dd65d1fd35f4c2b8f4c165a355ce2e4755e8e32c Mon Sep 17 00:00:00 2001 From: Noboru Ota Date: Wed, 26 Oct 2022 18:30:31 +0200 Subject: [PATCH] Add user option to use original backlinks buffer or with context * denote.el (denote-backlilnks-show-context): Add an user option to toggle the context. (denote-link--prepare-backlinks): Add the original insertion logic back in with refactoring for the xrefs-alist instead of a list of files. --- denote.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/denote.el b/denote.el index 7bce009..e53863b 100644 --- a/denote.el +++ b/denote.el @@ -356,6 +356,18 @@ command." :link '(info-link "(denote) The denote-templates option") :group 'denote) +(defcustom denote-backlilnks-show-context nil + "When non-nil, the backlinks buffer shows context of identifiers. +The context is the one line an identifier is found. This option +also enables the backlink buffer to show multiple occurrences of an +identifier in a single file. + +When nil, the backlinks buffer shows a list of file names where +the identifier is found." + :group 'denote + :package-version '(denote . "0.1.2") + :type 'boolean) + ;;;; Main variables ;; For character classes, evaluate: (info "(elisp) Char Classes") @@ -2623,7 +2635,13 @@ Use optional TITLE for a prettier heading." (l (length heading))) (insert (format "%s\n%s\n\n" heading (make-string l ?-)))) ;;; We could have a user option to use the current backlink buffer - (denote-xref--insert-xrefs xrefs-alist) + (if denote-backlilnks-show-context + (denote-xref--insert-xrefs xrefs-alist) + (mapc (lambda (x) + (insert (denote-get-file-name-relative-to-denote-directory (car x))) + (make-button (line-beginning-position) (line-end-position) :type 'denote-link-backlink-button) + (newline)) + xrefs-alist)) (goto-char (point-min)) (setq-local revert-buffer-function (lambda (_ignore-auto _noconfirm) -- 2.34.1 --=-=-=--