emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master e848ef1 323/433: * mmm-fontify-region: Save and restore su


From: Dmitry Gutov
Subject: [elpa] master e848ef1 323/433: * mmm-fontify-region: Save and restore submode, overlay and local vars
Date: Thu, 15 Mar 2018 19:44:28 -0400 (EDT)

branch: master
commit e848ef181e347c4d1484349047e3ea0003b16783
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    * mmm-fontify-region: Save and restore submode, overlay and local vars
    
    This function is called from different positions, so just calling
    `mmm-update-submode-region' at the end is not enough.
---
 mmm-region.el | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/mmm-region.el b/mmm-region.el
index 1c86422..69b62ea 100644
--- a/mmm-region.el
+++ b/mmm-region.el
@@ -769,23 +769,31 @@ of the REGIONS covers START to STOP."
 
 (defun mmm-fontify-region (start stop &optional loudly)
   "Fontify from START to STOP keeping track of submodes correctly."
-  (when loudly
-    (message "Fontifying %s with submode regions..." (buffer-name)))
-  ;; Necessary to catch changes in font-lock cache state and position.
-  (mmm-save-changed-local-variables
-   mmm-current-overlay mmm-current-submode)
-  ;; For some reason `font-lock-fontify-block' binds this to nil, thus
-  ;; preventing `mmm-beginning-of-syntax' from doing The Right Thing.
-  ;; I don't know why it does this, but let's undo it here.
-  (let ((font-lock-beginning-of-syntax-function 'mmm-beginning-of-syntax))
-    (mapc #'(lambda (elt)
-                (when (get (car elt) 'mmm-font-lock-mode)
-                  (mmm-fontify-region-list (car elt) (cdr elt))))
-            (mmm-regions-alist start stop)))
-  ;; It's in `post-command-hook' too, but that's executed before font-lock,
-  ;; so the latter messes up local vars (such as line-indent-function)
-  ;; until after the next command.
-  (mmm-update-submode-region)
+  (let ((saved-mode mmm-current-submode)
+        (saved-pos (and mmm-current-overlay
+                        (overlay-start mmm-current-overlay))))
+    (unwind-protect
+        (progn
+          (when loudly
+            (message "Fontifying %s with submode regions..." (buffer-name)))
+          ;; Necessary to catch changes in font-lock cache state and position.
+          (mmm-save-changed-local-variables
+           mmm-current-overlay mmm-current-submode)
+          ;; For some reason `font-lock-fontify-block' binds this to nil, thus
+          ;; preventing `mmm-beginning-of-syntax' from doing The Right Thing.
+          ;; I don't know why it does this, but let's undo it here.
+          (let ((font-lock-beginning-of-syntax-function 
'mmm-beginning-of-syntax))
+            (mapc #'(lambda (elt)
+                      (when (get (car elt) 'mmm-font-lock-mode)
+                        (mmm-fontify-region-list (car elt) (cdr elt))))
+                  (mmm-regions-alist start stop))))
+      (save-excursion
+        ;; `post-command-hook' contains `mmm-update-submode-region',
+        ;; but jit-lock runs later, so we need to restore local vars now.
+        (goto-char (or saved-pos (point-min)))
+        (mmm-set-current-submode saved-mode)
+        ;; This looks for the current overlay at point to set region locals.
+        (mmm-set-local-variables saved-mode))))
   (when loudly (message nil)))
 
 (defun mmm-fontify-region-list (mode regions)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]