From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: Re: Signal `quit' in a `font-lock-fontify-region-function' Date: Sun, 30 Jun 2019 12:51:41 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="227253"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 30 12:59:46 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 1hhXYg-000wzl-1N for ged-emacs-devel@m.gmane.org; Sun, 30 Jun 2019 12:59:46 +0200 Original-Received: from localhost ([::1]:43946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhXYe-0004MC-Ee for ged-emacs-devel@m.gmane.org; Sun, 30 Jun 2019 06:59:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51708) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhXRE-0002d5-2R for emacs-devel@gnu.org; Sun, 30 Jun 2019 06:52:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhXR8-00064O-Kr for emacs-devel@gnu.org; Sun, 30 Jun 2019 06:52:01 -0400 Original-Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:40777) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hhXR4-0005xH-9N for emacs-devel@gnu.org; Sun, 30 Jun 2019 06:51:57 -0400 Original-Received: by mail-wr1-x435.google.com with SMTP id p11so10679487wre.7 for ; Sun, 30 Jun 2019 03:51:53 -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=5z93R+1vuT42o3WDgu6niGr18vm7xBNIvGeqbtSWnBo=; b=ngq7otQMoinKKpVVK1OQZXLp5qIv2nLPEW/sZfGzqHxT+ARsqNt0/kTUpegMSLRaRB L+kxlothVGAoa/4uLoVGmVxRDfW1NW2Lo8TKDOSLPBfpdzyVooz9JFZSssjMGo7Y/QhQ RAu7ZKmtXU89hlts4q8e6KWjmdLyPGs9uueajmehILfYZjSEyU4Rrg3XU1oJBbDn/PA9 GSamJ9RnGHwKdAkp4s38w+lTUU3ffIcBLuLmPbpIALfPJpsjoR0jLQP/Z4yaWHsX+7O1 5Xf5ducye5e44PRgDvLp5xsO1Np5ktUkXOf06rPQ/obr/rCoan9necSYSW6g1nIsmakz ipnA== 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=5z93R+1vuT42o3WDgu6niGr18vm7xBNIvGeqbtSWnBo=; b=iVGzxGjUZZtZOtmcWxnEtemcjoeVr1SyGFWkapSANed737bqOxIajety0M2coVD+M+ Dt5bwKPCIDtOusAOp6dmurXbsNZvRT0V9Ln5l96RlF77+O8xdxATsB9B2a6pbS32UzVU st5Zu+tAKW4uizNrs3J1RiomaZX28vVfdvW8n425cprJEVWE9f1hK8YcFCXc43SOSDCX g1McsF2pGcyAU3wXzEPIS26DWUYpJ7qPJjtVdta82gj0mWv1g8xs3IRNlninZm31iUNw 2cO4v1GAfgpoAxDsOiKGx9DsAQsVzTOj84z4hAgg7LckEq439h4eHeMOY0pnp5Z8w/cX 7M7g== X-Gm-Message-State: APjAAAWWzTB1p4v6g480Z/JQWyQg0SVl7Ca0IMJ2gQhEh58BjudmRz4a 805aVIkIKo6bxXD4aiRLq4y3TIB+9mrUCSd7j8scctU= X-Google-Smtp-Source: APXvYqxT5GpCnobMXNTyOsVZb5kYQ3gw2ZIz00eZcE1kAibq/wxZ0AVL93RtDJkpVT1UqkE1cWNrVxZumpApGG2+B6I= X-Received: by 2002:adf:f84a:: with SMTP id d10mr7959086wrq.319.1561891912163; Sun, 30 Jun 2019 03:51:52 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::435 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:238250 Archived-At: > Your bounds-extension code could re-bind registered-many-C-g-callback to > do something less drastic than disable font-lock-mode (or exit brutally > from font-lock). The point is that I _do_ want to disable font-lock-mode after N C-g presses. But I also want my fontification function return normally after C-g (including Nth press) to preserve non-trivial amount of work that has been done. In principle, as long as font-locking code can finish fontification iteration normally even if it is disabled in the middle of it (because of Nth C-g), then your proposed solution is also fine for my usecase. I.e.: (let ((registered-many-C-g (cons "font-locking..." registered-many-C-g))) ; call fontification function, process its result etc. ; nowhere inside this let-block it checks if `font-lock-mode' ; is still enabled. only next iteration may be cancelled by ; setting `font-lock-mode' to nil, not the ongoing one. ) On Sun, 30 Jun 2019 at 02:18, Stefan Monnier wrote: > > > So, basically, as I understand, C-g handler in your proposal would > > look like (I know it is in C code, but...), simplified: > > > > (defun handle-C-g (...) > > (when registered-many-C-g-callback ; variable set by e.g. > > font-locking code > > (setq num-C-g-presses (1+ num-C-g-presses)) > > (when (> num-C-g-presses 3) > > (funcall registered-many-C-g-callback)))) > > Not quite, more like: > > (defvar registered-many-C-g-callback (lambda () (signal 'quit nil))) > (defvar registered-many-C-g nil) > > (defun handle-C-g (...) > (when registered-many-C-g > (setq num-C-g-presses (1+ num-C-g-presses)) > (when (> num-C-g-presses 3) > (funcall registered-many-C-g-callback)))) > > > and font-locking code would be roughly > > > > (let ((registered-many-C-g-callback (lambda () (setq font-lock-mode nil)))) > > ; call fontification function, process its result etc. > > ) > > More like: > > (let ((registered-many-C-g (cons "font-locking..." registered-many-C-g))) > ; call fontification function, process its result etc. > ) > > But, yes, maybe it would provide a callback to disable font-lock-mode, > or just catch the `quit` signal and disable font-lock-mode. > > > `count-C-g-presses' to t. The idea is to not invoke the "abort" > > callback immediately when the 3rd C-g is pressed, but instead let the > > iteration finish gracefully and _then_ let the higher-level code > > Your bounds-extension code could re-bind registered-many-C-g-callback to > do something less drastic than disable font-lock-mode (or exit brutally > from font-lock). > > > Stefan >