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

Wl-draft highlighting using jit-lock-mode



I've just submitted the following patch to David.

-- Juliusz
From 1a974111e5737157fcf1551be66159ed36efe2b0 Mon Sep 17 00:00:00 2001
From: Juliusz Chroboczek <jch@pps.univ-paris-diderot.fr>
Date: Wed, 7 May 2014 00:30:12 +0200
Subject: [PATCH] Implement draft highlighting using jit-lock-mode.

This uses Emacs' 21 native highlighting mechanism, and is enabled
by default if available.  Unlike the timer code, it avoids highlighting
the parts of the buffer that are not currently visible.
---
 wl/wl-draft.el | 46 ++++++++++++++++++++++++++++++++++++----------
 wl/wl-e21.el   |  2 ++
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/wl/wl-draft.el b/wl/wl-draft.el
index b688e57..97607ce 100644
--- a/wl/wl-draft.el
+++ b/wl/wl-draft.el
@@ -541,8 +541,9 @@ or `wl-draft-reply-with-argument-list' if WITH-ARG argument is non-nil."
 	      (wl-draft-add-references)
 	    (if wl-draft-add-in-reply-to
 		(wl-draft-add-in-reply-to)))
-      (wl-highlight-headers 'for-draft)) ; highlight when added References:
-    (when wl-highlight-body-too
+      (unless wl-draft-jit-highlight
+        (wl-highlight-headers 'for-draft))) ; highlight when added References:
+    (when (and wl-highlight-body-too (not wl-draft-jit-highlight))
       (wl-highlight-body-region beg (point-max)))))
 
 (defun wl-message-news-p ()
@@ -1809,7 +1810,8 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
     (when wl-draft-write-file-function
       (add-hook 'local-write-file-hooks wl-draft-write-file-function))
     (wl-draft-overload-functions)
-    (wl-highlight-headers 'for-draft)
+    (unless wl-draft-jit-highlight
+      (wl-highlight-headers 'for-draft))
     (wl-draft-save)
     (clear-visited-file-modtime)))
 
@@ -2013,7 +2015,8 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
       (setq wl-draft-parent-folder ""))
     (when wl-draft-write-file-function
       (add-hook 'local-write-file-hooks wl-draft-write-file-function))
-    (wl-highlight-headers 'for-draft)
+    (unless wl-draft-jit-highlight
+      (wl-highlight-headers 'for-draft))
     (goto-char body-top)
     (run-hooks 'wl-draft-reedit-hook)
     (goto-char (point-max))
@@ -2201,7 +2204,8 @@ Automatically applied in draft sending time."
 	  (setq wl-draft-config-exec-flag nil))
       (run-hooks 'wl-draft-config-exec-hook)
       (put-text-property (point-min)(point-max) 'face nil)
-      (wl-highlight-message (point-min)(point-max) t)
+      (unless wl-draft-jit-highlight
+        (wl-highlight-message (point-min)(point-max) t))
       (setq wl-draft-config-variables
 	    (elmo-uniq-list local-variables)))))
 
@@ -2618,7 +2622,8 @@ been implemented yet.  Partial support for SWITCH-FUNCTION now supported."
 	      t)
 	    (setq headers (cdr headers))))
 	;; highlight headers (from wl-draft in wl-draft.el)
-	(wl-highlight-headers 'for-draft)
+        (unless wl-draft-jit-highlight
+          (wl-highlight-headers 'for-draft))
 	;; insert body
 	(let ((body (wl-string-match-assoc "\\`body\\'"
 					   wl-user-agent-headers-and-body-alist
@@ -2649,8 +2654,20 @@ been implemented yet.  Partial support for SWITCH-FUNCTION now supported."
       (rename-file old-name new-name 'ok-if-already-exists))))
 
 ;; Real-time draft highlighting
+(defcustom wl-draft-jit-highlight (featurep 'jit-lock)
+  "When non-nil, enable real-time highlighting using jit-lock-mode.
+This only works in Emacs 21 and later."
+  :type 'boolean
+  :group 'wl-draft)
+
+(defcustom wl-draft-jit-highlight-function 'wl-draft-default-jit-highlight
+  "The function used for real-time highlighting using jit-lock-mode."
+  :type 'function
+  :group 'wl-draft)
+
 (defcustom wl-draft-idle-highlight t
-  "When non-nil, enable real-time highlighting."
+  "When non-nil, enable real-time highlighting using a timer.
+This is ignored when wl-draft-jit-highlight is set."
   :type 'boolean
   :group 'wl-draft)
 
@@ -2660,10 +2677,19 @@ been implemented yet.  Partial support for SWITCH-FUNCTION now supported."
   :group 'wl-draft)
 
 (defcustom wl-draft-idle-highlight-function 'wl-draft-default-idle-highlight
-  "A function for real-time highlighting."
+  "The function for real-time highlighting using a timer."
   :type 'function
   :group 'wl-draft)
 
+(defun wl-draft-default-jit-highlight (start end)
+  (let ((modified (buffer-modified-p)))
+    (unwind-protect
+         (save-excursion
+           (put-text-property start end 'face nil)
+           (wl-highlight-message start end t
+                                 (not (wl-draft-point-in-header-p))))
+      (set-buffer-modified-p modified))))
+
 (defvar wl-draft-idle-highlight-timer nil)
 
 (defun wl-draft-idle-highlight (&optional state)
@@ -2683,13 +2709,13 @@ If STATE is positive, enable real-time highlighting, and disable it otherwise.
   (save-match-data (wl-draft-highlight)))
 
 (defun wl-draft-idle-highlight-timer (buffer)
-  (when (and wl-draft-idle-highlight
+  (when (and (not wl-draft-jit-highlight) wl-draft-idle-highlight
 	     (buffer-live-p buffer))
     (with-current-buffer buffer
       (funcall wl-draft-idle-highlight-function))))
 
 (defun wl-draft-idle-highlight-set-timer (beg end len)
-  (when wl-draft-idle-highlight
+  (when (and (not wl-draft-jit-highlight) wl-draft-idle-highlight)
     (require 'timer)
     (when (timerp wl-draft-idle-highlight-timer)
       (cancel-timer wl-draft-idle-highlight-timer))
diff --git a/wl/wl-e21.el b/wl/wl-e21.el
index 45d99bb..c31e7f7 100644
--- a/wl/wl-e21.el
+++ b/wl/wl-e21.el
@@ -652,6 +652,8 @@ See info under Wanderlust for full documentation.
 Special commands:
 \\{wl-draft-mode-map}"
     (setq font-lock-defaults nil)
+    (when wl-draft-jit-highlight
+      (jit-lock-register wl-draft-jit-highlight-function))
     (add-hook 'after-change-functions
 	      'wl-draft-idle-highlight-set-timer nil t)
     ))
-- 
1.9.2