1

https://github.com/emacs-helm/helm-ls-git

Found no tutorial for it on google.
That means it doesn't exist in our universe?

I'm looking for a way to find files and grep files within emacs.
Hopefully as easy as in sublime with project directory opened.
(Your search is automatically limited to the directory you specified in sublime)

Community
  • 1
  • 1
eugene
  • 39,839
  • 68
  • 255
  • 489
  • 2
    It's a 350 line elisp extension for the [helm project](https://github.com/emacs-helm) which itself is pretty well documented. If you are using emacs *and* git, then certainly that snippet shouldn't befuddle you. Help save the world, document it and add it to the repo. Or write the author and demand a refund. – msw Jun 28 '13 at 02:15
  • I looked at the elisp file, but alas, I'm not good at elisp and had no idea how to use it.. what are 2-3 commands I can use for what purpose with helm-ls-git? – eugene Jun 28 '13 at 02:44
  • I wasn't being coy, I have no idea; I haven't used emacs/elisp for decades and don't use git. – msw Jun 28 '13 at 03:17
  • 1
    I've rushed to reply at first, but now I'm not sure. When you say "grep files within emacs", do you mean `git grep`, or just `grep`? The file you linked to is a back-end (basically, provides nice colored output) for `git grep` and `git ls-files`. I think `vc-git` has already something similar to it. –  Jun 28 '13 at 06:33
  • I heard `git grep` for the first time. I basically want to do grep on files under a directory. (or better, git project) – eugene Jun 28 '13 at 09:00

3 Answers3

2

The functionality you are after is something dired has been doing successfully for years. The file you have linked in your post is a minor enhancement for a convenience feature added on top of the built-in functionality, it doesn't really deal with searching for files outside the context of Git version control system.

Here are some examples of how you could do it with dired:

M-xfind-name-dired, answer the prompts to select the directory where you want to search and possibly refine by providing a regular expression to match file names. You then will be presented with the buffer listing all files you have selected so far. You can further refine from here by % m and providing it with a regexp to filter the file names on, or just hit t selecting all files in the buffer.

Then hit A and write the regexp to search for inside the selected files. The effect of this command will be to open the file, where the match is found. After you close the file, or return to the original buffer, you can press M-, to move to the next match.


If this sounds too elaborate, then you could just do M-xfind-dired to invoke find in the directory you choose with the arguments you can normally provide to find


To just grep and have the matches shown in a dedicated buffer you could do M-xfind-grep - this will invoke find with the output from it piped to grep. You will then need to modify the command used to invoke this to your taste.

M-xfind-grep-dired will do something similar, however it will display the files, where the match was found in a dired buffer, rather then the lines, where the match occurred.


Finally, there may be a bunch more ways to do this, depending on your particular task and what, in the end, you are trying to accomplish. Perhaps, some times, invoking a shell command to place the results directly in the buffer would be the best way to do it. Other times you may want to write your own eLisp function to do something more elaborate with the results. Sky is he limit :)

  • thanks for the detailed intro to `dired`. I've been using it for sometime now though. `I have to go to the directory to search to use any dired command and I find it tedious ` .. Can you initialize a directory so that any dired command after that will use the directory as the root (of a project in other IDE)? – eugene Jun 28 '13 at 14:27
  • and a capability to restrict search to files with certain extensions. I know I can do dired search and mark individual files. However when there are many files that match, this is also tedious. – eugene Jun 28 '13 at 14:31
  • @eugene You can bookmark a directory, for example. `M-x r m` to mark, `M-x r b` to open bookmarked directory. If that's some very particular folder you are often working with, you can place special file in it `.dir-locals.el` and there you can practically put any eLisp code to customize that particular directory. More here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html –  Jun 28 '13 at 21:24
  • @eugene also, look here: http://www.gnu.org/software/emacs/manual/html_node/dired-x/Omitting-Variables.html if I understand you correctly, you need to set `dired-omit-extensions` in the local variables to omit the files you don't want to search in. –  Jun 28 '13 at 21:46
0

This might not answer your entire question but I use the following bit of elisp as a shortcut for greping all files with a set list of extensions under a specific folder:

(defun pgrep (regexp)
  "rgrep files inside a project folder"
  (interactive
   (list (grep-read-regexp)))
  (grep-compute-defaults)
  (rgrep regexp "*rb *erb *js *css *scss" "~/path/to/folder/"))

Then I just run M-x pgrep foo

For anything more complicated I just run rgrep directly - it lets you specify the root folder, search string, and extension.

spike
  • 9,794
  • 9
  • 54
  • 85
0

I saw this question recently and updated the README on the repo page to reflect installation and usage:

https://github.com/emacs-helm/helm-ls-git

Hope it helps!

jhrr
  • 1,624
  • 14
  • 22