emacs-helm / helm

Emacs incremental completion and selection narrowing framework
https://emacs-helm.github.io/helm/
GNU General Public License v3.0
3.35k stars 389 forks source link

Cannot pre-set 'follow attribute #2639

Open alexvorobiev opened 5 months ago

alexvorobiev commented 5 months ago

What happened?

I want to always see the content of the buffers whenever I have the buffers source active. I tried adding this line to my configuration

(helm-set-attr 'follow 1 helm-source-buffers-list)

but helm-set-attr calls helm-get-current-source which fails with No buffer named *helm* error.

How to reproduce?

Run

(helm-set-attr 'follow 1 helm-source-buffers-list)

prior to calling any helm commands.

Helm Version

Master branch

Emacs Version

Emacs-30+

OS

GNU/Linux

Relevant backtrace (if possible)

Debugger entered--Lisp error: (error "No buffer named *helm*")
  helm-get-current-source()
  helm-set-attr(follow 1 nil)
  eval((helm-set-attr 'follow 1 helm-source-buffers-list) nil)
  elisp--eval-last-sexp(nil)
  #f(compiled-function () #<bytecode 0x299f04123357a>)()
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

Minimal configuration

thierryvolpiatto commented 5 months ago

Alex Vorobiev @.***> writes:

What happened?

I want to always see the content of the buffers whenever I have the buffers source active. I tried adding this line to my configuration

(helm-set-attr 'follow 1 helm-source-buffers-list)

but helm-set-attr calls helm-get-current-source which fails with No buffer named helm error.

This is not working because the source is not already built, you have to use cl-defmethod helm-setup-user-source to setup your source. See https://github.com/thierryvolpiatto/emacs-config/blob/main/init-helm.el#L355 and https://github.com/emacs-helm/helm/wiki/FAQ#why-is-a-customizable-helm-source-nil.

But for follow you don't need this, instead set helm-follow-mode-persistent to t and call once C-c C-f in helm-buffers-list or helm-mini and you are done, next emacs session you will have follow enabled in this source, if you call C-c C-f again follow will be disabled for next emacs session as well.

-- Thierry

alexvorobiev commented 5 months ago

Thanks! Yes, I am aware of helm-follow-mode-persistent and I do use it but I have many computers - both physical and often temporary virtual - and would prefer a configuration where everything is pre-configured to my liking from the beginning. I also share my settings with others (often beginners) and telling them to memorize yet another emacs key which they need to use only once seems cruel. After some experimentation I came up with this code (an excerpt form my much larger helm configuration) which seems to be doing what I want:

(setq helm-follow-mode-persistent t)

(unless (listp 'helm-source-names-using-follow)
    (setq helm-source-names-using-follow (list)))

(add-to-list 'helm-source-names-using-follow "Buffers")

Does it look reasonable? It feels like the the last line is good ergonomics and it looks more straightforward than the customizable source for this particular case. If helm-source-names-using-follow were initialized with an empty list by default, the approach (and the strings corresponding to the source names - I couldn't find them in the documentation) would maybe also be worth mentioning somewhere in the help.

thierryvolpiatto commented 5 months ago

Alex Vorobiev @.***> writes:

  1. ( ) text/plain (*) text/html

Thanks! Yes, I am aware of helm-follow-mode-persistent and I do use it but I have many computers - both physical and often temporary virtual

  • and would prefer a configuration where everything is pre-configured to my liking from the beginning. I also share my settings with others (often beginners) and telling them to memorize yet another emacs key which they need to use only once seems cruel.

Tell them to remember C-h m (it is mentionned in mode-line), they will find there a lot of infos.

After some experimentation I came up with this code (an excerpt form my much larger helm configuration) which seems to be doing what I want:

(setq helm-follow-mode-persistent t)

(unless (listp 'helm-source-names-using-follow) (setq helm-source-names-using-follow (list)))

That's just mean helm is not loaded at this point, use (require 'helm) instead.

(add-to-list 'helm-source-names-using-follow "Buffers")

Does it look reasonable?

I generally prefer users use helm-follow-mode-persistent mechanism though, but yes this is ok too.

It feels like the the last line is good ergonomics and if helm-source-names-using-follow were initialized with an empty list by default, the approach (and the strings corresponding to the source names - I couldn't find them in the documentation) could be mentioned somewhere in the help.

To have infos on a source use C-h d while running this source.

-- Thierry