[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 7a16d7bb69 3/5: Add optional command to sshow ba
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 7a16d7bb69 3/5: Add optional command to sshow backlinks for an individual Org heading |
Date: |
Sat, 20 Apr 2024 15:57:48 -0400 (EDT) |
branch: externals/denote
commit 7a16d7bb696a1a0269b3caa10bdbe001d8269995
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add optional command to sshow backlinks for an individual Org heading
Thanks to Harold Ollivier for suggesting this idea in issue 297:
<https://github.com/protesilaos/denote/issues/297>.
---
README.org | 14 ++++++++++++++
denote-org-extras.el | 26 +++++++++++++++++++++++++-
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index 338a982523..dbb46842fc 100644
--- a/README.org
+++ b/README.org
@@ -2425,6 +2425,20 @@ Reproducing it here for the sake of convenience:
(window-width . 0.3)))
#+end_src
+*** Backlinks for Org headings
+:PROPERTIES:
+:CUSTOM_ID: h:604bf92a-908a-485c-98b8-37ccae559afd
+:END:
+
+[ This is part of {{{development-version}}}. ]
+
+The optional =denote-org-extras.el= can produce Denote links to
+individual headings ([[#h:fc1ad245-ec08-41be-8d1e-7153d99daf02][Insert link to
an Org file with a further pointer to a heading]]).
+It is then possible to produce a corresponding backlinks buffer with
+the command ~denote-org-extras-backlinks-for-heading~. The resulting
+buffer behaves the same way as the standard backlinks buffer we
+provide ([[#h:c73f1f68-e214-49d5-b369-e694f6a5d708][The backlinks' buffer]]).
+
** Writing metanotes
:PROPERTIES:
:CUSTOM_ID: h:6060a7e6-f179-4d42-a9de-a9968aaebecc
diff --git a/denote-org-extras.el b/denote-org-extras.el
index 38772bc9be..5bf641ae74 100644
--- a/denote-org-extras.el
+++ b/denote-org-extras.el
@@ -102,7 +102,9 @@ to the current heading. Such links look the same as those
of
this command, though the functionality defined herein is
independent of it.
-To only link to a file, use the `denote-link' command."
+To only link to a file, use the `denote-link' command.
+
+Also see `denote-org-extras-backlinks-for-heading'."
(declare (interactive-only t))
(interactive nil org-mode)
(unless (derived-mode-p 'org-mode)
@@ -117,6 +119,28 @@ To only link to a file, use the `denote-link' command."
(description (denote-link-format-heading-description file-text
heading-text)))
(insert (denote-org-extras-format-link-with-heading file heading-id
description))))
+;;;; Heading backlinks
+
+(defun denote-org-extras--get-file-id-and-heading-id (file)
+ "Return IDENTIFIER::#ORG-HEADING-CUSTOM-ID string for FILE heading at point."
+ (if-let ((heading-id (org-entry-get (point) "CUSTOM_ID")))
+ (concat (denote-retrieve-filename-identifier-with-error file) "::#"
heading-id)
+ (error "No CUSTOM_ID for heading at point in file `%s'" file)))
+
+;;;###autoload
+(defun denote-org-extras-backlinks-for-heading ()
+ "Produce backlinks for the current heading.
+This otherwise has the same behaviour as `denote-backlinks'---refer to
+that for the details.
+
+Also see `denote-org-extras-link-to-heading'."
+ (interactive)
+ (when-let ((heading-id (denote-org-extras--get-file-id-and-heading-id
buffer-file-name)))
+ (denote-link--prepare-backlinks
+ (apply-partially #'xref-matches-in-files heading-id
+ (denote-directory-files nil :omit-current :text-only))
+ nil heading-id)))
+
;;;; Extract subtree into its own note
(defun denote-org-extras--get-heading-date ()