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

    Define helper functions to test if point is inside link regexp
    
    The 'denote--inside-link-regexp-p' is based on the function
    'org-in-regexp' that I found in the org-macs.el file of Org version
    9.7.11.
    
    Thanks to Jean-Philippe Gagné Guay for the feedback in issue 631 that
    helped refine 'denote--inside-link-regexp-p':
    <https://github.com/protesilaos/denote/issues/631#issuecomment-3194420425>.
---
 denote.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/denote.el b/denote.el
index c1d4e39005..6b8c7df4b3 100644
--- a/denote.el
+++ b/denote.el
@@ -6253,6 +6253,37 @@ To be assigned to `markdown-follow-link-functions'."
     map)
   "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.
+Return either nil or a list whose elements are two cons cells:
+
+- The first cons cell has the link target and the link description,
+  like (\"denote:20250816T080008\" . \"This is a test\").
+
+- 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)))
+      (save-excursion
+        (forward-line 0)
+        (while (and (re-search-forward regexp line-end t)
+                    (<= (match-beginning 0) point))
+          (when (>= (match-end 0) point)
+            (throw 'exit (list (cons
+                                (match-string-no-properties 1)
+                                (match-string-no-properties 2))
+                               (cons
+                                (match-beginning 0)
+                                (match-end 0))))))))))
+
+(defun denote--link-at-point-get-data ()
+  "Return matching data for the link at point."
+  (when-let* ((file buffer-file-name)
+              (regexp (denote--link-in-context-regexp 
(denote-filetype-heuristics file))))
+    (denote--inside-link-regexp-p regexp)))
+
 (defun denote--link-open-at-point-subr ()
   "Open link at point."
   (let ((query (get-text-property (point) 'denote-link-query-part)))

Reply via email to