[Top][All Lists]

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

Re: xref-find-matches and stuff

From: Vitalie Spinu
Subject: Re: xref-find-matches and stuff
Date: Tue, 05 May 2015 16:35:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

I got a bit of time to look through the abstractions. Here is my
concrete suggestion.

As I already said in other place, current old-school polymorphism with
`xref-find-function`, xref-identifier-at-point-function' and
`xref-identifier-completion-table-function` is rather clumsy if you want
to build an UI for backend manipulation. 

You are already using class machinery, so how about to shift the focus
on backends and use generics instead. More concretely:

   (cl-defmethod xref-definitions ((b (eql elisp)) id)
     (message "elisp definitions: %s" id))
   (cl-defmethod xref-references ((b (eql etags)) id)
     (message "etags references: %s" id))
   (cl-defmethod xref-apropos ((b (eql elisp)) pattern)
     (message "elisp apropos: %s" pattern))

   (cl-defmethod xref-matches ((b (eql elisp)) pattern)
     (message "elisp matches: %s" pattern))

Then you can simply.
   (xref-definitions 'etags "blabla")
   (xref-matches 'elisp "blabla")

Once that's done, you can introduce

  (setq xref-backends '(elisp etags ...))

for current backends. Then adding functionality to add/remove backends
from current list and rotate through different preset configurations of
backends is a piece of cake.

Alternatively you can still go with more monolithic

  (cl-defmethod xref-find ((b (eql elisp) action id)))

but this has an obvious drawback that whenever you add a new
`xref-find-SOMETHING` you need to go back and modify all `xref-find`
methods. Not quite an option for a good design IMO.

As to removing duplicates, I don't see it as a big deal. You can define
`xref-loc-name` methods for location objects to extract a
wanna-be-unique name to be specifically used in comparison between
backends. Even if you cannot get rid of all duplicates it's the task of
the *xref* UI to provide sorting and duplication removal on specific

If you are willing to wait till 20th of May I can propose patches for
this abstraction change and other UI ideas that we have discussed


reply via email to

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