[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 694c1517be 2/2: Expose public functions for retu
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/denote 694c1517be 2/2: Expose public functions for returning links or backlinks |
|
Date: |
Mon, 8 May 2023 11:57:52 -0400 (EDT) |
branch: externals/denote
commit 694c1517be73949edbc3993c105c764da8e2571f
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Expose public functions for returning links or backlinks
We are doing the work in standalone functions that can be called from
Lisp, instead of limiting it to interactive functions. The code is
more composable as a result.
This is in response to the mailing list thread started by relict007:
<https://lists.sr.ht/~protesilaos/denote/%3C87a5ygk6yi.fsf@kotlak.com%3E>
relict007 is the developer of the 'denote-cache' package (in
progress): <https://git.sr.ht/~relict007/denote-cache>.
---
README.org | 10 ++++++++++
denote.el | 46 +++++++++++++++++++++++++++++++---------------
2 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/README.org b/README.org
index 6670a4d0bb..b237c42de2 100644
--- a/README.org
+++ b/README.org
@@ -3411,6 +3411,16 @@ might change them without further notice.
matter =KEYWORDS= for org file type. =KEYWORDS= is a list of
strings. Consult the ~denote-file-types~ for how this is used.
+[ The following two functions are part of {{{development-version}}}. ]
+
+#+findex: denote-link-return-links
++ Function ~denote-link-return-links~ :: Return list of links in
+ current or optional =FILE=. Also see ~denote-link-return-backlinks~.
+
+#+findex: denote-link-return-backlinks
++ Function ~denote-link-return-backlinks~ :: Return list of links in
+ current or optional =FILE=. Also see ~denote-link-return-links~.
+
* Troubleshoot Denote in a pristine environment
:PROPERTIES:
:CUSTOM_ID: h:9c4467d5-6480-4681-80fb-cd9717bf8b3b
diff --git a/denote.el b/denote.el
index df952c3253..ebc1145352 100644
--- a/denote.el
+++ b/denote.el
@@ -2845,17 +2845,36 @@ whitespace-only), insert an ID-ONLY link."
(denote--completion-table 'file file-names)
nil t nil 'denote-link--find-file-history)))
+(defun denote-link-return-links (&optional file)
+ "Return list of links in current or optional FILE.
+Also see `denote-link-return-backlinks'."
+ (if-let* ((current-file (or file (buffer-file-name)))
+ (file-type (denote-filetype-heuristics current-file))
+ (regexp (denote--link-in-context-regexp file-type))
+ (links (with-current-buffer (find-file-noselect current-file)
+ (denote-link--expand-identifiers regexp))))
+ links
+ (user-error "No links found in `%s'" current-file)))
+
+(defalias 'denote-link-return-forelinks 'denote-link-return-links
+ "Alias of `denote-link-return-links'.")
+
;;;###autoload
(defun denote-link-find-file ()
"Use minibuffer completion to visit linked file."
(interactive)
- (if-let* ((current-file (buffer-file-name))
- (file-type (denote-filetype-heuristics current-file))
- (regexp (denote--link-in-context-regexp file-type))
- (files (denote-link--expand-identifiers regexp)))
- (find-file
- (denote-link--find-file-prompt files))
- (user-error "No links found in the current buffer")))
+ (find-file
+ (denote-link--find-file-prompt
+ (denote-link-return-links))))
+
+(defun denote-link-return-backlinks (&optional file)
+ "Return list of backlinks in current or optional FILE.
+Also see `denote-link-return-links'."
+ (if-let* ((current-file (or file (buffer-file-name)))
+ (id (denote-retrieve-filename-identifier current-file))
+ (backlinks (delete current-file (denote--retrieve-files-in-xrefs
id))))
+ backlinks
+ (user-error "No backlinks found in `%s'" current-file)))
;;;###autoload
(defun denote-link-find-backlink ()
@@ -2863,14 +2882,11 @@ whitespace-only), insert an ID-ONLY link."
Like `denote-link-find-file', but select backlink to follow."
(interactive)
- (if-let* ((file (buffer-file-name))
- (id (denote-retrieve-filename-identifier file))
- (files (delete file (denote--retrieve-files-in-xrefs id))))
- (find-file
- (denote-get-path-by-id
- (denote-extract-id-from-string
- (denote-link--find-file-prompt files))))
- (user-error "No links found in the current buffer")))
+ (find-file
+ (denote-get-path-by-id
+ (denote-extract-id-from-string
+ (denote-link--find-file-prompt
+ (denote-link-return-backlinks))))))
;;;###autoload
(defun denote-link-after-creating (&optional id-only)