From 07106cecf5468b7c6ba8702df3655215364eb704 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 21 Aug 2024 12:20:43 +0200 Subject: [PATCH] (elisp-fontify-region-semantically): Keep existing faces Also catch error when fontifying syntactically incorrect code --- lisp/progmodes/elisp-mode.el | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 6678b727a8e..11a1ecd01e8 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -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 -- 2.39.2