Ihor Radchenko <[email protected]> writes:

Hello, Ihor, all!

> As discussed during the meetup, let the discussion about
> org-forward/backward-paragraph be separate from the patch.
> Could you please strip the test cases that involve lists from the patch?
> Also, please add ORG-NEWS entry announcing the addition.

I noticed that sentence-at-point was misbehaving for headings too, and I think 
that a
more elegant way to fix this is to provide a proper adapter for
forward-thing-provider-alist. What do you think about this patch?

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 5d91569b6..8daabf6ae 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -204,6 +204,11 @@ having the line numbers included.
 Given the completed and total number of tasks, format the percent
 cookie =[N%]=.
 
+*** New function ~org--forward-sentence-thing-at-point-provider~
+
+This is an internal function added to ~forward-thing-provider-alist~.
+It should improve the reliability of =(sentence-at-point)=.
+
 ** Removed or renamed functions and variables
 
 ** Miscellaneous
diff --git a/lisp/org.el b/lisp/org.el
index 0a2c0b362..4bc254814 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5277,6 +5277,9 @@ define-derived-mode org-mode
   (when (boundp 'forward-thing-provider-alist)
     (setq-local forward-thing-provider-alist
                 (cons '(url . org-next-link)
+                      forward-thing-provider-alist))
+    (setq-local forward-thing-provider-alist
+                (cons '(sentence . org--forward-sentence-thing-at-point-provider)
                       forward-thing-provider-alist)))
   (when (boundp 'bounds-of-thing-at-point-provider-alist)
     (setq-local bounds-of-thing-at-point-provider-alist
@@ -9038,6 +9041,12 @@ defun org--bounds-of-link-at-point
       (cons (org-element-begin context)
             (org-element-end context)))))
 
+(defun org--forward-sentence-thing-at-point-provider (&optional backward)
+  "`forward-thing-at-point' provider function."
+  (if backward
+      (org-backward-sentence)
+    (org-forward-sentence)))
+
 ;;; File search
 
 (defun org-do-occur (regexp &optional cleanup)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 82beb9d58..ac8d78cea 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3750,6 +3750,30 @@ defmacro org-test-without-dow
       (should (equal (bounds-of-thing-at-point 'url)
                      '(1 . 51))))))
 
+(ert-deftest test-org/thing-at-point/sentence ()
+  "Test that `thing-at-point' returns the sentence at point."
+  (org-test-with-temp-text
+   "* This is a heading
+
+This is a test:
+
+- Sentence 1.
+- Sentence 2."
+   (when (boundp 'bounds-of-thing-at-point-provider-alist)
+     (let ((sentence-end-double-space t))
+       (goto-char (point-min))
+       (should (string= (thing-at-point 'sentence)
+                        "* This is a heading"))
+       (re-search-forward "test")
+       (should (string= (thing-at-point 'sentence)
+                        "This is a test:"))
+       (re-search-forward "Sentence 1")
+       (should (string= (thing-at-point 'sentence)
+                        "Sentence 1."))
+       (re-search-forward "Sentence 2")
+       (should (string= (thing-at-point 'sentence)
+                        "Sentence 2."))))))
+
 
 ;;; Node Properties
 
Sacha

Reply via email to