Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2017-04-15 16:52:46 +02:00
commit 42f24c167c
2 changed files with 79 additions and 26 deletions

View File

@ -24059,32 +24059,27 @@ Stop at the first and last subheadings of a superior heading.
Normally this only looks at visible headings, but when INVISIBLE-OK is Normally this only looks at visible headings, but when INVISIBLE-OK is
non-nil it will also look at invisible ones." non-nil it will also look at invisible ones."
(interactive "p") (interactive "p")
(if (not (ignore-errors (org-back-to-heading invisible-ok))) (let ((backward? (and arg (< arg 0))))
(if (and arg (< arg 0)) (if (org-before-first-heading-p)
(goto-char (point-min)) (if backward? (goto-char (point-min)) (outline-next-heading))
(outline-next-heading)) (org-back-to-heading invisible-ok)
(org-at-heading-p) (unless backward? (end-of-line)) ;do not match current headline
(let ((level (- (match-end 0) (match-beginning 0) 1)) (let ((level (- (match-end 0) (match-beginning 0) 1))
(f (if (and arg (< arg 0)) (f (if backward? #'re-search-backward #'re-search-forward))
're-search-backward (count (if arg (abs arg) 1))
're-search-forward)) (result (point)))
(count (if arg (abs arg) 1)) (while (and (> count 0)
(result (point))) (funcall f org-outline-regexp-bol nil 'move))
(while (and (prog1 (> count 0) (let ((l (- (match-end 0) (match-beginning 0) 1)))
(forward-char (if (and arg (< arg 0)) -1 1))) (cond ((< l level) (setq count 0))
(funcall f org-outline-regexp-bol nil 'move)) ((and (= l level)
(let ((l (- (match-end 0) (match-beginning 0) 1))) (or invisible-ok
(cond ((< l level) (setq count 0)) (not (outline-invisible-p
((and (= l level) (line-beginning-position)))))
(or invisible-ok (cl-decf count)
(progn (when (= l level) (setq result (point)))))))
(goto-char (line-beginning-position)) (goto-char result))
(not (outline-invisible-p))))) (beginning-of-line))))
(setq count (1- count))
(when (eq l level)
(setq result (point)))))))
(goto-char result))
(beginning-of-line 1)))
(defun org-backward-heading-same-level (arg &optional invisible-ok) (defun org-backward-heading-same-level (arg &optional invisible-ok)
"Move backward to the ARG'th subheading at same level as this one. "Move backward to the ARG'th subheading at same level as this one.

View File

@ -2598,6 +2598,64 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
;;; Navigation ;;; Navigation
(ert-deftest test-org/forward-heading-same-level ()
"Test `org-forward-heading-same-level' specifications."
;; Test navigation at top level, forward and backward.
(should
(equal "* H2"
(org-test-with-temp-text "* H1\n* H2"
(org-forward-heading-same-level 1)
(buffer-substring-no-properties (point) (line-end-position)))))
(should
(equal "* H1"
(org-test-with-temp-text "* H1\n<point>* H2"
(org-forward-heading-same-level -1)
(buffer-substring-no-properties (point) (line-end-position)))))
;; Test navigation in a sub-tree, forward and backward.
(should
(equal "* H2"
(org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
(org-forward-heading-same-level 1)
(buffer-substring-no-properties (point) (line-end-position)))))
(should
(equal "* H1"
(org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
(org-forward-heading-same-level -1)
(buffer-substring-no-properties (point) (line-end-position)))))
;; Stop at first or last sub-heading.
(should-not
(equal "* H2"
(org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
(org-forward-heading-same-level 1)
(buffer-substring-no-properties (point) (line-end-position)))))
(should-not
(equal "* H2"
(org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
(org-forward-heading-same-level -1)
(buffer-substring-no-properties (point) (line-end-position)))))
;; Allow multiple moves.
(should
(equal "* H3"
(org-test-with-temp-text "* H1\n* H2\n* H3"
(org-forward-heading-same-level 2)
(buffer-substring-no-properties (point) (line-end-position)))))
(should
(equal "* H1"
(org-test-with-temp-text "* H1\n* H2\n<point>* H3"
(org-forward-heading-same-level -2)
(buffer-substring-no-properties (point) (line-end-position)))))
;; Ignore spurious moves when first (or last) sibling is reached.
(should
(equal "** H3"
(org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
(org-forward-heading-same-level 100)
(buffer-substring-no-properties (point) (line-end-position)))))
(should
(equal "** H1"
(org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
(org-forward-heading-same-level -100)
(buffer-substring-no-properties (point) (line-end-position))))))
(ert-deftest test-org/end-of-meta-data () (ert-deftest test-org/end-of-meta-data ()
"Test `org-end-of-meta-data' specifications." "Test `org-end-of-meta-data' specifications."
;; Skip planning line. ;; Skip planning line.