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: jit-lock-antiblink-grace Date: Sat, 30 Nov 2019 19:11:57 +0000 Message-ID: <87r21ptc02.fsf@gmail.com> References: <83k198ly94.fsf@gnu.org> <83sgnuh5cq.fsf@gnu.org> <87k17qozii.fsf@gmail.com> <83wobps0zy.fsf@gnu.org> <20191125184650.GA4496@ACM> <20191125192628.GC4496@ACM> <20191125201115.GD4496@ACM> <83d0deseo7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="181396"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: acm@muc.de, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 30 20:12:28 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 1ib8AO-000l5H-99 for ged-emacs-devel@m.gmane.org; Sat, 30 Nov 2019 20:12:28 +0100 Original-Received: from localhost ([::1]:37434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ib8AN-0005EF-6y for ged-emacs-devel@m.gmane.org; Sat, 30 Nov 2019 14:12:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49455) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ib8AF-0005E8-VP for emacs-devel@gnu.org; Sat, 30 Nov 2019 14:12:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ib8AE-0001Pm-9D for emacs-devel@gnu.org; Sat, 30 Nov 2019 14:12:19 -0500 Original-Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:35931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ib8AD-0001Nq-Vq; Sat, 30 Nov 2019 14:12:18 -0500 Original-Received: by mail-wr1-x431.google.com with SMTP id z3so38976961wru.3; Sat, 30 Nov 2019 11:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=TuBdohykrJdEpdE+5kTPdDjOKdLLZ6p9StAs11LdzVE=; b=IbrDnQYdgAlU7bleoo7G+yLj00hwzKeB3KwtJqf6ib2zdAktGJ062f85IgC5Mbg1PJ +XUB67Ztd6H7I1QxhHHBa9KOTBQS5Fb/YieCk9I8AVvWhzRwXeECp5ARg4i5PTYmePTS t4pl5vBoksO7aFlkUNYkLaU9VTGi2VTLrZmGjodgIw9U+A72hn7haaCvTjjMaTLtXCUe kbzmbrbWRhDBvsta+ZSjwUgdkAZLm4DXbEhXEV3knnPM1IayHT+yW7hz8LMeLllvIPso IvXqZ++I9vAeU5o7FzQnCEckl+hngMGIUWT9oSmSo+8+ZYmOX+3ME4j3Rujt67qc9I0v Rc7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=TuBdohykrJdEpdE+5kTPdDjOKdLLZ6p9StAs11LdzVE=; b=Hl0O6GY49eITFZH87P1uCRBgykrZVGmlRMcauUvoTAnVz/I8CKY/QbUZv1/TiSmrEY yMCn3Ke1RXhyun9uBRNCi/ppFWyfmqQ1a5OWJtidN6uQAiK+j+eS/PjOAUUfL79iRe6s 0yokhNuT7RQ2ciYDfyHyPbdJTPezlmvN9NH2w2IaG2Q4HgMqsGvtQ00jaA6qLnW4UhFf 1pBrxh+MA31jn7/eksZm+uat2bdrIovurJ373I3CgQ6GT1rXnaWdSTn+Gu7EjzM+vj1K xCYWBc4nm96lzI5sl3nwp01cymYvC3CdlCMWJzcOQ8mlUDDtgtmko6CFn33oSMPphDf4 zIXw== X-Gm-Message-State: APjAAAWIfwe3EyHTVqqqzkBIMfg/UM4VpSAHR3tYUNqjXeV3h8UZSgvs CibLBjk4h5RRYxDvg4heFPQ= X-Google-Smtp-Source: APXvYqyuQQT3a5gjN+fziB7GXl4EYTtXJJ5I5Rv0TyzSb6rEheOrqJg5f2ZKGIuLfbqQaSdrFjTCeQ== X-Received: by 2002:adf:ff84:: with SMTP id j4mr21252810wrr.27.1575141135105; Sat, 30 Nov 2019 11:12:15 -0800 (PST) Original-Received: from lolita.yourcompany.com ([89.180.146.101]) by smtp.gmail.com with ESMTPSA id s8sm16789634wmc.39.2019.11.30.11.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2019 11:12:13 -0800 (PST) In-Reply-To: <83d0deseo7.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 26 Nov 2019 19:58:16 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 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:242919 Archived-At: Eli Zaretskii writes: >> +--- >> +** New customizable variable 'jit-lock-antiblink-grace'. >> +When adding strings to source code, this helps avoid >> +\"blinking\", an unwanted oscillation of certain regions between >> +string and non-string fontification. > > Escaping quotes in NEWS is not needed/expected. Fixed. > And this entry doesn't say what is the default value, and doesn't tell > how to get back old behavior. Fixed. I didn't mention because I found examples in NEWS that don't. But mostly because we haven't come to a decision yet. I generally agree with Stefan and I propose the latest patch with the default value of 2 seconds for jit-lock-antiblink-grace. However, I have detected a case where jit-lock-antiblink-grace kicks in and, while not exactly causing a regression in useful behaviour, also doesn't add any useful behaviour. Here is the case: a. You want to make a string region in a non-string buffer of 10 lines between line 3 and 7. b. You go to line 7 and type a quote c. You go to line 3 and type a quote Previously, after step b) you would get lines 8, 9, and 10 (and 7 partially) string-fontified "immediately". Now, after step b), and _if stay on the same line_, it takes 2 seconds for lines 7-10 to be string-fontified. If you leave line 7 in your journey to line 3 before those 2 seconds are up, 7-10 are immediately string-fontified (and the old and new version become identical in behaviour). It may be argued by users that create strings like this that the antiblink grace timer wasn't useful at all, or that it mis-fired: these users were already counting on (temporarily) invalidly fontified lines 7-10, so they were suprised that it didn't happen immediately (or rather that it didn't happen after a short jit-lock-context-time delay). I think most users will do step c) before step b), and this doesn't present any problem. >> +(defcustom jit-lock-antiblink-grace 2 >> + "Idle time after which to refontify due to unterminated strings. >> +If the user creates a temporarily unterminated string up to the >> +end of the current line, that part of the line is fontified after >> +`jit-lock-context-time', but an extended idle \"grace\" period of >> +this many seconds is granted before deciding it is a multi-line >> +string and fontifying the remainder of the buffer accordingly. >> +When adding strings to source code, this helps avoid >> +\"blinking\", an unwanted oscillation of certain regions between >> +string and non-string fontification. If nil, there is no grace >> +period." > > This is too wordy. If you think this description is necessary, we > probably need to move most of it into the user manual. Fixed. Tho you'll see it was about as wordy as the other jit-lock defcustoms preceding it. Hope it's better now. >> + :type '(number :tag "seconds") >> + :group 'jit-lock) > > Missing :version. Fixed. >> + (when jit-lock--antiblink-grace-timer >> + ;; Do refontify immediately, adding a small delay. This >> + ;; is per Lars' request, and it makes sense because we > ^^^^^^^^^^^^^^^^^ > Let's leave personae out of the code, okay? I really meant the person. But okay. Jo=C3=A3o diff --git a/etc/NEWS b/etc/NEWS index 7e86ccc71e..2f2acd52ac 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -604,6 +604,13 @@ If the region is active, the command joins all the lin= es in the region. When there's no active region, the command works on the current and the previous or the next line, as before. =20 +--- +** New customizable variable 'jit-lock-antiblink-grace'. +When typing strings, this helps avoid "blinking", an oscillation +between string and non-string fontification. The variable holds a +number of seconds (default is 2) before a potentially unwanted +fontification starts. Set to nil to deactivate. + * Changes in Specialized Modes and Packages in Emacs 27.1 =20 diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 48998a81fe..c896c9d5ea 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el @@ -123,6 +123,20 @@ jit-lock-context-time :type '(number :tag "seconds") :group 'jit-lock) =20 +(defcustom jit-lock-antiblink-grace 2 + "Grace period after which to refontify due to unterminated strings. +If nil, no grace period is given. Otherwise, a newly created +unterminated string is fontified only to the end of the current +line, after which the system waits this many seconds of idle time +before deciding the string is multi-line and fontifying the +remaining lines. When typing strings, this helps avoid +\"blinking\", an unwanted oscillation between string and +non-string fontification." + :type '(choice (const :tag "never" nil) + (number :tag "seconds")) + :group 'jit-lock + :version "27.1") + (defcustom jit-lock-defer-time nil ;; 0.25 "Idle time after which deferred fontification should take place. If nil, fontification is not deferred. @@ -157,6 +171,13 @@ jit-lock-defer-buffers "List of buffers with pending deferred fontification.") (defvar jit-lock-stealth-buffers nil "List of buffers that are being fontified stealthily.") + +(defvar jit-lock--antiblink-grace-timer nil + "Idle timer for fontifying unterminated string or comment, or nil.") +(defvar jit-lock--antiblink-line-beginning-position (make-marker) + "Last line beginning position after last command (a marker).") +(defvar jit-lock--antiblink-string-or-comment nil + "Non-nil if in string or comment after last command (a boolean).") ;;; JIT lock mode =20 @@ -232,7 +253,10 @@ 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))) + (lambda () + (unless jit-lock--antiblink-grace-tim= er + (jit-lock-context-fontify)))))) + (add-hook 'post-command-hook 'jit-lock--antiblink-post-command nil t) (setq jit-lock-context-unfontify-pos (or jit-lock-context-unfontify-pos (point-max)))) =20 @@ -669,6 +693,54 @@ jit-lock-after-change ;; buffer, only jit-lock-context-* will re-fontify it. (min jit-lock-context-unfontify-pos jit-lock-start)))))) =20 +(defun jit-lock--antiblink-post-command () + (let* ((new-l-b-p (copy-marker (line-beginning-position))) + (l-b-p-2 (line-beginning-position 2)) + (same-line + (and jit-lock-antiblink-grace + (not (=3D new-l-b-p l-b-p-2)) + (eq (marker-buffer jit-lock--antiblink-line-beginning-posit= ion) + (current-buffer)) + (=3D new-l-b-p jit-lock--antiblink-line-beginning-position)= )) + (new-s-o-c + (and same-line + (nth 8 (save-excursion (syntax-ppss l-b-p-2)))))) + (cond (;; opened a new multiline string... + (and same-line + (null jit-lock--antiblink-string-or-comment) new-s-o-c) + (setq jit-lock--antiblink-grace-timer + (run-with-idle-timer jit-lock-antiblink-grace nil + (lambda () + (jit-lock-context-fontify) + (setq jit-lock--antiblink-grace-ti= mer + nil))))) + (;; closed an unterminated multiline string. + (and same-line + (null new-s-o-c) jit-lock--antiblink-string-or-comment) + ;; Kill the grace timer, might already have run and died. + ;; Don't refontify immediately: it adds an unreasonable + ;; delay to a well-behaved operation. Leave it for the + ;; `jit-lock-context-timer' as usual. + (when jit-lock--antiblink-grace-timer + (cancel-timer jit-lock--antiblink-grace-timer) + (setq jit-lock--antiblink-grace-timer nil))) + (same-line + ;; in same line, but no state change, leave everything as it was + ) + (t + ;; left the line somehow or customized feature away, etc + ;; kill timer if running, resume normal operation. + (when jit-lock--antiblink-grace-timer + ;; Do refontify immediately, adding a small delay. This + ;; makes sense because it remarks somehow that we are + ;; leaving the unstable state. + (jit-lock-context-fontify) + (cancel-timer jit-lock--antiblink-grace-timer) + (setq jit-lock--antiblink-grace-timer nil)))) + ;; update variables + (setq jit-lock--antiblink-line-beginning-position new-l-b-p + jit-lock--antiblink-string-or-comment new-s-o-c))) + (provide 'jit-lock) =20 ;;; jit-lock.el ends here