protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
539 stars 55 forks source link

Jump to specific line of occurrence with denote-find-backlink #471

Open johkneisl opened 3 weeks ago

johkneisl commented 3 weeks ago

Between the two major options to visit backlinks

  1. Use denote-backlinks, visit the backlinks’ buffer, follow a backlink.
  2. Use denote-find-backlink, select a backlink from the minibuffer.

I'm seeing a difference in behavior after following a backlink.

(1) The backlink buffer opens the referenced file at the exact location of the outgoing link, which is useful. (2) With denote-find-backlink, I just land at the top of the file, which is less useful.

I think it would be convenient to have the behavior of (1) in (2). I hope I was able to make clear what I mean, I'm happy to provide some screenshots or more explanations if necessary.

protesilaos commented 2 weeks ago

From: johkneisl @.***> Date: Sun, 27 Oct 2024 07:23:36 -0700

[... 8 lines elided]

(1) The backlink buffer opens the referenced file at the exact location of the outgoing link, which is useful.

I assume you have set 'denote-backlinks-show-context' to non-nil? In that scenario, it should indeed take you to the exact match. Otherwise, it opens the file and leaves the point whereever it would be after a normal 'find-file'.

(2) With denote-find-backlink, I just land at the top of the file, which is less useful.

Indeed. To make this happen, we need to store the position of each match and then use it when we perform the jump to the file. In the scenario I mentioned above, we get this for free because of how Xref works.

Let me take a look at it and report back to you.

-- Protesilaos Stavrou https://protesilaos.com