[Top][All Lists]

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

Re: xref overrides user xref-backend-functions

From: Dmitry Gutov
Subject: Re: xref overrides user xref-backend-functions
Date: Tue, 1 Dec 2015 22:09:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Thunderbird/42.0

On 12/01/2015 08:15 AM, Stephen Leake wrote:

      (setq xref-backend-functions (lambda () 'my-xref-backend))
      (require 'xref)

I don't think we've ever discussed being able to override the backend from the init file like that.

This gives:

(etags--xref-backend (lambda nil (quote my-xref-backend)))

which is not what I want.

There's nothing surprising about it, though.

This needs a comment on why etags--xref-backend is not set in the
default value of the variable; it's not clear to me based on the bug
report, and the bug report is not referenced from the code.

Either we do it like this, or we ask every piece of code that wants to (add-hook 'xref-backend-functions ...), to (require 'xref) first. And if it doesn't do that, the default value of xref-backend-functions is lost.

Almost none hook variables have default values, but many add to it after the definition using `add-hook'. So I did the same.

I think a good fix is to not add the hook if already set:

(unless xref-backend-functions
  (add-hook 'xref-backend-functions #'etags--xref-backend))

This works for my use case, and for bug#21964.

This will make things worse when someone else writes (add-hook 'xref-backend-functions 'bar-backend) with the intention of seeing the element added to the beginning of the list, but still fall back to etags when their function fails.

An alternate work-around is to require xref before setting

That's one valid approach.

How about this, though?

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 8a69b07..cddb017 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -210,7 +210,7 @@ xref-backend-functions

 ;; We make the etags backend the default for now, until something
 ;; better comes along.
-(add-hook 'xref-backend-functions #'etags--xref-backend)
+(add-hook 'xref-backend-functions #'etags--xref-backend t)

 (defun xref-find-backend ()

reply via email to

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