diff --git a/lisp/org.el b/lisp/org.el index 71dbc611e..8e0040814 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20478,6 +20478,18 @@ entry." ((looking-at-p re) (forward-line)) (t (throw 'exit t)))))))) + +(defcustom org-navigate-invisible-headings nil + "If non-nil, navigate through (unfolded) invisible headings normally. +Commands such as `org-forward-heading-same-level' and +`org-forward-heading-same-level' will consider all invisible +headings except for those that are invisible due to folding of a +headline, a block or a drawer." + :group 'org + :type '(choice + (const :tag "Don't navigate invisible headings" nil) + (const :tag "Navigate invisible (unfolded) headings" t))) + (defun org-forward-heading-same-level (arg &optional invisible-ok) "Move forward to the ARG'th subheading at same level as this one. Stop at the first and last subheadings of a superior heading. @@ -20498,9 +20510,11 @@ non-nil it will also look at invisible ones." (let ((l (- (match-end 0) (match-beginning 0) 1))) (cond ((< l level) (setq count 0)) ((and (= l level) - (or invisible-ok + (or (and invisible-ok + (not org-navigate-invisible-headings)) (not (org-invisible-p - (line-beginning-position))))) + (line-beginning-position) + org-navigate-invisible-headings)))) (cl-decf count) (when (= l level) (setq result (point))))))) (goto-char result))