0

I'm not sure what kind of variable xref-backend-functions and how to update it.

After I open a .c file, I do M-: and do

(add-hook 'xref-backend-functions #'gxref-xref-backend)

and it shows me

(gxref-xref-backend etags--xref-backend)

So it looks updated, but then if I do M-: and type

xref-backend-functions

emacs shows me

(eglot-xref-backend t)

And so xref-backend-functions is not updated.

1 Answer 1

1

It's a hook variable. A hook variable has a global part, and the buffer-local part(s), the latter can be different between many modes.

In your example (eglot-xref-backend t) is a buffer-local value (with the special element t meaning to run the global value's functions as well), and (gxref-xref-backend etags--xref-backend) is the global value (which you updated with add-hook).

The usual way to update the buffer-local value is to pass the LOCAL=t argument to add-hook because the local values usually takes precedence over the global one.

The code which would call add-hook usually resides in some minor mode. But if you are writing your personal customization, you could put it in a function which is in turn added to some major mode hook. To c-mode-hook, for instance.

As a result the local value in c-mode buffers will be altered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.