branch: externals/denote
commit 0d696e7c35824252aa3669c67804d53678f236aa
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Change how the helpers of "link at point" get the position
    
    It is better for helper functions to expect an argument, because then
    we can adapt them to our needs. Here we use '(point)', but we may have
    another approach elsewhere.
---
 denote.el | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/denote.el b/denote.el
index 7a922e8d13..b150be31e4 100644
--- a/denote.el
+++ b/denote.el
@@ -6254,8 +6254,8 @@ To be assigned to `markdown-follow-link-functions'."
   "Keymap for mouse actions over fontified Denote links.")
 
 ;; Adapted from `org-in-regexp'.
-(defun denote--inside-link-regexp-p (regexp)
-  "Check if point is inside a Denote link REGEXP.
+(defun denote--inside-link-regexp-p (regexp position)
+  "Check if POSITION is inside a Denote link REGEXP.
 Return either nil or a list whose elements are two cons cells:
 
 - The first cons cell has the link target and the link description,
@@ -6264,13 +6264,12 @@ Return either nil or a list whose elements are two cons 
cells:
 - The second cons cell consists of two buffer positions, pointing to the
   beginning and end of REGEXP."
   (catch 'exit
-    (let ((point (point))
-          (line-end (line-end-position)))
+    (let ((line-end (line-end-position)))
       (save-excursion
         (forward-line 0)
         (while (and (re-search-forward regexp line-end t)
-                    (<= (match-beginning 0) point))
-          (when (>= (match-end 0) point)
+                    (<= (match-beginning 0) position))
+          (when (>= (match-end 0) position)
             (throw 'exit (list (cons
                                 (match-string-no-properties 1)
                                 (match-string-no-properties 2))
@@ -6278,15 +6277,15 @@ Return either nil or a list whose elements are two cons 
cells:
                                 (match-beginning 0)
                                 (match-end 0))))))))))
 
-(defun denote--link-at-point-get-data ()
-  "Return matching data for the link at point."
+(defun denote--link-at-point-get-data (position)
+  "Return matching data for the link at POSITION."
   (when-let* ((file buffer-file-name)
               (regexp (denote--link-in-context-regexp 
(denote-filetype-heuristics file))))
-    (denote--inside-link-regexp-p regexp)))
+    (denote--inside-link-regexp-p regexp position)))
 
-(defun denote--link-open-at-point-subr ()
-  "Open link at point."
-  (pcase-let* ((data (denote--link-at-point-get-data))
+(defun denote--link-open-at-point-subr (position)
+  "Open link at POSITION."
+  (pcase-let* ((data (denote--link-at-point-get-data position))
                (`(,target . ,_) (car data)))
     (if-let* ((path (denote-get-path-by-id target)))
         (funcall denote-open-link-function path)
@@ -6295,13 +6294,13 @@ Return either nil or a list whose elements are two cons 
cells:
 (defun denote-link-open-at-point ()
   "Open Denote link at point."
   (interactive)
-  (denote--link-open-at-point-subr))
+  (denote--link-open-at-point-subr (point)))
 
 (defun denote-link-open-at-mouse (ev)
   "Open Denote link for mouse EV click."
   (interactive "e")
   (mouse-set-point ev)
-  (denote--link-open-at-point-subr))
+  (denote--link-open-at-point-subr (point)))
 
 (defun denote-get-link-face (query)
   "Return appropriate face for QUERY."

Reply via email to