emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 1a124c2be6 204/355: Make 'denote:' link follow l


From: ELPA Syncer
Subject: [elpa] externals/denote 1a124c2be6 204/355: Make 'denote:' link follow links like 'file:'
Date: Sun, 26 Jun 2022 23:58:24 -0400 (EDT)

branch: externals/denote
commit 1a124c2be613fb466a78844342819924a891ba4d
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Make 'denote:' link follow links like 'file:'
    
    We want it to behave exactly like the standard 'file:' hyperlink type.
    With this change, we made it work with what is described in the manual.
    Evaluate:
    
        (info "(org) Search Options")
---
 denote-link.el | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/denote-link.el b/denote-link.el
index e7f785d327..ab4a5fe0f8 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -293,18 +293,29 @@ manual for more on the matter)."
   (require 'ol)
   (org-link-set-parameters
    "denote"
-   :follow #'denote-link-ol
+   :follow #'denote-link-ol-follow
    :complete #'denote-link-ol-complete))
 
-(defun denote-link--ol-find-file (identifier)
-  "Visit file with IDENTIFIER.
+(declare-function org-link-open-as-file "ol" (path arg))
+
+(defun denote-link-ol-follow (link)
+  "Find file of type `denote:' matching LINK.
+LINK is the identifier of the note, optionally followed by a
+search option akin to that of standard Org `file:' link types.
+Read Info node `(org) Search Options'.
+
 Uses the function `denote-directory' to establish the path to the
 file."
-  (find-file (file-name-completion identifier (denote-directory))))
-
-(defun denote-link-ol (identifier _)
-  "Find file of type `denote:' matching IDENTIFIER."
-  (funcall #'denote-link--ol-find-file identifier))
+  (let* ((search (and (string-match "::\\(.*\\)\\'" link)
+                             (match-string 1 link)))
+            (id (if (and (stringp search) (not (string-empty-p search)))
+                 (substring link 0 (match-beginning 0))
+               link))
+         (path (expand-file-name (file-name-completion id (denote-directory))))
+         (target (if (and (stringp search) (not (string-empty-p search)))
+                     (concat path "::" search)
+                   path)))
+    (org-link-open-as-file target nil)))
 
 (defun denote-link-ol-complete ()
   "Like `denote-link' but for Org integration.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]