Helm: Enhancement: use Ag -g for helm-ff-run-find-sh-command

Created on 17 Nov 2016  路  12Comments  路  Source: emacs-helm/helm

In my experience using ag -g (or pt -g, ack -g) is much faster way to search for a file then using the find utility. Since Helm already supports ag, ack, and pt, would it be possible to use their find-file functionality for the command helm-ff-run-find-sh-command? This seems like a good way to get a significant speed boost.

feature_request

All 12 comments

Troy Hinckley [email protected] writes:

In my experience using ag -g (or pt -g, ack -g) is much faster
way to search for a file then using the find utility. Since Helm
already supports ag, ack, and pt, would it be possible to use their
find-file functionality for the command helm-ff-run-find-sh-command?
This seems like a good way to get a significant speed boost.

That's looks a good idea, I will investigate as soon as possible.

Thanks.

Thierry

However this would be implemented as a different search command as it
would not have all the features find provides (atime, ctime, mtime, size etc...).

Thierry

That's a good point. Would be wise to make it a separate command. Though I would be willing to bet that most of the time for most people, they don't use the extra functionality. They are just trying to find a file they can't remember the path for.

Troy Hinckley [email protected] writes:

That's a good point. Would be wise to make it a separate
command. Though I would be willing to bet that most of the time for
most people, they don't use the extra functionality. They are just
trying to find a file they can't remember the path for.

Agree, but it is useful sometimes to know which files have been modified
in last n days hours, which size etc... particularly for sys admin.

Here a first shot with minimal options, have a try:

(defun helm-ag-find-file-init (directory)
  (start-process "ag-find-file" nil "ag" "-g" helm-pattern directory))

(defclass helm-ag-find-file-class (helm-source-async)
  ((filtered-candidate-transformer
    :initform
    (lambda (candidates _source)
      (cl-loop for c in candidates
               collect (helm--ansi-color-apply c))))
   (requires-pattern :initform 2)))

(defun helm-ag-find-file-1 (directory)
  (helm :sources (helm-make-source "AG find files" 'helm-ag-find-file-class
                   :candidates-process (lambda ()
                                         (helm-ag-find-file-init directory))
                   :action (helm-actions-from-type-file))
        :buffer "*helm ag find file*"))

(defun helm-ag-find-file ()
  (interactive)
  (helm-ag-find-file-1 (expand-file-name default-directory)))

Fill free to improve and submit it as a PR if you want.

Thierry

And here the bindings for HFF, not tested:

(defun helm-ff-ag-find-files (_candidate)
  (helm-ag-find-file-1 helm-ff-default-directory))

(defun helm-ff-run-ag-find-files ()
  (interactive)
  (with-helm-alive-p
    (helm-exit-and-execute-action 'helm-ff-ag-find-files)))

Thierry

Wow I am impressed you put that together so fast! Certainly works as a minimal solution. When I get some time I will have to see what I can do to improve on it. Though my Emacs-lisp is pretty poor right now.
Currently, it stops after it finds 100 items. Is that a limit that Helm is imposing on it? That is not the case in the terminal.

Troy Hinckley [email protected] writes:

Wow I am impressed you put that together so fast! Certainly works as a
minimal solution. When I get some time I will have to see what I can
do to improve on it. Though my Emacs-lisp is pretty poor right now.
currently its stops after it finds 100 items. Is that a limit that
Helm is imposing on it? That is not the case in the terminal.

It is helm-candidate-number-limit, it can be set locally to helm-buffer
in class:

(defclass helm-ag-find-file-class (helm-source-async)
  ((filtered-candidate-transformer
    :initform
    (lambda (candidates _source)
      (cl-loop for c in candidates
               collect (helm--ansi-color-apply c))))
   (requires-pattern :initform 2)
   (candidate-number-limit 9999))) ;; Here.

or in the helm-make-source call with :candidate-number-limit keyword.

And also in the helm call like any other helm-variable prefixed with
"helm-" (same as above with keyword).

Thierry

PR welcome based on the code above, perhaps the only thing missing is multi match, i.e implement
ag -g foo | ag bar.
Also add user variables to fully customize this e.g the backend to use (pt, ag or ack-grep), may be other stuff.

I am trying to add multimatch, a hotkey inside helm-find-files for helm-ff-run-ag-find-files, and support for other searchers (pt, ack, etc). But I can't seem to figure out what needs to be done. Is there a "helm development guide" or something that I can reference? I need some way to figure this out.

Troy Hinckley notifications@github.com writes:

I am trying to add multimatch,

You have to look in helm-grep.el how this is done for AG, see
helm-grep-ag-prepare-cmd-line.

a hotkey inside helm-find-files for helm-ff-run-ag-find-files,

This is easy, you just bind the command to helm-find-files-map.

and support for other searchers (pt, ack, etc).

We need a defcustom for the command and then modify it as needed for the
specificity of backend in the new function helm-<new>-prepare-cmd-line.

But I can't seem to figure out what needs to be done.

I have pushed devel branch, so just make your PR against this branch,
you can do several commits, don't worry if there is errors we will
polish it when finish.

Is there a "helm development guide" or something that I can reference?
I need some way to figure this out.

There is https://github.com/emacs-helm/helm/wiki/Developing

but it is not complete.

Thanks.

--
Thierry

For the helm-ff-run-find-sh-command we should just use find which provide more options as described above.
To use AG to find recursively files, I think helm-browse-project is a good place.
I modified it to allow customization of the function to use for non vc controlled directories.
So now you can use (setq helm-browse-project-default-find-files-fn #'helm-browse-project-ag-find-files)
then you can do M-x helm-browse-project from a buffer related to this directory or just C-x C-d from helm-find-files. The files will be cached, to refresh use C-u C-u C-x C-d.

This is a great solution. Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stakemori picture stakemori  路  7Comments

pcompassion picture pcompassion  路  3Comments

ChoppinBlockParty picture ChoppinBlockParty  路  6Comments

laurynas-biveinis picture laurynas-biveinis  路  5Comments

emelin picture emelin  路  3Comments