From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode Date: Thu, 11 Jul 2019 17:13:20 +0100 Message-ID: References: <20190708100539.GD4529@ACM> <20190708164501.GB5244@ACM> <20190708180551.GD5244@ACM> <20190709160022.GC5230@ACM> <20190709182646.GD5230@ACM> <20190710103242.GB4109@ACM> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003c4b1c058d6a13cf" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="233112"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Stefan Monnier , emacs-devel To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 11 18:22:40 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hlbqB-000y6o-6g for ged-emacs-devel@m.gmane.org; Thu, 11 Jul 2019 18:22:39 +0200 Original-Received: from localhost ([::1]:43332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbhT-00018V-32 for ged-emacs-devel@m.gmane.org; Thu, 11 Jul 2019 12:13:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38441) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlbhP-00015s-EA for emacs-devel@gnu.org; Thu, 11 Jul 2019 12:13:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlbhN-00018Q-Ou for emacs-devel@gnu.org; Thu, 11 Jul 2019 12:13:35 -0400 Original-Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:36804) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hlbhN-00015B-Ih for emacs-devel@gnu.org; Thu, 11 Jul 2019 12:13:33 -0400 Original-Received: by mail-io1-xd41.google.com with SMTP id o9so13814588iom.3 for ; Thu, 11 Jul 2019 09:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pJ5181vbaD5uCWUVzGLfrpZciz/c5DVw19o0O3Pvnsw=; b=LX8oY6+vnLRygOzcalzM0CCKjjB0V0eXeehqu4vAtVagFfJg7xaoPwDgZFVez8g/BT GLGDbYJNw2TtLvgh85urjBmbPWJ48DCYjgL4NVbH90vcxbEuPpn2za2ZzNtWBH4dv+Ls OXITKgkjby2dd8kopAuUNUzoYp0HvTTmILn7VuK6qpfTFiVuPoM9e/DruDAWAkKJN1dM FpysPMKIlhZ+Hbe2HfjVA65KQ1sRNvTaZyFTZ052UHwmlIiL/zaLuv6EWu1DkVPPqMPZ jpu8dBH8yqGPf51R1W9WOz4uIflzMLY46uXxfI2egVRwL4fMuN4+wn1GvUm7IDNH+Nuj 5QXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pJ5181vbaD5uCWUVzGLfrpZciz/c5DVw19o0O3Pvnsw=; b=dCyrsOOZzcCQixbuGmvo+owq1ipfXJdnYCRRMsXtewIGr7VwifyxvWYy6mMHtQ9oMW 1KxLgbl2MrY5c1ADM8BzH39GC07eILiG5fEMOZn/TnWwBsLGvuv9IjAab1JwI6fwSTQd iqn4gCYHB51Y5AfOoSO+16SnCoFnK7XF8mrDwlouNhmgGO8o/GJs9aXadoNg7270+vex 2L/AQy26hktds3mDjJELTkfvb5x2gjJat7Nfud7rP3Hdx2+a1rB2dKoWX8unfkfshldu jEwQWX1SviPKERbbtHF/arq2GGDpOS+M/7iOeZj0y/QuSXPBtK6CThrilJ6J1YwkK8gw 9QAA== X-Gm-Message-State: APjAAAWMYYU8KA9ZOmTgrxkV4Jaq2z5+OYT5YMHb1BVNWE4zy6RHV8Vr bBq3mCDc/n71OwP9m15PwxxF85PJJIPBs4X9F516C4BxCfA= X-Google-Smtp-Source: APXvYqwvhk7+8snNAM3XnTuWrFKOeh07Eo+Nhqi48NKKj8sm9z8407jPbEYtjvoQpKYfTRzzl3/ClD7i8Hsn48p0MOU= X-Received: by 2002:a6b:dd18:: with SMTP id f24mr4931747ioc.97.1562861612320; Thu, 11 Jul 2019 09:13:32 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d41 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238512 Archived-At: --0000000000003c4b1c058d6a13cf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jul 11, 2019 at 4:51 PM Lars Ingebrigtsen wrote: > > Jo=C3=A3o T=C3=A1vora 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 ni= l + ) + (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 --0000000000003c4b1c058d6a13cf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Jul 11, 2019 at 4:51 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
>= Jo=C3=A3o T=C3=A1vora <joaotavo= ra@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...=C2=A0 I'm ge= tting "malformed patch"...

Some Gmail me= ssup, maybe (my Gnus configuration is broken in
sometimes).<= /div>

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

> &g= t; + =C2=A0"Like `jit-lock-context-time' but for unterminated mult= iline strings.
> > +If the user has just opened an unterminated st= ring 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 ma= ny seconds."
>
> I think this is a good idea.=C2=A0 A slig= ht tweak to this would be to do the
> fontifying immediately if the u= ser moves off of the line with the
> unterminated string, too.

You mean after the system has discovered that he/sh= e has recently
created an string? If so, it makes sense. Otherwis= e we would be
context-fontifying more frequently than we did befo= re, 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 +1= 23,15 @@ jit-lock-context-time
=C2=A0 =C2=A0:type '(number :tag &quo= t;seconds")
=C2=A0 =C2=A0:group 'jit-lock)
=C2=A0
+(defcu= stom jit-lock-multiline-string-grace 2
+ =C2=A0"Like `jit-lock-cont= ext-time' but for unterminated multiline strings.
+If the user has j= ust opened an unterminated string at EOL, give
+him/her some grace time = before deciding it is a multi-line string
+and fontifying accordingly, d= o so only if the user stares idle at
+that string for more than this man= y seconds."
+ =C2=A0:type '(number :tag "seconds")+ =C2=A0:group 'jit-lock)
+
=C2=A0(defcustom jit-lock-defer-time= nil ;; 0.25
=C2=A0 =C2=A0"Idle time after which deferred fontifica= tion should take place.
=C2=A0If nil, fontification is not deferred.
= @@ -232,7 +241,7 @@ jit-lock-mode
=C2=A0 =C2=A0 =C2=A0 =C2=A0(unless jit= -lock-context-timer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq jit-lock-con= text-timer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(run-w= ith-idle-timer jit-lock-context-time t
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 'jit-lock-context-fontify)))
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (jit--lock-context-timer-function))))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0(setq jit-lock-context-unfontify-pos
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or jit-lock-context-unfontify-pos (point= -max))))
=C2=A0
@@ -306,6 +315,44 @@ jit-lock--debug-fontify
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pos 'fontified))))))))= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq jit-lock-defer-buffers nil))))
=C2= =A0
+(defun jit--lock-context-timer-function ()
+ =C2=A0(let (last = =C2=A0 =C2=A0 =C2=A0 =C2=A0; point marker the last time context timer was r= un
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0in-s-or-c-p ; t if in string or comment = that time around
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0grace-timer ; idle timer f= or fontifying unterminated s-or-c, or nil
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0)=
+ =C2=A0 =C2=A0(lambda ()
+ =C2=A0 =C2=A0 =C2=A0(let ((point (point-= marker))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(new-in-s-or-c-p
= + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (nth 8 (save-excursion (syntax-= ppss (line-end-position))))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (and jit-= lock-multiline-string-grace
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 last
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (eq (marker-buffer last) (current-buffer))
+ =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (eq (line-number-at-pos last) (line-num= ber-at-pos)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cond ((and (nu= ll in-s-or-c-p) new-in-s-or-c-p (null grace-timer))
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq grace-timer
+ =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (run-with-idle-timer jit-lock-multiline-string-grace nil
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(lambda ()
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(jit-lock-context-fontify)
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(setq grace-timer nil)))))
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((and in-s-or-c-p
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(n= ull new-in-s-or-c-p)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0grace-timer)
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cancel-timer grace-timer)
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq grace-= timer nil))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(t
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ;; no state change, leave everything as it was
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ))
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0;; left the line somehow or customized feature away: cancel+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; everything, resume normal operation= .
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when grace-timer
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cancel-timer grace-timer)
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq grace-timer nil)))
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0;; proceed as usual, unless grace-timer is counting
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0(unless grace-timer
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(jit-lock-context-fontify))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq= last point in-s-or-c-p new-in-s-or-c-p)))))
+
+
=C2=A0(defun jit-= lock-register (fun &optional contextual)
=C2=A0 =C2=A0"Register= FUN as a fontification function to be called in this buffer.
=C2=A0FUN = will be called with two arguments START and END indicating the region
--0000000000003c4b1c058d6a13cf--