Helm: Enabling helm-follow-mode on a per-command basis.

Created on 27 Mar 2018  路  14Comments  路  Source: emacs-helm/helm

The problem

I adore helm and am using a package called helm-ag. I'd like to turn on helm-follow-mode for certain helm-ag commands, but not all of them. Near as I can tell from the source all helm-ag commands use the same _source_, so doing something like this doesn't quite work:

(helm-attrset 'follow 1 helm-source-do-ag)

Unfortunately, this will turn on helm-follow-mode for every helm-ag command. It's great for helm-do-ag-this-file, but not so great for helm-projectile-ag, which kills emacs on big projects. I've also tried another approach:

(advice-add 'helm-do-ag-this-file :after (lambda () (helm-follow-mode))

This doesn't seem to work though. I'd rather not use helm-follow-mode-persistent.

Curious what my options are, thanks so much in advance.

Most helpful comment

Kevin Depue notifications@github.com writes:

Expected behavior

I adore helm and am using a package called helm-ag. I'd like to turn
on helm-follow-mode for certain helm-ag commands, but not all of
them. Near as I can tell from the source all helm-ag commands use the
same source, so doing something like this doesn't quite work:

(helm-attrset 'follow 1 helm-source-do-ag)

Unfortunately if it is the same source that is reused you can't do
someting better, you have to ask the developers of these sources to
provide a main class for all and build different sources from this main
class.

BTW, I don't understand why people are using helm-ag package when they
have at hand (bundle with helm package) helm-do-grep-ag (asynchronous,
faster and works in real time).
Same for projectile, which is capable of handling many VCS but works
slowly on git and most people use it with git, you have better time
using M-x helm-browse-project after installing helm-ls-git when you are
using git as VCS.
helm-browse-project is supporting git, hg and svn (install the modules
you need from melpa).

I guess people are using helm-ag, projectile or helm-swoop because some
popular configuration software like spacemacs are proposing this by
default and they don't look at what helm comes with out of the box.

Otherwise what do you not like with helm-follow-mode-persistent ?

--
Thierry

All 14 comments

Kevin Depue notifications@github.com writes:

Expected behavior

I adore helm and am using a package called helm-ag. I'd like to turn
on helm-follow-mode for certain helm-ag commands, but not all of
them. Near as I can tell from the source all helm-ag commands use the
same source, so doing something like this doesn't quite work:

(helm-attrset 'follow 1 helm-source-do-ag)

Unfortunately if it is the same source that is reused you can't do
someting better, you have to ask the developers of these sources to
provide a main class for all and build different sources from this main
class.

BTW, I don't understand why people are using helm-ag package when they
have at hand (bundle with helm package) helm-do-grep-ag (asynchronous,
faster and works in real time).
Same for projectile, which is capable of handling many VCS but works
slowly on git and most people use it with git, you have better time
using M-x helm-browse-project after installing helm-ls-git when you are
using git as VCS.
helm-browse-project is supporting git, hg and svn (install the modules
you need from melpa).

I guess people are using helm-ag, projectile or helm-swoop because some
popular configuration software like spacemacs are proposing this by
default and they don't look at what helm comes with out of the box.

Otherwise what do you not like with helm-follow-mode-persistent ?

--
Thierry

Hey @thierryvolpiatto, thanks for the response!

Unfortunately if it is the same source that is reused you can't do
someting better, you have to ask the developers of these sources to
provide a main class for all and build different sources from this main
class.

This is good to know, it's what I thought to be the case - maybe I can get around it using these other packages you're referring to.

BTW, I don't understand why people are using helm-ag package when they
have at hand (bundle with helm package) helm-do-grep-ag (asynchronous,
faster and works in real time).
Same for projectile, which is capable of handling many VCS but works
slowly on git and most people use it with git, you have better time
using M-x helm-browse-project after installing helm-ls-git when you are
using git as VCS.
helm-browse-project is supporting git, hg and svn (install the modules
you need from melpa).

I'm ashamed to say that after years of using helm I wasn't even aware of helm-browse-project (I've been using helm-projectile-find-file).

On this topic, are there helm equivalents for the following packages?

  • helm-projectile: There are a ton of commands in this package that I'm not sure how to replicate in helm-proper. For example, helm-projectile-ag is one of them - it lets you quickly search within any file in a git repository, subject to .gitignore. You can also browse git projects and interact with them from anywhere - you don't have to start emacs in a git repository. Are there other commands besides helm-browse-project that I'm not aware of?
  • helm-ag: This has a lot of different commands for searching for things in different ways. For example, helm-do-ag-this-file, helm-do-ag-buffers, etc.
  • helm-swoop: Unfortunately not well maintained, but it's great to interact with. I've been trying to replicate its functionality via commands like helm-do-ag-this-file and helm-projectile-ag.

Otherwise what do you not like with helm-follow-mode-persistent ?

Similar to this issue, I don't care for the behaviour of helm-follow-mode-persistent, I'd rather turn on helm-follow-mode explicitly on a per-command basis. If I checkout my emacs settings on a different machine, I have to type C-c C-f again to update custom.el which I find annoying.

By the way, on the topic of turning on helm-follow-mode on a per-command basis, is this possible with advice / hooks? Another pressing question I had is whether it's possible to advise said functions so that when following, it doesn't actually permanently open the buffer as you navigate up and down in the candidates list, but instead only truly opens the buffer once you hit enter on a result. Currently if I enable helm-follow-mode in helm-projectile-ag for example and navigate up and down through 100 files, it opens 100 buffers which really pollutes the buffer list.

Thanks again for responding, I'm happy to help in any way I can!

Kevin Depue notifications@github.com writes:

On this topic, are there helm equivalents for the following packages?

  • helm-projectile: There are a ton of commands in this package that I'm not sure how to replicate in helm-proper. For example, helm-projectile-ag is one of them -
    it lets you quickly search within any file in a git repository, subject to .gitignore. You can also browse git projects and interact with them from anywhere - you
    don't have to start emacs in a git repository. Are there other
    commands besides helm-browse-project that I'm not aware of?

Once you enter helm-browse-project you have the buffers opened in the
project, the files of the project and the status buffer (new files,
files modified etc...)
You can grep files with AG or git grep or grep, you can helm-moccur
buffers in buffer source etc...
At each time you open a new project, it is recorded and you can reach
it back like all your other projects M-x helm-projects-history

  • helm-ag: This has a lot of different commands for searching for
    things in different ways. For example, helm-do-ag-this-file,
    helm-do-ag-buffers, etc.

Use helm-do-grep-ag from any buffers or from helm-find-files, hit M-g a.

  • helm-swoop: Unfortunately not well maintained, but it's great to
    interact with.

We have helm-moccur and helm-occur perfectly integrated in helm, faster
than helm-swoop and well maintained, it is also highly configurable so
that you can configure it to behave like helm-swoop.

Otherwise what do you not like with helm-follow-mode-persistent ?

Similar to this issue, I don't care for the behaviour of helm-follow-mode-persistent, I'd rather turn on helm-follow-mode explicitly on a per-command basis. If I
checkout my emacs settings on a different machine, I have to type C-c C-f again to update custom.el which I find annoying.

This however allows great flexibility...

By the way, on the topic of turning on helm-follow-mode on a
per-command basis, is this possible with advice / hooks?

No.

Another pressing question I had is whether it's possible to advise
said functions so that when following, it doesn't actually permanently
open the buffer as you navigate up and down in the candidates list,
but instead only truly opens the buffer once you hit enter on a
result.

No.

Currently if I enable helm-follow-mode in helm-projectile-ag for
example and navigate up and down through 100 files, it opens 100
buffers which really pollutes the buffer list.

What you can do when helm-follow-mode is enabled is using C-down/up on
the files you don't want to see the contents and down/up or C-n/p to
follow. The behavior is inversed when follow-mode is disabled.

--
Thierry

Hey @thierryvolpiatto,

I have a few questions / comments about your last response:

Once you enter helm-browse-project you have the buffers opened in the
project, the files of the project and the status buffer (new files,
files modified etc...)
You can grep files with AG or git grep or grep, you can helm-moccur
buffers in buffer source etc...

Looking at the source, helm-do-grep-ag appears to start searching from the current directory. If the current buffer represents a file it starts searching from that file's directory, picking up other files with it when searching. Although the command is fast, it doesn't really do what I want unless I'm missing something about how to interact with it.

There doesn't appear to be a helm-moccur command in the helm source. I was able to do a multi occur by typing C-x b, marking several buffers, hitting TAB, and then executing the multi occur action. This isn't an ideal workflow for me unfortunately.

At each time you open a new project, it is recorded and you can reach
it back like all your other projects M-x helm-projects-history

This does not appear to persist across emacs sessions.

This however allows great flexibility...

Does helm-follow-mode-persistent store the helm-follow-mode state on a per-command basis? If so, why is it not possible to achieve this behavior manually (via advice-add or some other mechanism)?

What I'm Trying To Do

What I'm trying to achieve at a high level through various packages are the following (made up) commands:

  • find-in-current-buffer
  • find-in-marked-buffers
  • find-in-all-buffers
  • find-in-git-project
  • find-in-directory
  • ...

With every one of these commands, I'd like the interface to be like helm-swoop, that is, popping open a buffer next to the current one where I can C-n / C-p up and down the candidates list, _following_ them as I go via helm-follow-mode. For commands like find-in-git-project, I'd like to be able to close a buffer if I navigate away from it in the candidates list to avoid polluting the buffer space.

I'm trying to have a universal set of commands for finding things in files / buffers / repositories / et al.

Hope this helps, -It3ration

Kevin Depue notifications@github.com writes:

Looking at the source, helm-do-grep-ag appears to start searching from
the current directory. If the current buffer represents a file it
starts searching from that file's directory, picking up other files
with it when searching. Although the command is fast, it doesn't
really do what I want unless I'm missing something about how to
interact with it.

You can navigate with helm-find-files where you want and hit M-g a to
grep another directory, helm-do-grep-ag support as well vaious backend
like ripgrep, what do you need else.

There doesn't appear to be a helm-moccur command in the helm source.

No there isn't, you start from helm-buffers-list or helm-mini, mark some
buffers and hit C-s.

I was able to do a multi occur by typing C-x b, marking several
buffers, hitting TAB, and then executing the multi occur action. This
isn't an ideal workflow for me unfortunately.

What's the problem with this, swoop does the same but from a crappy
buffer list, it is not integrated in helm-buffers-list.
To use it in the current-buffer, use M-x helm-occur.

At each time you open a new project, it is recorded and you can reach
it back like all your other projects M-x helm-projects-history

This does not appear to persist across emacs sessions.

This is up to you to make emacs variables persistent with desktop or
psession packages (I use psession).

What I'm Trying To Do

What I'm trying to achieve at a high level through various packages are the following (made up) commands:

  • find-in-current-buffer
    helm-occur
  • find-in-marked-buffers
    helm-moccur
  • find-in-all-buffers
    mark all buffers (a bad idea)
  • find-in-git-project
    helm-browse-project
  • find-in-directory
    helm-find-files, helm-find, helm-locate with prefix-arg etc...

You have to use from helm-find-files C-h m to see documentation of all
this (seems you didn't).

With every one of these commands, I'd like the interface to be like
helm-swoop, that is, popping open a buffer next to the current one
where I can C-n / C-p up and down the candidates list, following them
as I go via helm-follow-mode.

Of course you can do this with helm-moccur!!!

For commands like find-in-git-project, I'd like to be able to close a
buffer if I navigate away from it in the candidates list to avoid
polluting the buffer space.

And of course you can do this as well once you have installed
helm-ls-git.

>

I'm trying to have a universal set of commands for finding things in files / buffers / repositories / et al.

It is there under your hand, documented as well.

--
Thierry

Hey @thierryvolpiatto,

I know you've closed this issue but I'm still stuck on something. helm-do-grep-ag is nice and fast, but is there some way to quickly run ag on all files within the current git repository, subject to .gitignore? I'm trying to replicate what helm-projectile-ag does and I still don't see a way with one command.

Thank!

Kevin Depue notifications@github.com writes:

Hey @thierryvolpiatto,

I know you've closed this issue but I'm still stuck on something. helm-do-grep-ag is nice and fast, but is there some way to quickly run ag on all files within the
current git repository, subject to .gitignore?

I don't understand, do you want to grep ignored files?

--
Thierry

I'd like to search within all files in a git repository except for files that are included in .gitignore. This is what helm-projectile-ag does, I'm trying to discern whether this is possible in helm itself per our previous discussion.

Thanks, -it3ration

Kevin Depue notifications@github.com writes:

I'd like to search within all files in a git repository except for
files that are included in .gitignore.

This is what the backends do.

See https://github.com/ggreer/the_silver_searcher
and https://github.com/BurntSushi/ripgrep

And of course git-grep is ignoring what's in .gitignore.

--
Thierry

Would it be possible to add a command that calls helm-grep-do-git-grep with default-directory set to the root of the git project? It looks like helm-grep-do-git-grep always searches from default-directory but what I'm really after is a command that searches the entire git repo, always.

A second question about helm-grep-do-git-grep: are you only able to provide a single regular expression? I don't seem to be able to specify multiple out of order regular expressions like with some other helm commands.

Cheers, -it3ration

Kevin Depue notifications@github.com writes:

Would it be possible to add a command that calls helm-grep-do-git-grep
with default-directory set to the root of the git project? It looks
like helm-grep-do-git-grep always searches from default-directory but
what I'm really after is a command that searches the entire git repo,
always.

From helm-find-files (explained in action list)
C-u M-g g
From helm-ls-git (files source)
M-g g (C-u allow specifying extensions to only match)

A second question about helm-grep-do-git-grep: are you only able to
provide a single regular expression?

No, separate with space like anywhere else in helm.
It behave like "grep foo | grep bar | grep baz".

--
Thierry

I'm not sure you're understanding me - I'm trying to replicate helm-projectile-ag. I'll just write a command that wraps helm-grep-git-1 directly, I just need to figure out a way to get the directory of the current git repository.

Kevin Depue notifications@github.com writes:

I'm not sure you're understanding me - I'm trying to replicate
helm-projectile-ag. I'll just write a command that wraps
helm-grep-git-1 directly, I just need to figure out a way to get the
directory of the current git repository.

helm-grep-git-1 already know where is the root of project.

(helm-grep-git-1 directory 'all)

But well, C-u M-g g will save your time writing a new command.
And from M-x helm-browse-project M-g g with no prefix arg does the same.

If you want to use AG from the root directory of project without
navigating to root, you can indeed write a new command using something
like this:

(helm-grep-ag (vc-find-root directory ".git") prefarg)

HTH

--
Thierry

Thanks, this is what I ended up writing:

(defun helm-grep-do-git-grep-all ()
  "Like helm-grep-do-git-grep but searches the entire repository."
  (interactive)
  (helm-grep-git-1 default-directory 'all))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bugcook picture bugcook  路  5Comments

nordlow picture nordlow  路  3Comments

laurynas-biveinis picture laurynas-biveinis  路  5Comments

ChoppinBlockParty picture ChoppinBlockParty  路  6Comments

phtrivier picture phtrivier  路  3Comments