diff --git a/etc/NEWS b/etc/NEWS index b60d1788e91..b76b18cdc8c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -117,6 +117,15 @@ obsolete. It is bound to 'C-e' and reveals the current entry with its parent hierarchy. +--- +*** New function 'outline-search-from-regexp'. +A generic 'outline-search-function' implementation driven by +'outline-regexp', suitable for modes or minor modes that customize +'outline-regexp' but do not need a custom search strategy. +Install it with: + + (setq-local outline-search-function #'outline-search-from-regexp) + * New Modes and Packages in Emacs 32.1 diff --git a/lisp/outline.el b/lisp/outline.el index 79bb8982e4e..3eb354a22ce 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -1550,6 +1550,26 @@ The rest of arguments are described in `outline-search-function'." (when move (goto-char (or bound (if backward (point-min) (point-max))))) nil)))) + +;;; Search regexp for outline headings + +;;;###autoload +(defun outline-search-from-regexp (&optional bound move backward looking-at) + "Search for the next heading matching `outline-regexp'. +The arguments BOUND, MOVE, BACKWARD, and LOOKING-AT are described +in `outline-search-function'. This function is intended to be +used in `outline-search-function' by modes and minor modes that +customize `outline-regexp' but do not need a custom search strategy. +Install it with + + (setq-local outline-search-function #\\='outline-search-from-regexp)" + (if looking-at + (looking-at outline-regexp) + (funcall (if backward #'re-search-backward #'re-search-forward) + (concat "^\\(?:" outline-regexp "\\)") + bound + (if move 'move t)))) + (defun outline-headers-as-kill (beg end) "Save the visible outline headers between BEG and END to the kill ring.