emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Bodertz <bodertz@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH v2] Bug: Indenting empty description list item leaves point at beginning of line [9.4.4]
Date: Thu, 09 Jun 2022 21:25:34 +0800	[thread overview]
Message-ID: <878rq6hstt.fsf@localhost> (raw)
In-Reply-To: <87ilxku6lk.fsf@gmail.com>

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

Bodertz <bodertz@gmail.com> writes:

> Apologies, I wasn't aware you were asking for feedback.
>
> The issue I described no longer occurs.
>
> However, there is still a minor issue with the proposed fix.
>
> After creating a new empty description list item by pressing {M-RET}
> after a description list item, the item created is the following:
>

Thanks for letting me know and sorry for the late reply. This patch has
been sunk in the depths of the todo list.

I have updated the patch to address your concern.
See the attached.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-list-Do-not-move-point-and-change-space-when-pro.patch --]
[-- Type: text/x-patch, Size: 3339 bytes --]

From 86f4e9b1bec488a420b28b91e3813a2cd74d586f Mon Sep 17 00:00:00 2001
Message-Id: <86f4e9b1bec488a420b28b91e3813a2cd74d586f.1654781017.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 2 Oct 2021 18:32:34 +0800
Subject: [PATCH] org-list: Do not move point and change space when
 promoting/demoting items

* lisp/org-list.el (org-list-struct-apply-struct): Make sure the
origin marker is not moved to bol when promoting/demoting item in
special case:
 - item
 - <point> ::
Do not remove the trailing space after point as well.
(org-insert-item): Do not expect point to remain at bol after writing
list struct.

* testing/lisp/test-org-list.el (test-org-list/indent-item): Add test

Fixes https://orgmode.org/list/87o88hlkvv.fsf@gmail.com
---
 lisp/org-list.el              | 15 ++++++++++++++-
 testing/lisp/test-org-list.el | 16 +++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 515763036..97d856fc9 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1940,7 +1940,19 @@ (defun org-list-struct-apply-struct (struct old-struct)
 	      (looking-at org-list-full-item-re)
 	      ;; a.  Replace bullet
 	      (unless (equal old-bul new-bul)
-		(replace-match new-bul nil nil nil 1))
+                (let ((keep-space ""))
+                  (save-excursion
+                    ;; If origin is inside the bullet, preserve the
+                    ;; spaces after origin.
+                    (when (<= (match-beginning 1) origin (match-end 1))
+                      (org-with-point-at origin
+                        (save-match-data
+                          (when (looking-at "[ \t]+")
+                            (setq keep-space (match-string 0))))))
+                    (replace-match "" nil nil nil 1)
+                    (goto-char (match-end 1))
+                    (insert-before-markers new-bul)
+                    (insert keep-space))))
 	      ;; b.  Replace checkbox.
 	      (cond
 	       ((equal (match-string 3) new-box))
@@ -2286,6 +2298,7 @@ (defun org-insert-item (&optional checkbox)
 	  (setq struct (org-list-insert-item pos struct prevs checkbox desc))
 	  (org-list-write-struct struct (org-list-parents-alist struct))
 	  (when checkbox (org-update-checkbox-count-maybe))
+          (beginning-of-line)
 	  (looking-at org-list-full-item-re)
 	  (goto-char (if (and (match-beginning 4)
 			      (save-match-data
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index bc8faa672..d3e6fc176 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -298,7 +298,21 @@ (ert-deftest test-org-list/indent-item ()
 	    (push-mark (point) t t)
 	    (goto-char (point-max))
 	    (let (org-list-demote-modify-bullet) (org-indent-item))
-	    (buffer-string)))))
+	    (buffer-string))))
+  ;; When point is right after empty item, do not move point.
+  (should
+   (= 13
+      (org-test-with-temp-text "
+- item
+- <point> ::"
+        (org-indent-item)
+        (point))))
+  ;; Preserve space after point upon promoting level.
+  (org-test-with-temp-text "
+- item
+- <point> 	::"
+    (org-indent-item)
+    (should (looking-at-p " \t"))))
 
 (ert-deftest test-org-list/indent-item-tree ()
   "Test `org-indent-item-tree' specifications."
-- 
2.35.1


  reply	other threads:[~2022-06-09 15:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24 21:32 Bug: Indenting empty description list item leaves point at beginning of line [9.4.4] Bodertz
2021-09-27  8:24 ` Bastien
2021-10-02 10:47 ` [PATCH] " Ihor Radchenko
2021-10-25 13:34   ` Ihor Radchenko
2021-10-25 21:39     ` Bodertz
2022-06-09 13:25       ` Ihor Radchenko [this message]
2022-06-11  5:12         ` [PATCH v2] " Bodertz
2022-06-11 12:18           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rq6hstt.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=bodertz@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).