summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2013-01-01 22:49:12 (GMT)
committer Bastien Guerry <bzg@altern.org>2013-01-01 22:49:12 (GMT)
commit2718888f8e4afcbecb608539b3f16414a7399d3d (patch)
tree66c213afa3d871d610b76161c8c46f2d75c2b3cd
parentbc0b22120347815195657bdee1df35b599e8abe0 (diff)
downloadorg-mode-2718888f8e4afcbecb608539b3f16414a7399d3d.zip
org-mode-2718888f8e4afcbecb608539b3f16414a7399d3d.tar.gz
Fix behavior of `org-forward/backward-h-s-l' before first headline
* org.el (org-forward-heading-same-level): Before the first headline, go to the first headline. (org-backward-heading-same-level): Before the first headline, go to the beginning of the buffer, like `outline-previous-visible-heading' does.
-rw-r--r--lisp/org.el58
1 files changed, 30 insertions, 28 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 1837218..d46b020 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -22382,39 +22382,41 @@ Stop at the first and last subheadings of a superior heading.
Normally this only looks at visible headings, but when INVISIBLE-OK is
non-nil it will also look at invisible ones."
(interactive "p")
- (org-back-to-heading invisible-ok)
- (org-at-heading-p)
- (let* ((level (- (match-end 0) (match-beginning 0) 1))
- (re (format "^\\*\\{1,%d\\} " level))
- l)
- (forward-char 1)
- (while (> arg 0)
- (while (and (re-search-forward re nil 'move)
- (setq l (- (match-end 0) (match-beginning 0) 1))
- (= l level)
- (not invisible-ok)
- (progn (backward-char 1) (outline-invisible-p)))
- (if (< l level) (setq arg 1)))
- (setq arg (1- arg)))
- (beginning-of-line 1)))
+ (if (not (ignore-errors (org-back-to-heading invisible-ok)))
+ (outline-next-heading)
+ (org-at-heading-p)
+ (let* ((level (- (match-end 0) (match-beginning 0) 1))
+ (re (format "^\\*\\{1,%d\\} " level))
+ l)
+ (forward-char 1)
+ (while (> arg 0)
+ (while (and (re-search-forward re nil 'move)
+ (setq l (- (match-end 0) (match-beginning 0) 1))
+ (= l level)
+ (not invisible-ok)
+ (progn (backward-char 1) (outline-invisible-p)))
+ (if (< l level) (setq arg 1)))
+ (setq arg (1- arg)))
+ (beginning-of-line 1))))
(defun org-backward-heading-same-level (arg &optional invisible-ok)
"Move backward to the arg'th subheading at same level as this one.
Stop at the first and last subheadings of a superior heading."
(interactive "p")
- (org-back-to-heading)
- (org-at-heading-p)
- (let* ((level (- (match-end 0) (match-beginning 0) 1))
- (re (format "^\\*\\{1,%d\\} " level))
- l)
- (while (> arg 0)
- (while (and (re-search-backward re nil 'move)
- (setq l (- (match-end 0) (match-beginning 0) 1))
- (= l level)
- (not invisible-ok)
- (outline-invisible-p))
- (if (< l level) (setq arg 1)))
- (setq arg (1- arg)))))
+ (if (not (ignore-errors (org-back-to-heading)))
+ (goto-char (point-min))
+ (org-at-heading-p)
+ (let* ((level (- (match-end 0) (match-beginning 0) 1))
+ (re (format "^\\*\\{1,%d\\} " level))
+ l)
+ (while (> arg 0)
+ (while (and (re-search-backward re nil 'move)
+ (setq l (- (match-end 0) (match-beginning 0) 1))
+ (= l level)
+ (not invisible-ok)
+ (outline-invisible-p))
+ (if (< l level) (setq arg 1)))
+ (setq arg (1- arg))))))
(defun org-forward-element ()
"Move forward by one element.