From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Generalizing find-definition Date: Thu, 11 Dec 2014 10:07:42 -0500 Message-ID: References: <20141102151524.0d9c665c@forcix> <877fymghgb.fsf@bredband.net> <85ppc0qf9a.fsf@stephe-leake.org> <85zjb3o09d.fsf@stephe-leake.org> <85tx1amnyg.fsf@stephe-leake.org> <85egsem1u2.fsf@stephe-leake.org> <867fy0or7p.fsf@yandex.ru> <86ppbqn841.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1418310583 13499 80.91.229.3 (11 Dec 2014 15:09:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Dec 2014 15:09:43 +0000 (UTC) Cc: Helmut Eller , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 11 16:09:31 2014 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 1Xz5Mx-0007nH-5Y for ged-emacs-devel@m.gmane.org; Thu, 11 Dec 2014 16:09:31 +0100 Original-Received: from localhost ([::1]:51976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz5Mw-0003hH-Ld for ged-emacs-devel@m.gmane.org; Thu, 11 Dec 2014 10:09:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz5LM-0001p8-KA for emacs-devel@gnu.org; Thu, 11 Dec 2014 10:08:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz5LE-00039h-Bf for emacs-devel@gnu.org; Thu, 11 Dec 2014 10:07:52 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:33497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz5LE-00039P-7t for emacs-devel@gnu.org; Thu, 11 Dec 2014 10:07:44 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwPAOwQflRFxIoH/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBViMFCwsOJhIUGA0kiEoJ1lkBAQEBBgEBAQEekG8HhEgFiwGSMYZRiyyBeIQZIYJ3AQEB X-IPAS-Result: AjwPAOwQflRFxIoH/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBViMFCwsOJhIUGA0kiEoJ1lkBAQEBBgEBAQEekG8HhEgFiwGSMYZRiyyBeIQZIYJ3AQEB X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="100193712" Original-Received: from 69-196-138-7.dsl.teksavvy.com (HELO pastel.home) ([69.196.138.7]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Dec 2014 10:07:43 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id E48AA7D7; Thu, 11 Dec 2014 10:07:42 -0500 (EST) In-Reply-To: <86ppbqn841.fsf@yandex.ru> (Dmitry Gutov's message of "Thu, 11 Dec 2014 06:06:06 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:179770 Archived-At: > To be honest, now I can better see the appeal of using the classes here. > For instance, in the modified API a backend has to return `:none' in its > identifier-at-point implementation if not found, because otherwise the > default implementation will be called (and it's hard to implement the > overriding otherwise). You don't need :none. You can do: (add-function :around (local xref-backend) #'elisp-xref-backend) and then in elisp-xref-backend you do: (defun elisp-xref-backend (orig action ...) (pcase action ... (_ (apply orig args)))) > +;; For now, make the etags backend the default. > +(defvar xref-backend #'etags-xref-backend This should be called `xref-backend-function', to follow usual practice. > + "The current xref-backend. > +This function can be called with different sets of arguments, as > +described below. > + > +Required: > + > + (definitions IDENTIFIER): Find definitions of IDENTIFIER. The > +result must be a list of `xref--xref' objects. If no definition > +can be found, return nil. Rename xref--xref to xref-xref, since it's clearly part of the API. > + (references IDENTIFIER): Find references of IDENTIFIER. The > +result must be a list of `xref--xref' objects. If no reference > +can be found, return nil. > + > +Optional: > + > + (read-identifier INIT PROMPT): Read an identifier from the > +minibuffer. PROMPT is a string used for prompting. INIT is > +either an identifier to use as the initial value or nil. > + > + (identifier-at-point): Search and return the identfier near > +point. If no identifier can be found, return `:none'. > + > + (identifier-to-string IDENTIFIER): Return a string representing > +IDENTIFIER.") A few comments: - As discussed earlier, `read-identifier' is probably a bad idea. Replace it with a `completion-table' method, so the completing-read is not in the backend but in xref.el. - identifier-at-point should document more clearly that the return value may be something else than a string. AFAIK the only interesting non-string non-nil case is to return a special value (e.g. a marker or just `t' to stand to (point)) which stands for "let the find-definitions code figure out the identifier at that place". - If we restrict identifier to "a string or nil or t", then we can get rid of identifier-to-string. - The first two methods use sufficiently similar (actual, identical) calling conventions, so it's perfectly fine to make them share a single backend function, but adding the other methods makes it scream "I want to use OO", just like completion-tables do. IOW, I think if we don't want to use EIEIO for the `xref-backend' objects, then we need to split `xref-backend' into several variables: - xref-find-function (can be used both for the `definitions' and for the `references'). - xref-identifier-at-point-function. - xref-identifier-completion-table. -- Stefan