all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] org-list-send-item: allow dest to be a buffer position
@ 2022-02-06  2:44 Sacha Chua
  2022-02-06  9:57 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Sacha Chua @ 2022-02-06  2:44 UTC (permalink / raw)
  To: emacs-orgmode

Passing an integer representing a buffer position to org-list-send-item
was failing because of the string-match-p, so here's something that lets
integers skip that part. I have copyright assignment papers on file.

Sacha

----------------------------------------------------------------
lisp/org-list.el: org-list-send-item: allow dest to be a buffer position

* lisp/org-list.el (org-list-send-item): Check if dest is a string
before matching it, to allow dest to be a buffer position.
---
 lisp/org-list.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 3533c8319..f1ab2ca76 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1442,7 +1442,7 @@ (defun org-list-send-item (item dest struct)
 		      (save-excursion
 			(goto-char (org-list-get-last-item item struct prevs))
 			(point-at-eol)))
-		     ((string-match-p "\\`[0-9]+\\'" dest)
+		     ((and (stringp dest) (string-match-p "\\`[0-9]+\\'" dest))
 		      (let* ((all (org-list-get-all-items item struct prevs))
 			     (len (length all))
 			     (index (mod (string-to-number dest) len)))
-- 
2.25.1




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

* Re: [PATCH] org-list-send-item: allow dest to be a buffer position
  2022-02-06  2:44 [PATCH] org-list-send-item: allow dest to be a buffer position Sacha Chua
@ 2022-02-06  9:57 ` Ihor Radchenko
  2022-02-07  0:48   ` Sacha Chua
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2022-02-06  9:57 UTC (permalink / raw)
  To: Sacha Chua; +Cc: emacs-orgmode

Sacha Chua <sacha@sachachua.com> writes:

> Passing an integer representing a buffer position to org-list-send-item
> was failing because of the string-match-p, so here's something that lets
> integers skip that part. I have copyright assignment papers on file.

LGTM! Would you mind supplying a test for this function?

Best,
Ihor


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

* Re: [PATCH] org-list-send-item: allow dest to be a buffer position
  2022-02-06  9:57 ` Ihor Radchenko
@ 2022-02-07  0:48   ` Sacha Chua
  2022-02-07 13:10     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Sacha Chua @ 2022-02-07  0:48 UTC (permalink / raw)
  To: emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

>> Passing an integer representing a buffer position to org-list-send-item
>> was failing because of the string-match-p, so here's something that lets
>> integers skip that part. I have copyright assignment papers on file.
> LGTM! Would you mind supplying a test for this function?

Sure! Here's the new patch that includes the change and tests for the
different kinds of input accepted by org-list-send-item.

Sacha

lisp/org-list.el: org-list-send-item: allow dest to be a buffer position

* lisp/org-list.el (org-list-send-item): Check if dest is a string
before matching it, to allow dest to be a buffer position.
* testing/lisp/test-org-list.el (test-org-list/send-item): Add tests
---
 lisp/org-list.el              |  2 +-
 testing/lisp/test-org-list.el | 64 +++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 3533c8319..f1ab2ca76 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1442,7 +1442,7 @@ (defun org-list-send-item (item dest struct)
 		      (save-excursion
 			(goto-char (org-list-get-last-item item struct prevs))
 			(point-at-eol)))
-		     ((string-match-p "\\`[0-9]+\\'" dest)
+		     ((and (stringp dest) (string-match-p "\\`[0-9]+\\'" dest))
 		      (let* ((all (org-list-get-all-items item struct prevs))
 			     (len (length all))
 			     (index (mod (string-to-number dest) len)))
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index 3689a172f..e21409ca5 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -900,6 +900,70 @@ (ert-deftest test-org-list/insert-item ()
       (org-insert-item)
       (buffer-string)))))
 
+(ert-deftest test-org-list/send-item ()
+  "Test `org-list-send-item' specifications."
+  ;; Move to beginning
+  (should
+   (equal "- item3\n- item1\n- item2\n"
+          (org-test-with-temp-text
+              "- item1\n- item2\n- item3\n"
+            (org-list-send-item (caar (last (org-list-struct)))
+                                'begin (org-list-struct))
+            (buffer-string))))
+  ;; Move to beginning with child item
+  (should
+   (equal "- item3\n  - item4\n- item1\n- item2\n"
+          (org-test-with-temp-text
+              "- item1\n- item2\n- item3\n  - item4\n"
+            (org-list-send-item (car (nth 2 (org-list-struct)))
+                                'begin (org-list-struct))
+            (buffer-string))))
+  ;; Move to end
+  (should
+   (equal "- item2\n- item3\n  - item4\n- item1\n  - item1child\n"
+          (org-test-with-temp-text
+              "- item1\n  - item1child\n- item2\n- item3\n  - item4\n"
+            (org-list-send-item (car (nth 0 (org-list-struct)))
+                                'end (org-list-struct))
+            (buffer-string))))
+  ;; Move to item number by string should move the item before the specified one
+  (should
+   (equal "- item2\n- item1\n  - item1child\n- item3\n- item4\n- item5\n"
+          (org-test-with-temp-text
+              "- item1\n  - item1child\n- item2\n- item3\n- item4\n- item5\n"
+            (org-list-send-item (car (nth 0 (org-list-struct)))
+                                "3" (org-list-struct))
+            (buffer-string))))
+  ;; Move to item number by position should move the item before the specified one
+  (should
+   (equal "- item2\n- item1\n  - item1child\n- item3\n- item4\n- item5\n"
+          (org-test-with-temp-text
+              "- item1\n  - item1child\n- item2\n- item3\n- item4\n- item5\n"
+            (re-search-forward "item3")
+            (org-list-send-item (car (nth 0 (org-list-struct)))
+                                (point-at-bol) (org-list-struct))
+            (buffer-string))))
+  ;; Delete
+  (should
+   (equal "- item1\n  - item1child\n- item2\n- item4\n- item5\n"
+          (org-test-with-temp-text
+              "- item1\n  - item1child\n- item2\n- item3\n- item4\n- item5\n"
+            (re-search-forward "item3")
+            (org-list-send-item (point-at-bol)
+                                'delete (org-list-struct))
+            (buffer-string))))
+  ;; Kill
+  (let ((kill-ring nil))
+    (org-test-with-temp-text
+        "- item1\n  - item1child\n- item2\n- item3\n  - item3child\n- item4\n- item5\n"
+      (re-search-forward "item3")
+      (org-list-send-item (point-at-bol)
+                          'kill (org-list-struct))
+      (should (equal "- item1\n  - item1child\n- item2\n- item4\n- item5\n"
+                     (buffer-string)))
+      (should (equal "item3\n  - item3child"
+                     (current-kill 0 t))))))
+
 (ert-deftest test-org-list/repair ()
   "Test `org-list-repair' specifications."
   ;; Repair indentation.
-- 
2.25.1




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

* Re: [PATCH] org-list-send-item: allow dest to be a buffer position
  2022-02-07  0:48   ` Sacha Chua
@ 2022-02-07 13:10     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2022-02-07 13:10 UTC (permalink / raw)
  To: Sacha Chua; +Cc: emacs-orgmode

Sacha Chua <sacha@sachachua.com> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>>> Passing an integer representing a buffer position to org-list-send-item
>>> was failing because of the string-match-p, so here's something that lets
>>> integers skip that part. I have copyright assignment papers on file.
>> LGTM! Would you mind supplying a test for this function?
>
> Sure! Here's the new patch that includes the change and tests for the
> different kinds of input accepted by org-list-send-item.

Thanks! Pushed to bugfix as c5ceb6a2c.

Best,
Ihor


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

end of thread, other threads:[~2022-02-07 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-06  2:44 [PATCH] org-list-send-item: allow dest to be a buffer position Sacha Chua
2022-02-06  9:57 ` Ihor Radchenko
2022-02-07  0:48   ` Sacha Chua
2022-02-07 13:10     ` Ihor Radchenko

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.