ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

feature request: find occurrences #156

Closed nbros closed 4 years ago

nbros commented 10 years ago

It would be great if merlin could search for an identifier and return a list of locations for all occurrences of this identifier either in the current buffer or the whole project (depending on an option).

This would allow implementing editor services such as mark occurrences (example for Java in this screenshot): mark occurrences

and search: search

trefis commented 10 years ago

Related to #125 .

That should be doable with a bit of work; but don't expect anything soon (christmas and all that).

roshanjames commented 10 years ago

In addition to find occurrences it would be great if merlin can someday rename identifiers.

trefis commented 10 years ago

Well, that will be your job. :) Once you have the positions of every occurrence of an identifier you only need to have your editor change them.

EDIT: My bad, I hadn't paid close attention and I though that nbros was commenting. Doesn't change te gist of the remark though :)

roshanjames commented 10 years ago

If there is some way to script it, once the locations have been found, sure :)

eras commented 10 years ago

If this functionality of finding the occurrences is implemented, iedit-mode (http://www.emacswiki.org/emacs/Iedit) could perhaps enhanced to support that. It's what i currently use for finding occurrences and renaming identifiers (and a lot of other things).

yminsky commented 10 years ago

I concur that this would be quite useful. Renaming would be a nice feature to add in, but I'm quite happy to start with just finding them.

trefis commented 10 years ago

Ok so, I finished binding the "occurence" command in both vim and emacs.

In vim one can use it by calling ":Occurences" over an identifier and it will then populate the location list (:h location-list). N.B. there is one location-list per buffer, so there might be conflict with other plugins using it, Syntastic for example.

In emacs one needs to call the "merlin-occurences" function over an identifier. This function is kind of a "poor man's occur" (see Occur Mode ), i.e. we populate a buffer (*merlin-occurences* by default) with a clickable list of occurences, clicking on entry of this buffer will move you to the related occurence. One can also configure the way this list is displayed (in the window where the command was called, in another window, nowhere).

N.B. I spent a good amount of time looking for an alternative to occur mode (there are a few of those) which would allow a custom function to give it the list of occurences, and not just by matching a regexp. There however appear to be none.

PS: I'm not closing the issue since the emacs mode hasn't been done on the refactor branch.

roshanjames commented 10 years ago

That's fantastic.

On Mar 28, 2014, at 12:40 PM, Thomas Refis notifications@github.com wrote:

Ok so, I finished binding the "occurence" command in both vim and emacs.

In vim one can use it by calling ":Occurences" over an identifier and it will then populate the location list (:h location-list). N.B. there is one location-list per buffer, so there might be conflict with other plugins using it, Syntastic for example.

In emacs one needs to call the "merlin-occurences" function over an identifier. This function is kind of a "poor man's occur" (see Occur Mode ), i.e. we populate a buffer (merlin-occurences by default) with a clickable list of occurences, clicking on entry of this buffer will move you to the related occurence. One can also configure the way this list is displayed (in the window where the command was called, in another window, nowhere).

N.B. I spent a good amount of time looking for an alternative to occur mode (there are a few of those) which would allow a custom function to give it the list of occurences, and not just by matching a regexp. There however appear to be none.

PS: I'm not closing the issue since the emacs mode hasn't been done on the refactor branch.

— Reply to this email directly or view it on GitHub.

trefis commented 10 years ago

Hi! Just a quick update, def introduced a PoC renamming function based on occurences in both vim and emacs since 2b34a6d2aa (it is only available on the merlin2 branch though).

roshanjames commented 10 years ago

Interesting. Is it applicable only for the current buffer or, can it walk through multiple files?

Roshan

On Jul 1, 2014, at 7:13 AM, Thomas Refis notifications@github.com wrote:

Hi! Just a quick update, def introduced a PoC renamming function based on occurences in both vim and emacs since 2b34a6d (it is only available on the merlin2 branch though).

— Reply to this email directly or view it on GitHub.

trefis commented 10 years ago

Only for the current buffer.

sheijk commented 10 years ago

trefis: You could use grep-mode and just run it with a custom command. That would also allow it to be used for some refactorings using wgrep.

let-def commented 10 years ago

@sheijk: we use occur-mode (thanks to @gsg) to display occurences, and my PoC uses iedit to edit them. What are the benefits of grep-mode?

sheijk commented 10 years ago

It might be a matter of preference. grep-mode allows navigation with the same keys as compilation-mode which I prefer for moving through all occurrences.

gsg commented 10 years ago

If you mean next-error and previous-error, occur-mode works with those commands. It also allows editing as of emacs 24.1.

bluddy commented 9 years ago

Just my 2 cents here: I was really excited for this feature, but it's really mostly useful as a general project search. This is the thing that's hard to get in vim/emacs. For the current file, a quick search usually does the trick. For all files in a project, you need to use something like silver-searcher, which is a little slow + it gets many false positives. I'm looking for something akin to cscope, which unfortunately is horribly out of date and doesn't work for ocaml.

roshanjames commented 9 years ago

On Oct 13, 2014, at 6:23 PM, Yotam Barnoy notifications@github.com wrote:

Just my 2 cents here: I was really excited for this feature, but it's really mostly useful as a general project search.

+1

This is the thing that's hard to get in vim/emacs. For the current file, a quick search usually does the trick. For all files in a project, you need to use something like silver-searcher, which is a little slow + it gets many false positives. I'm looking for something akin to cscope, which unfortunately is horribly out of date and doesn't work for ocaml.

— Reply to this email directly or view it on GitHub.

nilsbecker commented 8 years ago

the :MerlinRename functionality is great but does not yet seem to work for module aliases. that would be a nice addition. e.g.

module A = Array

and then call MerlinRename on A to change it globally to Arr or whatever.