From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Signal `quit' in a `font-lock-fontify-region-function' Date: Sat, 29 Jun 2019 17:26:02 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="87677"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Emacs developers To: Paul Pogonyshev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 29 23:26:27 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 1hhKrb-000MiL-7L for ged-emacs-devel@m.gmane.org; Sat, 29 Jun 2019 23:26:27 +0200 Original-Received: from localhost ([::1]:42168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhKra-0000s2-9H for ged-emacs-devel@m.gmane.org; Sat, 29 Jun 2019 17:26:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45595) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhKrJ-0000rn-Dh for emacs-devel@gnu.org; Sat, 29 Jun 2019 17:26:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhKrG-0006El-RA for emacs-devel@gnu.org; Sat, 29 Jun 2019 17:26:09 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39417) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhKrG-0006E3-Id for emacs-devel@gnu.org; Sat, 29 Jun 2019 17:26:06 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 89E88444301; Sat, 29 Jun 2019 17:26:05 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 14E9C4442FB; Sat, 29 Jun 2019 17:26:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1561843564; bh=9WU8Qpk7e5R1+xbY1fw2XNy44JLB4PYZmYQTdm2OSNg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=CsFNAZB118k97tk1Y9tGv5Jj531AXZTqk0FQEiqcLwJ8vGlaOrHECUD1HKDNTddbG hXpbnWK+zFkvRZ1x6xchHi08mFuI/9+tSkR48NeRFfMI2s3onLTM5MsOh3VWU27xuR /mk6ssX6ZrmQ5bDfOZnob3skfeDPMuWlHKSNFyyGQDE3VvEAGnIWm2VunRn+lLc4oZ 9V4kkBPMSEndM9Kct4cBWXmDFS8rdGFiRvvgMPNrS5jpDA1i14aw2XutWXM+KQHjfx gK/1Xbdg6XWB8cxYyF/ZmeLcXK5DhKwJo5JpURns+BtUsxZQkis/Og+Wnrgc8wlTom lba2dH4UXnNcw== Original-Received: from alfajor (76-10-151-214.dsl.teksavvy.com [76.10.151.214]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C2812120046; Sat, 29 Jun 2019 17:26:03 -0400 (EDT) In-Reply-To: (Paul Pogonyshev's message of "Sat, 29 Jun 2019 19:50:13 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 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:238244 Archived-At: > I'm not sure if this is flexible enough. I don't like the idea of C-g > already invoking some code (that e.g. disables font-locking). In my suggestion, C-g wouldn't invoke any significant code. All it would do is setup a timer, and when the timer expires a message would be emitted in the echo area to inform the user what it is that Emacs is currently doing. It definitely wouldn't disable font-locking right away. The disabling would only be in response to a "large" number of C-g, which presumably should only be needed in extreme circumstances (basically when currently the user ends up killing Emacs instead). > So, I'd like to be able to _handle_ `quit' signal in the function > itself and stop extending the region and return immediately, so that I > don't throw away work on a considerable region of text that has been > done already. I don't understand why you say "don't throw away work on a considerable region of text that has been done already": if you're in the middle of extending the region, presumably no "work" has been done yet. > However, fontlocking code shouldn't discard the results > (as otherwise this is pointless). So, I cannot resignal `quit', I > have to return normally. But I also don't want to "eat" this signal > and hide C-g press from Emacs' monitoring code. So basically, I want > font-locking still continue to work for a while, even if C-g has been > pressed too many times, but if so, abort soon. Could `while-no-input` be usable in this case? > I'm not sure if it is the best solution, but I'd propose C-g to be > counted not when `quit' signal is caught, but when it would be > emitted, even if `inhibit-quit' is t. And font-locking code would > look something like this: > > (let ((count-C-g-presses t)) ; Instead of "registering" as you > proposed, I think we just > ; need to tell C-g handler to count > presses while inside > ; certain blocks of code. > (condition-case error > (let ((fontified-region (funcall actual-handler ...))) > ;; Process the fontified region > ...) > (error ;; This logs any errors inside the handler, including uncaught > ;; `quit' signals. Just as now. > ...)) > (when (too-many-C-g-recently) ; This would count both C-g that > resulted in (signal 'quit ...) > ; and those that resulted in > `(setq quit-flag t)'. I think if C-g resulted in (signal 'quit ...), then presumably we exited this code, so the only really interesting case should be the one where we just have `quit-flag` set to t. Maybe we should change the C-g code so it sets `quit-flag` to the number of C-g that are pending. > ;; The below forms are roughly what would be "registered" in your > ;; proposal. I feel leaving it up to the caller gives more > ;; flexibility in actually permorming "abort everything" tasks. > (setq font-lock-mode nil) > (message "Too many C-g, font-locking disabled"))) Maybe when "registering", the code could provide a function to execute instead of "aborting". Stefan