]> git.eshelyaron.com Git - emacs.git/commitdiff
(elisp-fontify-region-semantically): Keep existing faces
authorEshel Yaron <me@eshelyaron.com>
Wed, 21 Aug 2024 10:20:43 +0000 (12:20 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 21 Aug 2024 10:20:43 +0000 (12:20 +0200)
Also catch error when fontifying syntactically incorrect code

lisp/progmodes/elisp-mode.el

index 6678b727a8e6654f5d32989d00fd9357830ed301..11a1ecd01e8092d3ad7ccc5c73be392b62647c9a 100644 (file)
@@ -389,11 +389,12 @@ happens in interactive invocations."
                                   (function 'font-lock-function-call-face)
                                   (defun    'font-lock-function-name-face)
                                   (defvar   'font-lock-variable-name-face))))
-                 (put-text-property sym (+ sym len) 'face face))
-             (put-text-property sym (+ sym len) 'face
-                                (if (equal sym bind)
-                                    'elisp-binding-variable
-                                  'elisp-bound-variable))
+                 (add-face-text-property sym (+ sym len) face t))
+             (add-face-text-property sym (+ sym len)
+                                     (if (equal sym bind)
+                                         'elisp-binding-variable
+                                       'elisp-bound-variable)
+                                     t)
              (put-text-property sym (+ sym len 1) 'cursor-sensor-functions
                                 ;; Get a fresh list with SYM hardcoded,
                                 ;; so that the value is distinguishable
@@ -407,15 +408,18 @@ happens in interactive invocations."
 Non-nil optional argument LOUDLY permits printing status messages.
 
 This is the `font-lock-fontify-region-function' for `emacs-lisp-mode'."
-  (if elisp-fontify-semantically
-      (let ((beg (save-excursion (goto-char beg) (beginning-of-defun) (point)))
-            (end (save-excursion (goto-char end) (end-of-defun)
-                                 (skip-chars-backward " \t\n")
-                                 (point))))
-        (font-lock-default-fontify-region beg end loudly)
-        (elisp-fontify-region-semantically beg end)
-        `(jit-lock-bounds ,beg . ,end))
-    (font-lock-default-fontify-region beg end loudly)))
+  (or (and elisp-fontify-semantically
+           (condition-case nil
+               (let ((beg (save-excursion (goto-char beg) (beginning-of-defun)
+                                          (point)))
+                     (end (save-excursion (goto-char end) (end-of-defun)
+                                          (skip-chars-backward " \t\n")
+                                          (point))))
+                 (font-lock-default-fontify-region beg end loudly)
+                 (elisp-fontify-region-semantically beg end)
+                 `(jit-lock-bounds ,beg . ,end))
+             (scan-error nil)))
+      (font-lock-default-fontify-region beg end loudly)))
 
 ;;;###autoload
 (define-derived-mode emacs-lisp-mode lisp-data-mode