emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Tor Kringeland <tor.kringeland@ntnu.no>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: [PATCH] Re: [BUG] Adding note to heading without newline at the end
Date: Tue, 21 Jun 2022 10:24:39 +0800	[thread overview]
Message-ID: <87fsjysqhk.fsf@localhost> (raw)
In-Reply-To: <m24k0ffjyd.fsf@ntnu.no>

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

Tor Kringeland <tor.kringeland@ntnu.no> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> Can you reproduce the problem starting from emacs -Q?
>
> I did.  The bug only occurs if there is no newline at the end.  So for
> example if you open a new buffer and don't save it, the bug should
> occur.

Aha. Not saving is an important piece of information.
(said the person with compulsive saving syndrome)

Can you test the attached patch?

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-log-beginning-Fix-for-headline-at-eob-with-no-tr.patch --]
[-- Type: text/x-patch, Size: 1732 bytes --]

From 7c40a003166c9ab8f5f034b8bb6d506ed2b8b62f Mon Sep 17 00:00:00 2001
Message-Id: <7c40a003166c9ab8f5f034b8bb6d506ed2b8b62f.1655778085.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Tue, 21 Jun 2022 10:18:58 +0800
Subject: [PATCH] org-log-beginning: Fix for headline at eob with no trailing
 newline

* lisp/org.el (org-log-beginning): Fix edge case when there is a
headline at the end of buffer and that headline does not have a
trailing newline.

Fixes https://orgmode.org/list/m24k0ffjyd.fsf@ntnu.no
---
 lisp/org.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 220210992..78f51f9ad 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10121,12 +10121,17 @@ (defun org-log-beginning (&optional create)
 	   (end-of-line -1))))
       (t
        (org-end-of-meta-data org-log-state-notes-insert-after-drawers)
-       (skip-chars-forward " \t\n")
-       (beginning-of-line)
-       (unless org-log-states-order-reversed
-	 (org-skip-over-state-notes)
-	 (skip-chars-backward " \t\n")
-	 (beginning-of-line 2)))))
+       (let ((endpos (point)))
+         (skip-chars-forward " \t\n")
+         (beginning-of-line)
+         (unless org-log-states-order-reversed
+	   (org-skip-over-state-notes)
+	   (skip-chars-backward " \t\n")
+	   (beginning-of-line 2))
+         ;; When current headline is at the end of buffer and does not
+         ;; end with trailing newline the above can move to the
+         ;; beginning of the headline.
+         (when (< (point) endpos)) (goto-char endpos)))))
    (if (bolp) (point) (line-beginning-position 2))))
 
 (defun org-add-log-setup (&optional purpose state prev-state how extra)
-- 
2.35.1


  reply	other threads:[~2022-06-21  2:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  0:27 [BUG] Adding note to heading without newline at the end Tor Kringeland
2022-06-20 13:41 ` Ihor Radchenko
2022-06-20 15:11   ` Tor Kringeland
2022-06-21  2:24     ` Ihor Radchenko [this message]
2022-06-21 10:58       ` [PATCH] " Tor Kringeland
2022-06-21 11:13         ` Tim Cross
2022-06-21 11:38         ` Ihor Radchenko
2022-06-22 14:28           ` Tor Kringeland
2022-06-23 15:59             ` Samuel Banya
2022-06-26 23:32               ` Samuel Banya
2022-06-26 23:45                 ` Ihor Radchenko
2022-06-27  2:42                 ` Samuel Banya
2022-06-27 10:18                   ` Ihor Radchenko
2022-06-28  2:47                     ` Samuel Banya
2022-06-28  2:57                       ` Ihor Radchenko
2022-09-13 14:13         ` Ihor Radchenko
2022-06-21  1:56 ` Samuel Banya
2022-06-21  2:21   ` Tor Kringeland

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=87fsjysqhk.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tor.kringeland@ntnu.no \
    /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).