all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Stephen Leake <stephen_leake@stephe-leake.org>, emacs-devel@gnu.org
Subject: Re: xref overrides user xref-backend-functions
Date: Tue, 1 Dec 2015 22:09:00 +0200	[thread overview]
Message-ID: <565DFE5C.4090209@yandex.ru> (raw)
In-Reply-To: <864mg2u22p.fsf@stephe-leake.org>

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

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

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
> xref-backend-functions.

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)

  ;;;###autoload
  (defun xref-find-backend ()




  reply	other threads:[~2015-12-01 20:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01  6:15 xref overrides user xref-backend-functions Stephen Leake
2015-12-01 20:09 ` Dmitry Gutov [this message]
2015-12-01 23:41   ` Stephen Leake
2015-12-02  2:08     ` Dmitry Gutov
     [not found] <CABr8ebbkBS+45FV-3h5ZuVLMTS3DU53h4OYm9XRuLzp4gQg7BA@mail.gmail.com>
2015-12-02 12:13 ` Dmitry Gutov

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=565DFE5C.4090209@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=stephen_leake@stephe-leake.org \
    /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.