From: Juri Linkov Date: Tue, 29 Apr 2025 16:55:48 +0000 (+0300) Subject: Ignore parens in strings for outline headings in emacs-lisp-mode. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e95d448782d7088a8f015b1693ae28dd5c89e3cc;p=emacs.git Ignore parens in strings for outline headings in emacs-lisp-mode. * lisp/outline.el (outline-font-lock-keywords): For non-nil outline-search-function return a lambda that calls the function, then sets the match data to the end of the line that is equivalent to adding ".*" in the regexp. Then search functions don't need to match ".*" themselves. * lisp/progmodes/elisp-mode.el (elisp-outline-search): New function to skip leading parens in strings when searching for outline headings. (emacs-lisp-mode): Set buffer-local 'outline-search-function' to 'elisp-outline-search'. https://lists.gnu.org/archive/html/emacs-devel/2025-04/msg00934.html (cherry picked from commit 746a3cb3143194436c4a1a63d26aac890c1a705f) --- diff --git a/lisp/outline.el b/lisp/outline.el index 6cfdf1c191e..5eb1852726e 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -261,7 +261,12 @@ non-nil and point is located on the heading line.") (defvar outline-font-lock-keywords '( ;; Highlight headings according to the level. - (eval . (list (or outline-search-function + (eval . (list (or (when outline-search-function + (lambda (limit) + (when-let* ((ret (funcall outline-search-function limit))) + ;; This is equivalent to adding ".*" in the regexp below. + (set-match-data (list (match-beginning 0) (pos-eol))) + ret))) (concat "^\\(?:" outline-regexp "\\).*" outline-heading-end-regexp)) 0 '(if outline-minor-mode (if outline-minor-mode-highlight diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index e46b4d55a11..74aa644d8f9 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -292,6 +292,19 @@ Comments in the form will be lost." (string-to-syntax "'"))))) start end))) +(defun elisp-outline-search (&optional bound move backward looking-at) + "Don't use leading parens in strings for outline headings." + (if looking-at + (and (looking-at outline-regexp) + (save-excursion (not (nth 8 (syntax-ppss (match-beginning 0)))))) + (let ((search-success nil)) + (while (and (setq search-success + (funcall (if backward #'re-search-backward #'re-search-forward) + (concat "^\\(?:" outline-regexp "\\)") + bound (if move 'move t))) + (save-excursion (nth 8 (syntax-ppss (match-beginning 0)))))) + search-success))) + (defcustom emacs-lisp-mode-hook nil "Hook run when entering Emacs Lisp mode." :options '(eldoc-mode imenu-add-menubar-index checkdoc-minor-mode) @@ -655,6 +668,7 @@ be used instead. (add-hook 'xref-backend-functions #'elisp--xref-backend nil t) (setq-local project-vc-external-roots-function #'elisp-load-path-roots) (setq-local syntax-propertize-function #'elisp-mode-syntax-propertize) + (setq-local outline-search-function #'elisp-outline-search) (add-hook 'completion-at-point-functions #'elisp-capf nil 'local) (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)