all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* RE: Re: [External] : Re: Adding custom providers for thingatpt.el (was: [PATCH] Add support for 'thing-at-point' to get URL at point)
@ 2024-05-08 16:09 Pedro Andres Aranda Gutierrez
  2024-05-08 18:14 ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-05-08 16:09 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 875 bytes --]

Jim wrote:

> At the risk of veering off-topic (I mainly care about adding
> 'bounds-of-thing-at-point-provider-alist' and
> 'forward-thing-provider-alist'), would adding a new optional STRICT
> argument to 'thing-at-point' and friends be an ok resolution for
> everyone? This argument would enable Drew's proposed behavior. That way,
> users get all the nice behavior by default just like today, and
> programmers who require strict correctness in their code also have an
> option.

1+ if STRICT means thing starting at point and without it we may need to
look for the beginning of the thing (lazy point setting)....

/PA
-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #2: Type: text/html, Size: 1309 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH] Add support for 'thing-at-point' to get URL at point
@ 2023-11-06 19:45 Jim Porter
  2023-11-06 20:11 ` Adding custom providers for thingatpt.el (was: [PATCH] Add support for 'thing-at-point' to get URL at point) Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Porter @ 2023-11-06 19:45 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

This is similar to Emacs bug#66752[1]. It would be nice if 
"(thing-at-point 'url)" would return the URL when point is over an Org 
link. With this, it's easier to write a function that copies (or browses 
to) the URL at point without coding so many special cases.

Attached is a patch with a regression test for it. Should this also get 
a NEWS entry?

[1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-10/msg01628.html

[-- Attachment #2: 0001-Add-support-for-thing-at-point-to-get-URL-at-point.patch --]
[-- Type: text/plain, Size: 2229 bytes --]

From 6bce84bd28253236eff8ef972ede7daf82f95a71 Mon Sep 17 00:00:00 2001
From: Jim Porter <itsjimporter@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--url-at-point): New function...
(org-mode): ... and add it to 'thing-at-point-provider-alist'.

* testing/lisp/test-org.el (test-org/thing-at-point/url): New test.
---
 lisp/org.el              | 10 ++++++++++
 testing/lisp/test-org.el | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 4eb6ad0ee..c7ecfc13a 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)
@@ -4948,6 +4949,11 @@ 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
+              (append thing-at-point-provider-alist
+                      '((url . org--url-at-point))))
+
   ;; If empty file that did not turn on Org mode automatically, make
   ;; it to.
   (when (and org-insert-mode-line-in-empty-file
@@ -8611,6 +8617,10 @@ there is one, return it."
 	   (setq link (nth (1- nth) links)))))
        (cons link end)))))
 
+(defun org--url-at-point ()
+  "`thing-at-point' provider function."
+  (org-element-property :raw-link (org-element-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 21b850c03..2fe4477a3 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3583,6 +3583,16 @@ Foo Bar
 	     (org-open-at-point))
 	 nil)))))
 
+\f
+;;; Thing at point
+
+(ert-deftest test-org/thing-at-point/url ()
+  "Test that `thing-at-point' returns the URL at point."
+  (should
+   (org-test-with-temp-text
+       "[[https://www.gnu.org/software/emacs/][GNU Emacs]]"
+     (string= (thing-at-point 'url) "https://www.gnu.org/software/emacs/"))))
+
 \f
 ;;; Node Properties
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-15 21:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-08 16:09 Re: [External] : Re: Adding custom providers for thingatpt.el (was: [PATCH] Add support for 'thing-at-point' to get URL at point) Pedro Andres Aranda Gutierrez
2024-05-08 18:14 ` Drew Adams
2024-05-09  5:46   ` Pedro Andres Aranda Gutierrez
2024-05-15  8:06   ` Jean Louis
2024-05-15 20:56     ` Drew Adams
2024-05-15 21:25       ` Jean Louis
2024-05-15 21:56         ` Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2023-11-06 19:45 [PATCH] Add support for 'thing-at-point' to get URL at point Jim Porter
2023-11-06 20:11 ` Adding custom providers for thingatpt.el (was: [PATCH] Add support for 'thing-at-point' to get URL at point) Ihor Radchenko
2023-11-06 20:53   ` Jim Porter
2024-02-05 15:07     ` Ihor Radchenko
2024-02-05 22:44       ` Jim Porter
2024-04-12 12:41         ` Ihor Radchenko
2024-04-12 22:30           ` Jim Porter
2024-04-29  4:26             ` Jim Porter
2024-04-29 18:14               ` Ihor Radchenko
2024-04-30  4:42                 ` Jim Porter
2024-04-30 11:39                   ` Ihor Radchenko
2024-04-30 18:27                     ` Jim Porter
2024-04-30 21:10                       ` [External] : " Drew Adams
2024-05-07  1:08                         ` Jim Porter
2024-05-07  1:52                           ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.