]> git.eshelyaron.com Git - emacs.git/commitdiff
Ignore parens in strings for outline headings in emacs-lisp-mode.
authorJuri Linkov <juri@linkov.net>
Tue, 29 Apr 2025 16:55:48 +0000 (19:55 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 1 May 2025 07:24:00 +0000 (09:24 +0200)
* 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)

lisp/outline.el
lisp/progmodes/elisp-mode.el

index 6cfdf1c191e37e4925d2e0f32189c774b33dd9a6..5eb1852726ebfa2eab13fd722f7ef8e9426436cc 100644 (file)
@@ -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
index e46b4d55a1122457c03d957d40a6e40cd78a596a..74aa644d8f9cc7d14c1dc49e4b6462d77d410fe3 100644 (file)
@@ -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)