Function org-backward-heading-same-level fails in a specific case. Suppose the following org-mode file:

==================
* first
* second
* third
==================

where '* first' is right at the beginning of the file.

When the cursor is at line '* third' and org-backward-heading-same-level is called, we go to the previous line correctly. However when the cursor is at '* second', org-backward-heading-same-level does bring us to the first line but emits an error "Beginning of buffer". It seems that the patch attached to this message fixes the problem.

Best,

Rafael
>From ff792a00e28b7b0ca4fde98f72611ef8079daf04 Mon Sep 17 00:00:00 2001
From: Rafael Laboissiere <raf...@laboissiere.net>
Date: Wed, 12 Apr 2017 22:18:54 +0200
Subject: [PATCH] Do not fail when heading is at the beginning of the buffer

* org.el (org-forward-heading-same-level): Do not move backward when
at the beginning of the buffer
---
 lisp/org.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 17caa3fa6..b46369ad5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -24071,7 +24071,8 @@ non-nil it will also look at invisible ones."
           (count (if arg (abs arg) 1))
           (result (point)))
       (while (and (prog1 (> count 0)
-		    (forward-char (if (and arg (< arg 0)) -1 1)))
+		    (forward-char (if (and arg (< arg 0))
+				      (if (= (point) 1) 0 -1) 1)))
                   (funcall f org-outline-regexp-bol nil 'move))
         (let ((l (- (match-end 0) (match-beginning 0) 1)))
           (cond ((< l level) (setq count 0))
-- 
2.11.0

Reply via email to