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

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

[elpa] master 5837c90 066/433: Fixed font-lock woes (hopefully).


From: Dmitry Gutov
Subject: [elpa] master 5837c90 066/433: Fixed font-lock woes (hopefully).
Date: Thu, 15 Mar 2018 19:43:36 -0400 (EDT)

branch: master
commit 5837c906f07f49e61b023ab6416bbe7f93114733
Author: mas <mas>
Commit: mas <mas>

    Fixed font-lock woes (hopefully).
---
 mmm-auto.el   | 12 +++++++-----
 mmm-cmds.el   | 46 +++++++++++++++++++++++-----------------------
 mmm-mode.el   | 17 ++++++++---------
 mmm-region.el | 34 ++++++++++++++++++++++++++++------
 mmm-utils.el  | 19 +++++++++++--------
 5 files changed, 77 insertions(+), 51 deletions(-)

diff --git a/mmm-auto.el b/mmm-auto.el
index b43a350..a21b198 100644
--- a/mmm-auto.el
+++ b/mmm-auto.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-auto.el,v 1.9 2000/06/29 18:23:41 mas Exp $
+;; Version: $Id: mmm-auto.el,v 1.10 2000/06/30 02:43:01 mas Exp $
 
 ;;{{{ GPL
 
@@ -107,9 +107,10 @@ everything in `mmm-major-mode-hook' will be run."
   "Run major mode hook for the buffers in `mmm-changed-buffers-list'."
   (remove-hook 'post-command-hook 'mmm-check-changed-buffers)
   (dolist (buffer mmm-changed-buffers-list)
-    (and (not (window-minibuffer-p (get-buffer-window buffer)))
-         (buffer-live-p buffer)
-         (mmm-run-major-mode-hook buffer)))
+    (when (buffer-live-p buffer)
+      (save-excursion
+        (set-buffer buffer)
+        (mmm-run-major-mode-hook))))
   (setq mmm-changed-buffers-list '()))
 
 (defun mmm-mode-on-maybe ()
@@ -118,7 +119,8 @@ Turn on MMM Mode if `global-mmm-mode' is non-nil and there 
are classes
 to apply, or always if `global-mmm-mode' is t."
   (cond ((eq mmm-global-mode t) (mmm-mode-on))
         ((not mmm-global-mode))
-        ((mmm-get-all-classes) (mmm-mode-on))))
+        ((mmm-get-all-classes nil) (mmm-mode-on)))
+  (mmm-update-font-lock-buffer))
 
 (add-hook 'mmm-major-mode-hook 'mmm-mode-on-maybe)
 
diff --git a/mmm-cmds.el b/mmm-cmds.el
index 63b8c1b..d1878e0 100644
--- a/mmm-cmds.el
+++ b/mmm-cmds.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-cmds.el,v 1.6 2000/06/27 00:34:02 mas Exp $
+;; Version: $Id: mmm-cmds.el,v 1.7 2000/06/30 02:41:36 mas Exp $
 
 ;;{{{ GPL
 
@@ -42,9 +42,7 @@
   (interactive "SSubmode Class: ")
   (mmm-apply-class class)
   (mmm-add-to-history class)
-  (and (featurep 'font-lock)
-       font-lock-mode
-       (font-lock-fontify-buffer)))
+  (mmm-update-font-lock-buffer))
 
 ;;}}}
 ;;{{{ Applying by the Region
@@ -56,12 +54,10 @@
   (setq front (mmm-make-marker front t nil)
         back (mmm-make-marker back nil nil))
   (mmm-add-to-history `(:submode ,submode :front ,front :back ,back))
-  (and (featurep 'font-lock)
-       font-lock-mode
-       (font-lock-fontify-buffer)))
+  (mmm-enable-font-lock submode))
 
 ;;}}}
-;;{{{ Applying simple Regexps
+;;{{{ Applying Simple Regexps
 
 (defun mmm-ify-by-regexp
   (submode front front-offset back back-offset save-matches)
@@ -78,9 +74,7 @@ nNumber of matched substrings to save: ")
                 front-offset back-offset save-matches)))
     (apply #'mmm-ify args)
     (mmm-add-to-history args))
-  (and (featurep 'font-lock)
-       font-lock-mode
-       (font-lock-fontify-buffer)))
+  (mmm-enable-font-lock submode))
 
 ;;}}}
 ;;{{{ Re-parsing Areas
@@ -250,22 +244,28 @@ MODIFIERS, the dotted list becomes simply BASIC-KEY."
         (destructuring-bind (back end beg front) skeleton-positions
           ;; TODO: Find a way to trap invalid-parent signals from
           ;; make-region and undo the skeleton insertion.
-          (mmm-make-region (plist-get class :submode) beg end
-                           :front (buffer-substring front beg)
-                           :back (buffer-substring end back)
-                           :face (plist-get class :face)
-                           :beg-sticky (plist-get class :beg-sticky)
-                           :end-sticky (plist-get class :end-sticky))
-          (and (featurep 'font-lock)
-               font-lock-mode
-               (font-lock-fontify-region front back)))))))
+          (let* ((match-submode (plist-get class :match-submode))
+                 (front-str (buffer-substring front beg))
+                 (back-str (buffer-substring end back))
+                 (submode
+                  (if match-submode
+                      (mmm-save-all (funcall match-submode front-str))
+                    (plist-get class :submode))))
+            (mmm-make-region
+             submode beg end :front front-str :back back-str
+             :face (plist-get class :face)
+             :beg-sticky (plist-get class :beg-sticky)
+             :end-sticky (plist-get class :end-sticky)
+             :creation-hook (plist-get class :creation-hook))
+            (mmm-enable-font-lock submode)))))))
 
 (defun mmm-get-insertion-spec (key &optional classlist)
   "Get the insertion info for KEY from all classes in CLASSLIST.
 Return \(CLASS SKEL STR) where CLASS is the class spec a match was
 found in, SKEL is the skeleton to insert, and STR is the argument.
-CLASSLIST defaults to the return value of `mmm-get-all-classes'."
-  (loop for classname in (or classlist (mmm-get-all-classes))
+CLASSLIST defaults to the return value of `mmm-get-all-classes',
+including global classes."
+  (loop for classname in (or classlist (mmm-get-all-classes t))
         for class = (mmm-get-class-spec classname)
         for inserts = (plist-get class :insert)
         for skel = (cddr (assoc key inserts))
@@ -323,7 +323,7 @@ is a symbol naming the insertion."
 Elements look like \(KEY NAME ...) where KEY is an insertion key and
 NAME is a symbol naming the insertion."
   (remove-duplicates
-   (loop for classname in (or classlist (mmm-get-all-classes))
+   (loop for classname in (or classlist (mmm-get-all-classes t))
          for class = (mmm-get-class-spec classname)
          append (plist-get class :insert) into keys
          ;; If we have a group class, recurse.
diff --git a/mmm-mode.el b/mmm-mode.el
index 5368198..bacc376 100644
--- a/mmm-mode.el
+++ b/mmm-mode.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1999 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-mode.el,v 1.5 2000/06/26 22:20:48 mas Exp $
+;; Version: $Id: mmm-mode.el,v 1.6 2000/06/30 02:41:53 mas Exp $
 ;; Keywords: convenience faces languages tools
 
 ;;{{{ GPL
@@ -95,6 +95,7 @@
 (require 'mmm-class)
 ;; This file is set up to autoload by `mmm-auto.el'.
 ;; (require 'mmm-cmds)
+(require 'mmm-univ)
 
 ;;{{{ Toggle Function
 
@@ -328,11 +329,10 @@ Programming | Tools | Mmm, except the major mode and 
submode hooks
      (mmm-set-local-variables major-mode)
      (mmm-add-hooks)
      (mmm-fixup-skeleton)
-     (when (featurep 'font-lock)
-       (make-local-variable 'font-lock-fontify-region-function)
-       (make-local-variable 'font-lock-beginning-of-syntax-function)
-       (setq font-lock-fontify-region-function 'mmm-fontify-region
-             font-lock-beginning-of-syntax-function 'mmm-beginning-of-syntax))
+     (make-local-variable 'font-lock-fontify-region-function)
+     (make-local-variable 'font-lock-beginning-of-syntax-function)
+     (setq font-lock-fontify-region-function 'mmm-fontify-region
+           font-lock-beginning-of-syntax-function 'mmm-beginning-of-syntax)
      (setq mmm-mode t)
      (condition-case err
          (mmm-apply-all)
@@ -359,9 +359,8 @@ Programming | Tools | Mmm, except the major mode and 
submode hooks
     (mmm-clear-mode-ext-classes)
     (mmm-clear-local-variables)
     (mmm-update-submode-region)
-    (and (featurep 'font-lock)
-         font-lock-mode
-         (font-lock-fontify-buffer))
+    (mmm-update-font-lock-buffer)
+    (mmm-refontify-maybe)
     (setq mmm-mode nil)))
 
 (add-to-list 'minor-mode-alist (list 'mmm-mode mmm-mode-string))
diff --git a/mmm-region.el b/mmm-region.el
index b9ccf43..788c853 100644
--- a/mmm-region.el
+++ b/mmm-region.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-region.el,v 1.14 2000/06/29 18:48:47 mas Exp $
+;; Version: $Id: mmm-region.el,v 1.15 2000/06/30 02:43:17 mas Exp $
 
 ;;{{{ GPL
 
@@ -515,6 +515,26 @@ region and mode for the previous position."
        (get mode 'mmm-font-lock-mode)
        (font-lock-mode 1)))
 
+(defun mmm-update-font-lock-buffer ()
+  "Turn on font lock iff any mode in the buffer enables it."
+  (if (some #'(lambda (mode)
+                (get mode 'mmm-font-lock-mode))
+            (remove-duplicates
+             (cons major-mode
+                   (mapcar #'(lambda (ovl)
+                               (overlay-get ovl 'mmm-mode))
+                           (mmm-overlays-in (point-min) (point-max))))))
+      (font-lock-mode 1)
+    (font-lock-mode 0)))
+
+(defun mmm-refontify-maybe (&optional start stop)
+  "Re-fontify from START to STOP, or entire buffer, if enabled."
+  (and font-lock-mode
+       (if (or start stop)
+           (font-lock-fontify-region (or start (point-min))
+                                     (or stop (point-max)))
+         (font-lock-fontify-buffer))))
+
 ;;}}}
 ;;{{{ Get Submode Regions
 
@@ -566,6 +586,9 @@ of the REGIONS covers START to STOP."
   "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.
@@ -583,10 +606,6 @@ of the REGIONS covers START to STOP."
     (let ((major-mode mode)
           (func (get mode 'mmm-fontify-region-function)))
       (mapcar #'(lambda (reg)
-                  ;; Next line is necessary to catch changes in
-                  ;; font-lock cache state and position.
-                  (mmm-save-changed-local-variables
-                   mmm-current-overlay mmm-current-submode)
                   (goto-char (car reg))
                   ;; Here we do the same sort of thing that
                   ;; `mmm-update-submode-region' does, but we force it
@@ -594,7 +613,10 @@ of the REGIONS covers START to STOP."
                   ;; fontify, or change the mode line.
                   (mmm-set-current-submode mode)
                   (mmm-set-local-variables mode)
-                  (funcall func (car reg) (cadr reg) nil))
+                  (funcall func (car reg) (cadr reg) nil)
+                  ;; Catch changes in font-lock cache.
+                  (mmm-save-changed-local-variables
+                   mmm-current-overlay mmm-current-submode))
               regions))))
 
 ;;}}}
diff --git a/mmm-utils.el b/mmm-utils.el
index 8225037..8f61810 100644
--- a/mmm-utils.el
+++ b/mmm-utils.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-utils.el,v 1.5 2000/06/30 00:47:23 mas Exp $
+;; Version: $Id: mmm-utils.el,v 1.6 2000/06/30 02:42:05 mas Exp $
 
 ;;{{{ GPL
 
@@ -39,16 +39,19 @@
 ;; only `mmm-mode-on' really needs it. Kept it as a macro, though,
 ;; for modularity and in case we need it somewhere else.
 (defmacro mmm-valid-buffer (&rest body)
-  "Execute BODY if in a valid buffer for MMM Mode to be enabled.
-This means if not currently in one of the temporary buffers that MMM
-Mode creates, and not in one of `mmm-never-modes'."
-  `(unless (or (equal (buffer-name) mmm-temp-buffer-name)
+  "Execute BODY if in a valid buffer for MMM Mode to be enabled.  This
+means not hidden, not a minibuffer, not in batch mode, and not in of
+`mmm-never-modes'."
+  `(unless (or (eq (aref (buffer-name) 0) ?\ )
+               (window-minibuffer-p (selected-window))
                (memq major-mode mmm-never-modes)
                noninteractive
-               (eq (aref (buffer-name) 0) ?\ ))
+               ;; Unnecessary as now hidden
+;;;               (equal (buffer-name) mmm-temp-buffer-name)
+               )
      ,@body))
 
-(def-edebug-spec mmm-valid-buffer t)
+;;;(def-edebug-spec mmm-valid-buffer t)
 
 ;;}}}
 ;;{{{ Save Everything
@@ -62,7 +65,7 @@ restrictions, and match data."
        (save-match-data
          ,@body))))
 
-(def-edebug-spec mmm-save-all t)
+;;;(def-edebug-spec mmm-save-all t)
 
 ;;}}}
 ;;{{{ String Formatting



reply via email to

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