emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Bug] incorrect indent of next heading after org-paste-subtree
@ 2021-11-30 11:42 Max Nikulin
  2022-05-01  2:31 ` Ihor Radchenko
  2022-05-02  1:54 ` Samuel Wales
  0 siblings, 2 replies; 8+ messages in thread
From: Max Nikulin @ 2021-11-30 11:42 UTC (permalink / raw)
  To: emacs-orgmode

Another old bug with org-paste-subtree.

It make indentation of next heading wrong.

Consider the following document and follow described steps:

---- >8 ----
#+STARTUP: indent
Enable soft indent mode

Put to kill ring some text *without trailing newline*
that represents a subtree. In my case it is generated
by a browser extension.
#+begin_src elisp :results silent
   (kill-new "* Pasted Header\nPasted body")
#+end_src

Several levels of heading to make the problem apparent:
* H1
** H2
Ensure that the following "H3" heading is expanded,
put cursor to this line and try =C-c C-x C-y=
or [[elisp:(org-paste-subtree)]]
*** H3
:PROPERTIES:
:CUSTOM_ID: h3
:END:
Body
---- 8< ----

Actual result:

---- >8 ----
Several levels of heading to make the problem apparent:
* H1
*** H2
     Ensure that the following "H3" heading is expanded,
     put cursor to this line and try =C-c C-x C-y=
     or elisp:(org-paste-subtree)
***** Pasted Header
       Pasted body
***** H3
   :PROPERTIES:
   :CUSTOM_ID: h3
   :END:
   Body
---- 8< ----

Expected result

---- >8 ----
Several levels of heading to make the problem apparent:
* H1
*** H2
     Ensure that the following "H3" heading is expanded,
     put cursor to this line and try =C-c C-x C-y=
     or elisp:(org-paste-subtree)
***** Pasted Header
       Pasted body
***** H3
       :PROPERTIES:
       :CUSTOM_ID: h3
       :END:
       Body
---- 8< ----

Org mode version 9.5 (release_9.5-225-g494c20



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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2021-11-30 11:42 [Bug] incorrect indent of next heading after org-paste-subtree Max Nikulin
@ 2022-05-01  2:31 ` Ihor Radchenko
  2022-05-01 11:09   ` Max Nikulin
  2022-05-02  1:54 ` Samuel Wales
  1 sibling, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2022-05-01  2:31 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> Another old bug with org-paste-subtree.
>
> It make indentation of next heading wrong.
>
> Consider the following document and follow described steps:

I am unable to reproduce on the latest Org.

Best,
Ihor


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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2022-05-01  2:31 ` Ihor Radchenko
@ 2022-05-01 11:09   ` Max Nikulin
  2022-05-02  4:00     ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Max Nikulin @ 2022-05-01 11:09 UTC (permalink / raw)
  To: emacs-orgmode

On 01/05/2022 09:31, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> Another old bug with org-paste-subtree.
>>
>> It make indentation of next heading wrong.
>>
>> Consider the following document and follow described steps:
> 
> I am unable to reproduce on the latest Org.

Thank you, Ihor. I have checked it once more for current main HEAD 
2bd34edb64. I can reproduce it using the provided steps in Emacs-26, but 
not in Emacs-27.

Unless there is a reason to suspect something weird underneath, the 
issue should be considered with rather low priority. Anyway, I have 
added trailing newline to generated content and mostly use org-capture 
with org-protocol for communication between applications.




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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2021-11-30 11:42 [Bug] incorrect indent of next heading after org-paste-subtree Max Nikulin
  2022-05-01  2:31 ` Ihor Radchenko
@ 2022-05-02  1:54 ` Samuel Wales
  1 sibling, 0 replies; 8+ messages in thread
From: Samuel Wales @ 2022-05-02  1:54 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

fwiw
[idk if this is useful but here just in case]

iirc, outline mode does not include the final newline for subtrees in
at least one case.

yet, many users and much code assume or ensure that lines are
terminated with a final newline.

this can result in unexpected behavior.  it required code to ensure
compatibility and flexibility, and it required consideration for edge
cases.  sometimes the workarounds would have to be worked around by
the calling code.

core emacs code like sorting assumed/assumes newline.

org would assume or provide none in some [but not all] cases.

user or package code might naturally kill a subtree by killing the
whole line when folded or killing each of the lines.  those include
final newline.  or set require-final-newline.  this is anissue for
things similar to editing source blocks or capture.

the usual bugs were unexpected presence or absence of newlines.  idk
if htat might help you debug or not.


On 11/30/21, Max Nikulin <manikulin@gmail.com> wrote:
> Another old bug with org-paste-subtree.
>
> It make indentation of next heading wrong.
>
> Consider the following document and follow described steps:
>
> ---- >8 ----
> #+STARTUP: indent
> Enable soft indent mode
>
> Put to kill ring some text *without trailing newline*
> that represents a subtree. In my case it is generated
> by a browser extension.
> #+begin_src elisp :results silent
>    (kill-new "* Pasted Header\nPasted body")
> #+end_src
>
> Several levels of heading to make the problem apparent:
> * H1
> ** H2
> Ensure that the following "H3" heading is expanded,
> put cursor to this line and try =C-c C-x C-y=
> or [[elisp:(org-paste-subtree)]]
> *** H3
> :PROPERTIES:
> :CUSTOM_ID: h3
> :END:
> Body
> ---- 8< ----
>
> Actual result:
>
> ---- >8 ----
> Several levels of heading to make the problem apparent:
> * H1
> *** H2
>      Ensure that the following "H3" heading is expanded,
>      put cursor to this line and try =C-c C-x C-y=
>      or elisp:(org-paste-subtree)
> ***** Pasted Header
>        Pasted body
> ***** H3
>    :PROPERTIES:
>    :CUSTOM_ID: h3
>    :END:
>    Body
> ---- 8< ----
>
> Expected result
>
> ---- >8 ----
> Several levels of heading to make the problem apparent:
> * H1
> *** H2
>      Ensure that the following "H3" heading is expanded,
>      put cursor to this line and try =C-c C-x C-y=
>      or elisp:(org-paste-subtree)
> ***** Pasted Header
>        Pasted body
> ***** H3
>        :PROPERTIES:
>        :CUSTOM_ID: h3
>        :END:
>        Body
> ---- 8< ----
>
> Org mode version 9.5 (release_9.5-225-g494c20
>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2022-05-01 11:09   ` Max Nikulin
@ 2022-05-02  4:00     ` Ihor Radchenko
  2022-05-02  7:29       ` Max Nikulin
  2022-05-02 23:32       ` Samuel Wales
  0 siblings, 2 replies; 8+ messages in thread
From: Ihor Radchenko @ 2022-05-02  4:00 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

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

Max Nikulin <manikulin@gmail.com> writes:

>> I am unable to reproduce on the latest Org.
>
> Thank you, Ihor. I have checked it once more for current main HEAD 
> 2bd34edb64. I can reproduce it using the provided steps in Emacs-26, but 
> not in Emacs-27.
>
> Unless there is a reason to suspect something weird underneath, the 
> issue should be considered with rather low priority. Anyway, I have 
> added trailing newline to generated content and mostly use org-capture 
> with org-protocol for communication between applications.

Thanks for the extra info!
I managed to reproduce using Emacs 26 and it is a real problem with some
edge case in org-indent. The problem is masked by
combine-after-change-calls that is used since Emacs 27 but replaced by a
placeholer in Emacs 26.

The fix is attached. Let me know if it also works on your side.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-indent-Fix-edge-case-when-edited-region-ends-at-.patch --]
[-- Type: text/x-patch, Size: 1325 bytes --]

From 5dd89d7b36bee94804c7ab631780a4bd020c49cb Mon Sep 17 00:00:00 2001
Message-Id: <5dd89d7b36bee94804c7ab631780a4bd020c49cb.1651463875.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Mon, 2 May 2022 11:56:15 +0800
Subject: [PATCH] org-indent: Fix edge case when edited region ends at headline
 leading stars

* lisp/org-indent.el (org-indent-refresh-maybe): Extend affected
region to the whole line after END.

Fixes https://orgmode.org/list/t4lpos$l3p$1@ciao.gmane.io
---
 lisp/org-indent.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/org-indent.el b/lisp/org-indent.el
index 4cca0c35d..7469aba97 100644
--- a/lisp/org-indent.el
+++ b/lisp/org-indent.el
@@ -409,7 +409,13 @@ (defun org-indent-refresh-maybe (beg end _)
 		 (goto-char beg)
 		 (beginning-of-line)
 		 (re-search-forward
-		  (org-with-limited-levels org-outline-regexp-bol) end t)))
+		  (org-with-limited-levels org-outline-regexp-bol)
+                  (save-excursion
+                    (goto-char end)
+                    ;; Extend to headline if END is within its
+                    ;; headline stars.
+                    (line-end-position))
+                  t)))
 	   (let ((end (save-excursion
 			(goto-char end)
 			(org-with-limited-levels (outline-next-heading))
-- 
2.35.1


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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2022-05-02  4:00     ` Ihor Radchenko
@ 2022-05-02  7:29       ` Max Nikulin
  2022-05-02 23:32       ` Samuel Wales
  1 sibling, 0 replies; 8+ messages in thread
From: Max Nikulin @ 2022-05-02  7:29 UTC (permalink / raw)
  To: emacs-orgmode

On 02/05/2022 11:00, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>>> I am unable to reproduce on the latest Org.
>>
>> Thank you, Ihor. I have checked it once more for current main HEAD
>> 2bd34edb64. I can reproduce it using the provided steps in Emacs-26, but
>> not in Emacs-27.
> 
> Thanks for the extra info!
> I managed to reproduce using Emacs 26 and it is a real problem with some
> edge case in org-indent. The problem is masked by
> combine-after-change-calls that is used since Emacs 27 but replaced by a
> placeholer in Emacs 26.
> 
> The fix is attached. Let me know if it also works on your side.

I have not performed extensive testing, but your patch fixes the problem 
at least with my test file, so thank you for digging into this issue.



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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2022-05-02  4:00     ` Ihor Radchenko
  2022-05-02  7:29       ` Max Nikulin
@ 2022-05-02 23:32       ` Samuel Wales
  2022-05-03  1:21         ` Ihor Radchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2022-05-02 23:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Max Nikulin, emacs-orgmode

that sounds like great debugging ability.  was this using edebug or something?


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

* Re: [Bug] incorrect indent of next heading after org-paste-subtree
  2022-05-02 23:32       ` Samuel Wales
@ 2022-05-03  1:21         ` Ihor Radchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2022-05-03  1:21 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Max Nikulin, emacs-orgmode

Samuel Wales <samologist@gmail.com> writes:

> that sounds like great debugging ability.  was this using edebug or something?

Just good old debug-on-entry. Nothing fancy.

Best,
Ihor


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

end of thread, other threads:[~2022-05-03  1:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 11:42 [Bug] incorrect indent of next heading after org-paste-subtree Max Nikulin
2022-05-01  2:31 ` Ihor Radchenko
2022-05-01 11:09   ` Max Nikulin
2022-05-02  4:00     ` Ihor Radchenko
2022-05-02  7:29       ` Max Nikulin
2022-05-02 23:32       ` Samuel Wales
2022-05-03  1:21         ` Ihor Radchenko
2022-05-02  1:54 ` Samuel Wales

Code repositories for project(s) associated with this 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).