[Top][All Lists]

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

Re: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuita

From: João Távora
Subject: Re: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
Date: Thu, 11 Jul 2019 16:43:21 +0100

It's another subject split from this thread, started by Stefan, with
a few messages only. But here it is again, and a little animated gif
I made yesterday but forgot to attach.


diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el
index 48998a81fe..8481e8ebb0 100644
--- a/lisp/jit-lock.el
+++ b/lisp/jit-lock.el
@@ -123,6 +123,15 @@ jit-lock-context-time
   :type '(number :tag "seconds")
   :group 'jit-lock)
+(defcustom jit-lock-multiline-string-grace 2
+  "Like `jit-lock-context-time' but for unterminated multiline strings.
+If the user has just opened an unterminated string at EOL, give
+him/her some grace time before deciding it is a multi-line string
+and fontifying accordingly, do so only if the user stares idle at
+that string for more than this many seconds."
+  :type '(number :tag "seconds")
+  :group 'jit-lock)
 (defcustom jit-lock-defer-time nil ;; 0.25
   "Idle time after which deferred fontification should take place.
 If nil, fontification is not deferred.
@@ -232,7 +241,7 @@ jit-lock-mode
       (unless jit-lock-context-timer
         (setq jit-lock-context-timer
               (run-with-idle-timer jit-lock-context-time t
-                                   'jit-lock-context-fontify)))
+                                   (jit--lock-context-timer-function))))
       (setq jit-lock-context-unfontify-pos
             (or jit-lock-context-unfontify-pos (point-max))))
@@ -306,6 +315,44 @@ jit-lock--debug-fontify
                                    pos 'fontified)))))))))
       (setq jit-lock-defer-buffers nil))))
+(defun jit--lock-context-timer-function ()
+  (let (last        ; point marker the last time context timer was run
+        in-s-or-c-p ; t if in string or comment that time around
+        grace-timer ; idle timer for fontifying unterminated s-or-c, or nil
+        )
+    (lambda ()
+      (let ((point (point-marker))
+            (new-in-s-or-c-p
+             (nth 8 (save-excursion (syntax-ppss (line-end-position))))))
+        (if (and jit-lock-multiline-string-grace
+                 last
+                 (eq (marker-buffer last) (current-buffer))
+                 (eq (line-number-at-pos last) (line-number-at-pos)))
+            (cond ((and (null in-s-or-c-p) new-in-s-or-c-p (null grace-timer))
+                   (setq grace-timer
+                         (run-with-idle-timer jit-lock-multiline-string-grace nil
+                                              (lambda ()
+                                                (jit-lock-context-fontify)
+                                                (setq grace-timer nil)))))
+                  ((and in-s-or-c-p
+                        (null new-in-s-or-c-p)
+                        grace-timer)
+                   (cancel-timer grace-timer)
+                   (setq grace-timer nil))
+                  (t
+                   ;; no state change, leave everything as it was
+                   ))
+          ;; left the line somehow or customized feature away: cancel
+          ;; everything, resume normal operation.
+          (when grace-timer
+            (cancel-timer grace-timer)
+            (setq grace-timer nil)))
+        ;; proceed as usual, unless grace-timer is counting
+        (unless grace-timer
+          (jit-lock-context-fontify))
+        (setq last point in-s-or-c-p new-in-s-or-c-p)))))
 (defun jit-lock-register (fun &optional contextual)
   "Register FUN as a fontification function to be called in this buffer.
 FUN will be called with two arguments START and END indicating the region

On Thu, Jul 11, 2019 at 4:15 PM Lars Ingebrigtsen <address@hidden> wrote:
João Távora <address@hidden> writes:

> I do understand the suffering of those that don't use e-p-m. It's
> one of the reasons that I started using it.  But if you don't want
> to for any reason, I posted a patch to jit-lock.el in the split thread
> that should  reduce if not eliminate the blinking you suffer. 

It's a pretty long thread, and I couldn't find the patch.  :-/  Could
you repost?

(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

João Távora

Attachment: blinking-no-blinking.gif
Description: GIF image

reply via email to

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