all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Signal `quit' in a `font-lock-fontify-region-function'
Date: Sun, 30 Jun 2019 12:51:41 +0200	[thread overview]
Message-ID: <CAG7Bpap10_ZW=xB3cyQmL+VO9ko6M=rWXPZSgxLupTK9ED-Ojw@mail.gmail.com> (raw)
In-Reply-To: <jwv7e94kk2y.fsf-monnier+emacs@gnu.org>

> 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 <monnier@iro.umontreal.ca> 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
>



  reply	other threads:[~2019-06-30 10:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-29 17:50 Signal `quit' in a `font-lock-fontify-region-function' Paul Pogonyshev
2019-06-29 21:26 ` Stefan Monnier
2019-06-29 23:49   ` Paul Pogonyshev
2019-06-30  0:18     ` Stefan Monnier
2019-06-30 10:51       ` Paul Pogonyshev [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-05-28 16:24 Paul Pogonyshev
2019-05-28 17:50 ` Stefan Monnier
2019-05-28 18:14   ` Paul Pogonyshev
2019-05-28 18:24     ` Stefan Monnier
2019-05-16 22:20 Paul Pogonyshev
2019-05-16 23:20 ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to='CAG7Bpap10_ZW=xB3cyQmL+VO9ko6M=rWXPZSgxLupTK9ED-Ojw@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=emacs-devel@gnu.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.