backlink query mode showing raw org-mode content
After executing denote-backlinks on a buffer, a new buffer is opened in a split and it shows a list of files that link to the original buffer/file. This new buffer uses a mode called denote-query-mode which is derived from xref--xref-buffer-mode. As such, the context portion of the results doesn't render org-mode content correctly.
Example:
/home/user/org/20200922T070000--2020-09-22__daily.org
7:* 09:12 Learned about [[denote:20200922T091327][How to take smart notes]]
It would be great if the links were rendered the usual org-mode way. Is that something that can be accomplished via existing configuration options? Thanks!
Hello @honza!
I suspect we can do this, though it will need some work to make sure we retain the Xref faces and functionality.
Anyway, to prove the concept, I made this change in denote.el, which is NOT AN ACTUAL PATCH:
denote.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/denote.el b/denote.el
index e067760..b891db5 100644
--- a/denote.el
+++ b/denote.el
@@ -5728,7 +5728,7 @@ (defun denote--fontify-links-subr (query limit)
(defun denote-fontify-links (limit)
"Provide font-lock matcher to fontify links up to LIMIT."
- (when-let* ((type (denote-filetype-heuristics (buffer-file-name))))
+ (when-let* ((type 'org))
(denote--fontify-links-subr (denote--link-in-context-regexp type) limit)))
(define-obsolete-function-alias
Then I did M-x denote-fontify-links-mode in the backlinks buffer. The links are styled correctly, though we lose all the other fontification.
More generally, we may want to add faces to this buffer to also highlight file names the same way we do in Dired.
Hello @protesilaos and @honza!
I was just about to open the same issue, I'm glad you also think this is a good idea.
The backlinks buffer is indeed the backbone of a Roam-like/Zettelkasten workflows, and having both the links and filenames fontified would be a very useful addition!
Thank you @kofm! I think this should be straightforward because we define the major mode. Though we want to make sure not to interfere with whatever Xref is doing.
Can't wait to see it happen! If I can be of any help, please let me know P.S. Thank you for all your precious work
I just want to say this is an awesome idea and would really improve the usability of the backlinks buffer.
I think it is a quality-of-life improvement. But I am not making any substantial changes yet because I want to wait for at least two weeks after version 4.0.0 to work on any bugs that users may report. After that, we can start with what will become 4.1.0.
Just as a proof of concept, here is a function for fontifying Denote Org links only, without breaking Xref fontification:
(defun denote-fontify-links-query-buffer ()
"Fontify links in a query buffer."
(let ((query (denote--link-in-context-regexp 'org)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward query nil t)
(let* ((inhibit-read-only t)
(start (match-beginning 0))
(end (match-end 0))
(visible-start (or (match-beginning 2) start))
(visible-end (or (match-end 2) end))
(query (match-string-no-properties 1)))
(let* ((properties `( face ,(denote-get-link-face query)
mouse-face highlight
keymap ,denote-link-mouse-map
denote-link-query-part ,query
help-echo query
htmlize-link (:uri ,query)))
(non-sticky-props
'(rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo htmlize-link)))
(face-property 'link)
(hidden (append '(invisible t) properties)))
(remove-text-properties start end '(invisible nil))
(add-text-properties start visible-start hidden)
(add-face-text-property start end face-property)
(add-text-properties visible-start visible-end properties)
(add-text-properties visible-end end hidden)
(dolist (pos (list end visible-start visible-end))
(add-text-properties (1- pos) pos non-sticky-props))))))))
I'm just playing around, there's probably a better way. But it works, for backlinks, denote-grep and query links.
I would be interested in this, and consider it a significant quality of life improvement. While I can't help with the implementation, I'd like to explain why.
By comparison, I played around with a setup of
- markdown notes
- a markdown LSP that resolves links and backlinks to markdown notes as definitions and references, thereby offering some core functionality of knowledge management systems.
- neovim or helix as an editor
This setup supports wiki-style links of the format [[filename]].
Such a link format has basically no 'noise', thus fontification is unnecessary.
If your buffer shows a file called Zermelo-Fraenkel Set Theory, and you check its backlinks,
you're simply going to see sentences, such as
This cannot be formalized in [[Zermelo-Fraenkel Set Theory]]
from some other note.
By comparison,
This cannot be formalized in [[denote:20231027T191021][Zermelo-Fraenkel Set Theory]]
simply is a lot of visual noise and significantly interrupts the flow of reading.
Worse if one sentence includes further links to other notes.
Together with a very nice preview window in helix (out of the box) or neovim (telescope), the setup outlined above often makes it unnecessary to even "follow" backlinks. There is no need to actively visit the file that links to the current file. Instead, one can easily recall some piece of information by just reading it in the backlink preview window. As an illustration, I include some images of dummy notes.
I think this is a beautiful and efficient way of gathering information about the note you're concerned with.
With denote, I'd prefer to use denote-find-backlink-with-location,
because I consider it to be the most efficient method.
But the Emacs minibuffer, in combination with the visual noise surrounding denote links in org,
makes it feel somewhat clunky and "ugly", compared to the setup above.
I've played around with various options, like using vertico-multiform and its buffer option, etcetera.
But ultimately, having fontified backlinks would help a lot.
For me, the best way to look through backlinks in denote with a nice preview is to use
consult-notes
and invoke its consult-notes-search-in-all-notes
with the identifier of the current note as a search term.
This gives a nice fontified preview window.
For someone with some basic elisp skills (not me), I guess a workaround would be to
invoke denote-retrieve-filename-identifier, and pass the result to
consult-notes-search-in-all-notes,
assign a key binding to this, and use it as a custom backlinks function.