[Top][All Lists]

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

[elpa] master 26f48c5 06/21: Improve Font Lock integration.

From: Jackson Ray Hamilton
Subject: [elpa] master 26f48c5 06/21: Improve Font Lock integration.
Date: Fri, 23 Dec 2016 20:27:51 +0000 (UTC)

branch: master
commit 26f48c5ffa4fb7e5ce672f1e308a892482ba404f
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Improve Font Lock integration.
    Advising this function, which does nothing when Context Coloring is enabled,
    allows for modes that would normally flush Font Lock to instead trigger 
    Coloring colorization.
    In particular, when prettify-symbols-mode is enabled after
    context-coloring-mode, the buffer's symbols will immediately be prettified.
 context-coloring.el |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/context-coloring.el b/context-coloring.el
index 814466b..0d5b72c 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -427,6 +427,24 @@ permissible.")
 (defvar context-coloring-interruptable-p t
   "When non-nil, coloring may be interrupted by user input.")
+(defvar context-coloring-mode)
+(defun context-coloring-around-font-lock-flush (oldfun &rest r)
+  "Advice around `font-lock-flush' for this mode only."
+  (if context-coloring-mode
+      (apply #'context-coloring-font-lock-flush r)
+    (apply oldfun r)))
+(defun context-coloring-font-lock-flush (&optional start end)
+  "Reimplementation of `font-lock-flush' for this mode.
+The original relies on Font Lock variables that would be messy to
+maintain here."
+  (let* ((start (or start (point-min)))
+         (end (or end (point-max)))
+         (length (- end start)))
+    (context-coloring-change-function start end length)
+    (context-coloring-maybe-colorize-with-buffer (current-buffer))))
 (define-minor-mode context-coloring-mode
   "Toggle contextual code coloring.
@@ -464,6 +482,11 @@ Feature inspired by Douglas Crockford."
         ;; Safely change the value of this function as necessary.
         (make-local-variable 'font-lock-syntactic-face-function)
+        ;; Improve integration with modes relying on Font Lock.  Here, attempts
+        ;; to refontify in Font Lock contexts will instead refontifiy in 
+        ;; Coloring contexts.  This is necessary for `prettify-symbols-mode'
+        ;; integration.
+        (advice-add #'font-lock-flush :around 
         (let ((setup (plist-get dispatch :setup)))
           (when setup
             (funcall setup))

reply via email to

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