From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: xref overrides user xref-backend-functions Date: Tue, 1 Dec 2015 22:09:00 +0200 Message-ID: <565DFE5C.4090209@yandex.ru> References: <864mg2u22p.fsf@stephe-leake.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1449000569 4031 80.91.229.3 (1 Dec 2015 20:09:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Dec 2015 20:09:29 +0000 (UTC) To: Stephen Leake , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 01 21:09:24 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a3rEn-0003eq-Rh for ged-emacs-devel@m.gmane.org; Tue, 01 Dec 2015 21:09:21 +0100 Original-Received: from localhost ([::1]:54688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3rEn-0006Uv-72 for ged-emacs-devel@m.gmane.org; Tue, 01 Dec 2015 15:09:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3rEa-0006Uq-M3 for emacs-devel@gnu.org; Tue, 01 Dec 2015 15:09:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3rEW-0000Y1-Gt for emacs-devel@gnu.org; Tue, 01 Dec 2015 15:09:08 -0500 Original-Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:38636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3rEW-0000Xx-8z for emacs-devel@gnu.org; Tue, 01 Dec 2015 15:09:04 -0500 Original-Received: by wmec201 with SMTP id c201so29679569wme.1 for ; Tue, 01 Dec 2015 12:09:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=4Jb8IumKpXo6oFpgUhSjm0Qw8jd5C1kdd759gZJWgxc=; b=WjekPQ/xhIkA7RF16+/d8Q+X5i45zILOZLMq6JfiglMCBVOZE4yrQet82h9jFkpKTY D1LmQ8trXkqtLK0MERAny4EZTztN7PH7aD9GQYpeRxVp8a2U2rM0tsrt80BXHs/f0RR3 AFUPhCmUlV+tuRvVDPwYRliTXLnvrXcyUp+Yq0KQBRp4ZimL+EeCCnboJF7OqKiYGMdC NC5aIFzZyYi5TmaiAXDnvaX3Kqex+F0cQmqF3HOCnNIHpCsW2ASUdu3F+BCKqeELTLIY A64SIzb6zgrH16xntHshPQDsRFJvTMGGtBZPQP9P+6L+tgT4xZzVX3vgiuv/G+DJ2J2f 0Onw== X-Received: by 10.28.176.200 with SMTP id z191mr40169177wme.102.1449000543610; Tue, 01 Dec 2015 12:09:03 -0800 (PST) Original-Received: from [192.168.1.2] ([185.105.175.24]) by smtp.googlemail.com with ESMTPSA id a186sm27470297wmh.4.2015.12.01.12.09.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Dec 2015 12:09:02 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Thunderbird/42.0 In-Reply-To: <864mg2u22p.fsf@stephe-leake.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:195717 Archived-At: 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 ()