unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
Date: Thu, 11 Jul 2019 17:13:20 +0100	[thread overview]
Message-ID: <CALDnm50SNOqK_xC4VvPMXE+KG8z06d_sSLvm1rz+AapyG1BPkQ@mail.gmail.com> (raw)
In-Reply-To: <m3tvbsvabf.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 4770 bytes --]

On Thu, Jul 11, 2019 at 4:51 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> João Távora <joaotavora@gmail.com> writes:
>
> > 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.
>
> Hm...  I'm getting "malformed patch"...

Some Gmail messup, maybe (my Gnus configuration is broken in
sometimes).

I try again at the end of this mail, after having asked gmail
to send unformatted text.

> > +  "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."
>
> I think this is a good idea.  A slight tweak to this would be to do the
> fontifying immediately if the user moves off of the line with the
> unterminated string, too.

You mean after the system has discovered that he/she has recently
created an string? If so, it makes sense. Otherwise we would be
context-fontifying more frequently than we did before, and that
could create a performance problem.

I'll add this to the TODO list.

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

[-- Attachment #2: Type: text/html, Size: 5827 bytes --]

  reply	other threads:[~2019-07-11 16:13 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190702131632.GA30597@ACM>
     [not found] ` <CALDnm51Hi10KMqYneWBamNL4sNdzHEz6_NasGk=oR_y-=1Y7nQ@mail.gmail.com>
2019-07-02 15:27   ` Fwd: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode João Távora
     [not found]   ` <20190702160410.GB30597@ACM>
2019-07-02 17:22     ` João Távora
2019-07-02 18:28       ` bug#36474: " Alan Mackenzie
2019-07-02 21:11         ` Stefan Monnier
2019-07-03  9:28         ` João Távora
2019-07-03 10:58           ` Alan Mackenzie
2019-07-03 13:07             ` Dmitry Gutov
2019-07-03 13:32               ` Alan Mackenzie
2019-07-03 14:25                 ` Dmitry Gutov
2019-07-03 15:58                 ` Eli Zaretskii
2019-07-03 20:54                   ` Alan Mackenzie
2019-07-04  2:33                     ` Eli Zaretskii
2019-07-04  1:36                 ` Richard Stallman
2019-07-03 13:33               ` Eli Zaretskii
2019-07-03 13:35               ` João Távora
2019-07-03 13:31             ` João Távora
2019-07-03 18:25               ` Kévin Le Gouguec
2019-07-04  0:52                 ` João Távora
2019-07-04  6:17                   ` Kévin Le Gouguec
2019-07-04 15:05               ` Alan Mackenzie
2019-07-04 15:50                 ` João Távora
2019-07-04 16:58               ` [PATCH] " Alan Mackenzie
2019-07-04 18:45                 ` João Távora
2019-07-04 19:01                   ` Alan Mackenzie
2019-07-04 21:44                     ` João Távora
2019-07-08 10:05                       ` Alan Mackenzie
2019-07-08 12:10                         ` João Távora
2019-07-08 15:49                         ` Stefan Monnier
2019-07-08 16:33                           ` Stefan Monnier
2019-07-08 17:24                             ` Alan Mackenzie
2019-07-08 17:32                               ` Stefan Monnier
2019-07-08 16:45                           ` Alan Mackenzie
2019-07-08 17:29                             ` Stefan Monnier
2019-07-08 18:05                               ` Alan Mackenzie
2019-07-08 20:59                                 ` Stefan Monnier
2019-07-09  6:41                                   ` Clément Pit-Claudel
2019-07-09  9:06                                     ` João Távora
2019-07-09  9:23                                       ` João Távora
2019-07-09  9:52                                         ` Alan Mackenzie
2019-07-09 10:54                                           ` João Távora
2019-07-09 11:18                                             ` João Távora
2019-07-09 15:18                                             ` Dmitry Gutov
2019-07-09 15:40                                               ` contextual refontification (was: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode) Stefan Monnier
2019-07-10  9:32                                                 ` João Távora
2019-07-09 15:43                                               ` [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode João Távora
2019-07-09 15:31                                             ` Alan Mackenzie
2019-07-09 16:14                                               ` João Távora
2019-07-09 12:33                                       ` Clément Pit-Claudel
2019-07-09 14:28                                         ` João Távora
2019-07-09 16:05                                           ` Clément Pit-Claudel
2019-07-09 16:32                                             ` João Távora
2019-07-09 17:09                                               ` João Távora
2019-07-09 13:45                                     ` Stefan Monnier
2019-07-09 16:00                                   ` Alan Mackenzie
2019-07-09 17:11                                     ` Stefan Monnier
2019-07-09 18:26                                       ` Alan Mackenzie
2019-07-09 18:47                                         ` Eli Zaretskii
2019-07-09 18:53                                         ` João Távora
2019-07-10 10:32                                           ` Alan Mackenzie
2019-07-10 10:40                                             ` Lars Ingebrigtsen
2019-07-10 12:24                                               ` João Távora
2019-07-10 14:14                                                 ` Clément Pit-Claudel
2019-07-10 16:07                                                   ` João Távora
2019-07-11 15:14                                                 ` Lars Ingebrigtsen
2019-07-11 15:43                                                   ` João Távora
2019-07-11 15:51                                                     ` Lars Ingebrigtsen
2019-07-11 16:13                                                       ` João Távora [this message]
2019-07-12 15:58                                                         ` Lars Ingebrigtsen
2019-07-12 18:47                                                           ` João Távora
2019-07-13  0:08                                                             ` Lars Ingebrigtsen
2019-07-10 12:10                                             ` João Távora
2019-07-10 14:03                                               ` Alan Mackenzie
2019-07-10 16:05                                                 ` João Távora
2019-07-10 17:56                                                   ` Alan Mackenzie
2019-07-11  0:11                                                     ` Richard Stallman
2019-07-03 16:56             ` Stefan Monnier
2019-07-03 16:58             ` Stefan Monnier
2019-07-04 15:24               ` Alan Mackenzie
2019-07-04 15:52                 ` Stefan Monnier
2019-07-04 16:42                   ` Alan Mackenzie
2019-07-04 20:16                     ` Stefan Monnier
2019-07-04 21:27                     ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALDnm50SNOqK_xC4VvPMXE+KG8z06d_sSLvm1rz+AapyG1BPkQ@mail.gmail.com \
    --to=joaotavora@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).