From 194c28aaf22979d46f22cc424ba8f1bc78db27b3 Mon Sep 17 00:00:00 2001 From: Paul Hsin-ti McClelland Date: Wed, 22 Apr 2026 23:49:09 -0400 Subject: [PATCH] Add outline-search-from-regexp generic helper Add outline-search-from-regexp generic helper (bug#80887) Minor modes and third-party packages that customize 'outline-regexp' typically need an 'outline-search-function' implementation that searches for 'outline-regexp' anchored at beginning of line. Without a generic helper, each such user reinvents the function locally. Add it to outline.el. This pattern has been in production use as a default value of 'outline-search-function' (set via 'setq-default') without issues. * lisp/outline.el (outline-search-from-regexp): New function. * etc/NEWS: Announce it. --- etc/NEWS | 9 +++++++++ lisp/outline.el | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) 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.