[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 746a3cb3143: Ignore parens in strings for outline headings in ema
From: |
Juri Linkov |
Subject: |
master 746a3cb3143: Ignore parens in strings for outline headings in emacs-lisp-mode. |
Date: |
Tue, 29 Apr 2025 12:56:51 -0400 (EDT) |
branch: master
commit 746a3cb3143194436c4a1a63d26aac890c1a705f
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
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
---
lisp/outline.el | 7 ++++++-
lisp/progmodes/elisp-mode.el | 14 ++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lisp/outline.el b/lisp/outline.el
index a53e0a1f070..e484bcef878 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 e8b2a8da65e..a9c00085056 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -287,6 +287,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)
@@ -382,6 +395,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-completion-at-point nil 'local)
(add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 746a3cb3143: Ignore parens in strings for outline headings in emacs-lisp-mode.,
Juri Linkov <=