emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Signal `quit' in a `font-lock-fontify-region-function'


From: Paul Pogonyshev
Subject: Re: Signal `quit' in a `font-lock-fontify-region-function'
Date: Sun, 30 Jun 2019 12:51:41 +0200

> 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 <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]