From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) Newsgroups: gmane.emacs.devel Subject: xref backends for elisp-related modes Was: Re: Bad moves with xref-find-definitions Date: Sun, 26 Apr 2015 12:51:00 +0100 Message-ID: References: <87h9s6c27z.fsf@gmail.com> <87zj5wnlyt.fsf@gmail.com> <553C285B.4070400@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1430049090 1173 80.91.229.3 (26 Apr 2015 11:51:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Apr 2015 11:51:30 +0000 (UTC) Cc: Vitalie Spinu , Stefan Monnier , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 26 13:51:25 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 1YmL5n-0007PX-Rh for ged-emacs-devel@m.gmane.org; Sun, 26 Apr 2015 13:51:24 +0200 Original-Received: from localhost ([::1]:50470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YmL5n-0006IC-13 for ged-emacs-devel@m.gmane.org; Sun, 26 Apr 2015 07:51:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YmL5a-0006I6-EZ for emacs-devel@gnu.org; Sun, 26 Apr 2015 07:51:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YmL5V-0003kK-Br for emacs-devel@gnu.org; Sun, 26 Apr 2015 07:51:10 -0400 Original-Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:33302) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YmL5V-0003kG-0m for emacs-devel@gnu.org; Sun, 26 Apr 2015 07:51:05 -0400 Original-Received: by wiax7 with SMTP id x7so64494384wia.0 for ; Sun, 26 Apr 2015 04:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=4BC0xeEE/iO1f1sEjFL3H8tOlDdQNR+W6R08CnsOpS8=; b=jKFtzBF5XBZyKy9VNq36ufZSYlyWDuV8n7brfqN2BGbLrbwW1xQlyC2FYe6WCspgOX y+hJFMaSuDAs4RqUrQoxqKixbtFLNrOBNdm2dHtrKgW8eLT37a5/HvH3V7x9LShTaQJS zB2wCoF4//V7bB6dXISTIKE16xky+t2rZCPD4gtYhJuug/Q/r2rh5uYy74A+0R8kzFVs VKDNLqUhKHKnn18E32Q6T0N4nRsgIq7/NYuxxCdtj7ezczbtRqNial5vKg721z+EMo0T XC+9qVEOtanPHmzyNKMHilxKydIyguxR4XgN9SoWmXu8QSBhfcZM7zKRzVsBvZAfxBVe d2Bw== X-Received: by 10.180.81.70 with SMTP id y6mr11982773wix.47.1430049064102; Sun, 26 Apr 2015 04:51:04 -0700 (PDT) Original-Received: from holy.lan.yourcompany.com (31.57.37.188.rev.vodafone.pt. [188.37.57.31]) by mx.google.com with ESMTPSA id ln8sm24824719wjc.18.2015.04.26.04.51.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2015 04:51:03 -0700 (PDT) In-Reply-To: <553C285B.4070400@yandex.ru> (Dmitry Gutov's message of "Sun, 26 Apr 2015 02:50:51 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::235 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:185906 Archived-At: Dmitry Gutov writes: > On 04/25/2015 09:56 PM, joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) wrot= e: > >> While we're on the subject, is a patch welcome to set >> `xref-find-function' to `elisp-xref-find' more pervasively in the >> apropos, debugger and help buffers? > > I'm fine with that, but the effect will also make it harder for Eli to > undo that change. :) Dunno how important that is. > > See http://debbugs.gnu.org/19466. I've read/skimmed it. Indeed, it's not acceptable to force users to customize their xref-finding backend in emacs-lisp-mode, its derived modes (lisp-interaction-mode), or its related modes (elisp apropos, help, debugger), if, for some reason, they believe etags is a better backend for them in certain contexts. BTW the necessary level of indirection is already present with `advice-add': we needn't necessarily add more variables. I mean: (advice-add 'elisp-xref-find :override #'etags-xref-find) Should be enough and quite readable. Conversely, I wouldn't be very annoyed if etags were the default method of finding elisp xrefs. Then I would use advice-add to set my behaviour, perhaps by doing (advice-add 'elisp-xref-find :override #'elisp-compiled-identifier-locations) ; better name pending Additionally, if `add-function' allowed `:append' for its WHERE arg, like Common Lisp's method combinations, it would be even cleaner to get the behaviour desired by Eli (and Vitalie, I think), of multiple backends. (advice-add 'elisp-xref-find :append #'etags-xref-find) >> The patch attached does this to a certain degree, but takes some care to >> not do this is the major mode's definitions, since in theory these modes >> could be used for something other than emacs-lisp. > > Makes sense. It does, I know, but it would be a lot simpler, especially for functions spawning *Help* buffers, to just assume we're in an elisp-related context. Packages like SLIME or SLY or CIDER that make use of these major modes should be the ones overriding the backend. >> +(advice-add 'describe-mode :after #'help--setup-xref-find-function) >> +(advice-add 'describe-function :after #'help--setup-xref-find-function) >> +(advice-add 'describe-variable :after #'help--setup-xref-find-function) >> +(advice-add 'describe-bindings :after #'help--setup-xref-find-function) > > Why not add the call to the command definitions directly? Because there are a lot more "describe-*" functions, and ideally, one would want to advise them on a predictable pattern, not clutter each `describe-*''s sometimes intricate design with pin-pointed calls to a setup function. Anyway, this problem goes away if we take the simpler approach of just setting it in the major-mode function. It makes the resulting patch a lot simpler. Jo=C3=A3o PS: here's my latest version diff --git a/lisp/apropos.el b/lisp/apropos.el index 023ba4b..492d9d7 100644 --- a/lisp/apropos.el +++ b/lisp/apropos.el @@ -475,7 +475,8 @@ This requires at least two keywords (unless only one wa= s given)." (define-derived-mode apropos-mode special-mode "Apropos" "Major mode for following hyperlinks in output of apropos commands. =20 -\\{apropos-mode-map}") +\\{apropos-mode-map}" + (elisp--setup-xref-backend)) =20 (defvar apropos-multi-type t "If non-nil, this apropos query concerns multiple types. diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index ce5c786..e4c59f0 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el @@ -708,6 +708,7 @@ Complete list of commands: \\{debugger-mode-map}" (setq truncate-lines t) (set-syntax-table emacs-lisp-mode-syntax-table) + (elisp--setup-xref-backend) (use-local-map debugger-mode-map)) (defcustom debugger-record-buffer "*Debugger-record*" diff --git a/lisp/help-mode.el b/lisp/help-mode.el index d6679e9..6fc63ea 100644 --- a/lisp/help-mode.el +++ b/lisp/help-mode.el @@ -288,7 +288,8 @@ Commands: (set (make-local-variable 'revert-buffer-function) 'help-mode-revert-buffer) (set (make-local-variable 'bookmark-make-record-function) - 'help-bookmark-make-record)) + 'help-bookmark-make-record) + (elisp--setup-xref-backend)) =20 ;;;###autoload (defun help-mode-setup () diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index ad35c48..98a3427 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -218,6 +218,8 @@ Comments in the form will be lost." :type 'hook :group 'lisp) =20 +(declare-function 'elisp--setup-xref-backend "elisp-mode") + ;;;###autoload (define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp" "Major mode for editing Lisp code to run in Emacs. @@ -227,8 +229,6 @@ Blank lines separate paragraphs. Semicolons start comm= ents. =20 \\{emacs-lisp-mode-map}" :group 'lisp - (defvar xref-find-function) - (defvar xref-identifier-completion-table-function) (lisp-mode-variables nil nil 'elisp) (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers) (setq-local electric-pair-text-pairs @@ -236,9 +236,7 @@ Blank lines separate paragraphs. Semicolons start comm= ents. (setq imenu-case-fold-search nil) (add-function :before-until (local 'eldoc-documentation-function) #'elisp-eldoc-documentation-function) - (setq-local xref-find-function #'elisp-xref-find) - (setq-local xref-identifier-completion-table-function - #'elisp--xref-identifier-completion-table) + (elisp--setup-xref-backend) (add-hook 'completion-at-point-functions #'elisp-completion-at-point nil 'local)) =20 @@ -581,6 +579,11 @@ It can be quoted, or be inside a quoted form." (declare-function xref-make-bogus-location "xref" (message)) (declare-function xref-make "xref" (description location)) =20 +(defun elisp--setup-xref-backend () + (setq-local xref-find-function #'elisp-xref-find) + (setq-local xref-identifier-completion-table-function + #'elisp--xref-identifier-completion-table)) + (defun elisp-xref-find (action id) (require 'find-func) (pcase action