unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* advice after fontify region with c-mode
@ 2023-09-14 20:30 Filippo Argiolas
  2023-09-15  3:43 ` Filippo Argiolas
  0 siblings, 1 reply; 2+ messages in thread
From: Filippo Argiolas @ 2023-09-14 20:30 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

with [1] I'd like to run a function after fontification is completed.

At the moment I'm doing something like this:
         (add-function :after (local 'font-lock-fontify-region-function)
                       #'my-fontify-region-function))

This runs in a hook for eglot-managed-hook.

While this works pretty well with c-ts-mode I'm having some issues
with c-mode because they have a custom fontification function that
extends the region to fontify before funcalling the default fontify
region function.

Relevant code in cc-mode.el is:
- at init
  (make-local-variable 'font-lock-fontify-region-function)
  (setq font-lock-fontify-region-function 'c-font-lock-fontify-region)

- at the end of c-font-lock-fontify-region
     (funcall (default-value 'font-lock-fontify-region-function)
          new-beg new-end verbose)

Problem is my function gets called after c-font-lock-fontify (as I
wanted) but with the original beg end values instead of the extended
new-beg and new-end values.

What am I missing? Any suggestions?

Thanks,
Filippo


1. https://github.com/fargiolas/clangd-inactive-regions



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: advice after fontify region with c-mode
  2023-09-14 20:30 advice after fontify region with c-mode Filippo Argiolas
@ 2023-09-15  3:43 ` Filippo Argiolas
  0 siblings, 0 replies; 2+ messages in thread
From: Filippo Argiolas @ 2023-09-15  3:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Sep 14, 2023 at 10:30 PM Filippo Argiolas
<filippo.argiolas@gmail.com> wrote:
> At the moment I'm doing something like this:
>          (add-function :after (local 'font-lock-fontify-region-function)
>                        #'my-fontify-region-function))

Apparently using local here ends up calling my function after
c-fontify-region-function while I want it to be called after default
fontify region.
This:
         (add-function :after (default-value 'font-lock-fontify-region-function)
                       #'clangd-inactive-regions--fontify))

Seems to do the trick and my function gets properly chained to the
major mode one with the new extended region.
Still open to feedback and suggestions if anyone wants to chime in!

Filippo



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-15  3:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 20:30 advice after fontify region with c-mode Filippo Argiolas
2023-09-15  3:43 ` Filippo Argiolas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).