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

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

[elpa] externals/org 66cb45658d: Add support for 'thing-at-point' to get


From: ELPA Syncer
Subject: [elpa] externals/org 66cb45658d: Add support for 'thing-at-point' to get URL at point
Date: Sun, 26 May 2024 09:58:21 -0400 (EDT)

branch: externals/org
commit 66cb45658dd1bd546e7051de05a99689b4483282
Author: Jim Porter <itsjimporter@gmail.com>
Commit: Ihor Radchenko <yantar92@posteo.net>

    Add support for 'thing-at-point' to get URL at point
    
    * lisp/org.el (thingatpt): Require.
    (org--link-at-point, org--bounds-of-link-at-point): New functions...
    (org-mode): ... add to 'thing-at-point-provider-alist' and friends.
    
    * testing/lisp/test-org.el (test-org/thing-at-point/url): New test.
    
    * etc/ORG-NEWS: Announce this change.
---
 etc/ORG-NEWS             |  5 +++++
 lisp/org.el              | 25 +++++++++++++++++++++++++
 testing/lisp/test-org.el | 13 +++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e2bbe3e0e2..e6f9de431c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -1486,6 +1486,11 @@ library should be loaded first.
 TODO state, priority, tags, statistics cookies, and COMMENT keywords
 are allowed in the tree structure.
 
+*** Org links now support ~thing-at-point~
+
+You can now retrieve the destination of a link by calling
+~(thing-at-point 'url)~.
+
 *** Add support for ~logind~ idle time in ~org-user-idle-seconds~
 
 When Emacs is built with =dbus= support and
diff --git a/lisp/org.el b/lisp/org.el
index ed18565bd3..656f628bad 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -81,6 +81,7 @@
 (require 'calendar)
 (require 'find-func)
 (require 'format-spec)
+(require 'thingatpt)
 
 (condition-case nil
     (load (concat (file-name-directory load-file-name)
@@ -5041,6 +5042,19 @@ The following commands are available:
             #'pcomplete-completions-at-point nil t)
   (setq-local buffer-face-mode-face 'org-default)
 
+  ;; `thing-at-point' support
+  (setq-local thing-at-point-provider-alist
+              (cons '(url . org--link-at-point)
+                    thing-at-point-provider-alist))
+  (when (boundp 'forward-thing-provider-alist)
+    (setq-local forward-thing-provider-alist
+                (cons '(url . org-next-link)
+                      forward-thing-provider-alist)))
+  (when (boundp 'bounds-of-thing-at-point-provider-alist)
+    (setq-local bounds-of-thing-at-point-provider-alist
+                (cons '(url . org--bounds-of-link-at-point)
+                      bounds-of-thing-at-point-provider-alist)))
+
   ;; If empty file that did not turn on Org mode automatically, make
   ;; it to.
   (when (and org-insert-mode-line-in-empty-file
@@ -8753,6 +8767,17 @@ there is one, return it."
           (setq link (nth (1- nth) links)))))
        (cons link end)))))
 
+(defun org--link-at-point ()
+  "`thing-at-point' provider function."
+  (org-element-property :raw-link (org-element-context)))
+
+(defun org--bounds-of-link-at-point ()
+  "`bounds-of-thing-at-point' provider function."
+  (let ((context (org-element-context)))
+    (when (eq (org-element-type context) 'link)
+      (cons (org-element-begin context)
+            (org-element-end context)))))
+
 ;;; File search
 
 (defun org-do-occur (regexp &optional cleanup)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 072d405bdc..519b966471 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3631,6 +3631,19 @@ Foo Bar
         nil)))))
 
 
+;;; Thing at point
+
+(ert-deftest test-org/thing-at-point/url ()
+  "Test that `thing-at-point' returns the URL at point."
+  (org-test-with-temp-text
+      "[[https://www.gnu.org/software/emacs/][GNU Emacs]]"
+    (should (string= (thing-at-point 'url)
+                     "https://www.gnu.org/software/emacs/";))
+    (when (boundp 'bounds-of-thing-at-point-provider-alist)
+      (should (equal (bounds-of-thing-at-point 'url)
+                     '(1 . 51))))))
+
+
 ;;; Node Properties
 
 (ert-deftest test-org/accumulated-properties-in-drawers ()



reply via email to

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