On 5/19/2024 6:34 PM, Jim Porter wrote:
On 5/18/2024 1:26 AM, Eli Zaretskii wrote:
I think you can install this now.
Thanks. Merged as ae9045a8bd8.
Ihor, I'll update the Org-mode part of this next and post the new patch
for that to the Org list once it's ready.
... and here's the Org-mode patch for this.
From 93c485f5348c879ef2328e00035d7b16a7d94342 Mon Sep 17 00:00:00 2001
From: Jim Porter <itsjimpor...@gmail.com>
Date: Mon, 6 Nov 2023 11:39:09 -0800
Subject: [PATCH] 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.
---
lisp/org.el | 25 +++++++++++++++++++++++++
testing/lisp/test-org.el | 13 +++++++++++++
2 files changed, 38 insertions(+)
diff --git a/lisp/org.el b/lisp/org.el
index 5e9f479fb..0c2f347ff 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)
@@ -5042,6 +5043,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
@@ -8752,6 +8766,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 23d12b26a..a83078e45 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3630,6 +3630,19 @@ Foo Bar
(org-open-at-point))
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
--
2.25.1