always saving choices from file sources to file-name-history

15 views
Skip to first unread message

Ted Zlatanov

unread,
Apr 29, 2015, 6:06:53 PM4/29/15
to emacs...@googlegroups.com
My current `helm-mini-sources' are (helm-source-buffers-list
helm-source-recentf helm-source-buffer-not-found
helm-source-minibuffer-history helm-source-occur helm-source-session
helm-source-files-in-current-dir helm-source-files-in-all-dired
helm-source-etags-select helm-source-locate) and I'd like all of them to
save to `file-name-history' (and any other sources that return file
names). Basically I can't see a reason I wouldn't want to save files to
`file-name-history'.

So I dug into it and I had two questions:

1) the `helm-files-save-history-extra-sources' customization needs work.
It's a "value menu" but presents as a string, and it's not clear how to
include something like "Recentf". I couldn't find any docs for it and
didn't dig further in the source, but if you need a patch I can try to
assemble it.

2) I think there should be a way to automatically save all file choices
to the Emacs `file-name-history'. Currently I accomplished this by
overriding the default setup. I only use `helm-mini' so this is
probably a dumb solution in general:

(add-hook 'helm-exit-minibuffer-hook (lambda () (helm-files-save-file-name-history t)))

...but that's a hack. The selection logic is:

(when (or force (helm-file-completion-source-p)
(member src-name helm-files-save-history-extra-sources))
....

so, checking `helm-file-completion-source-p', I find that it checks

(defvar helm--file-completion-sources
'("Find Files" "Read File Name" "Read File Name History")

which doesn't include the "Recentf", "Locate", and "Files in Current
Directory" etc. sources I typically use (see above for the full list).
Should it? That seems to be the key to my problem.

If not, then I have to customize `helm-files-save-history-extra-sources'
which as I mentioned is not easy to customize and feels like an
unpleasant customization for every Helm user.

Thanks
Ted

Thierry Volpiatto

unread,
Apr 30, 2015, 12:58:33 AM4/30/15
to emacs...@googlegroups.com

Ted Zlatanov <t...@lifelogs.com> writes:

> My current `helm-mini-sources' are (helm-source-buffers-list
> helm-source-recentf helm-source-buffer-not-found
> helm-source-minibuffer-history helm-source-occur helm-source-session
> helm-source-files-in-current-dir helm-source-files-in-all-dired
> helm-source-etags-select helm-source-locate) and I'd like all of them to
> save to `file-name-history' (and any other sources that return file
> names). Basically I can't see a reason I wouldn't want to save files to
> `file-name-history'.
>
> So I dug into it and I had two questions:
>
> 1) the `helm-files-save-history-extra-sources' customization needs work.
> It's a "value menu" but presents as a string,

No, it is a repeat => string (a list of strings IOW).

> and it's not clear how to include something like "Recentf".

You just go to customize menu and add Recentf.
or
(add-to-list 'helm-files-save-history-extra-sources "Recentf")

>
> 2) I think there should be a way to automatically save all file choices
> to the Emacs `file-name-history'. Currently I accomplished this by
> overriding the default setup. I only use `helm-mini' so this is
> probably a dumb solution in general:
>
> (add-hook 'helm-exit-minibuffer-hook (lambda () (helm-files-save-file-name-history t)))

This add twice the files to history.

> ...but that's a hack. The selection logic is:
>
> (when (or force (helm-file-completion-source-p)
> (member src-name helm-files-save-history-extra-sources))
> ....

It is what `helm-files-save-file-name-history' is doing.

> so, checking `helm-file-completion-source-p', I find that it checks
>
> (defvar helm--file-completion-sources
> '("Find Files" "Read File Name" "Read File Name History")
>
> which doesn't include the "Recentf", "Locate", and "Files in Current
> Directory" etc.

`helm-files-save-history-extra-sources' contain by default locate and find.

> sources I typically use (see above for the full list). Should it?
> That seems to be the key to my problem.
>
> If not, then I have to customize `helm-files-save-history-extra-sources'
> which as I mentioned is not easy to customize and feels like an
> unpleasant customization for every Helm user.

Why, as stated above, it's easy, I don't understand what is difficult to
customize this var.

BTW, you really should switch to helm-find-files for all your files
task, it will allow you to switch from it to many differents action
related to files (browse-project, locate, find, grep, file history,
etc...), you can also bookmark these sessions.

For file-history, try `C-x C-f C-c h' (assuming C-x C-f is
helm-find-files).

If you really want to keep helm-mini or helm-for-files, try instead
helm-multi-files which allow to not kick-in locate when searching files:
start typing a filename, if you have no result hit `C-c p' that switch
to locate, hit C-c p again when you want to be back to other sources.

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Ted Zlatanov

unread,
Apr 30, 2015, 10:36:47 AM4/30/15
to emacs...@googlegroups.com
On Thu, 30 Apr 2015 06:58:25 +0200 Thierry Volpiatto <thierry....@gmail.com> wrote:

TV> Ted Zlatanov <t...@lifelogs.com> writes:

>> My current `helm-mini-sources' are (helm-source-buffers-list
>> helm-source-recentf helm-source-buffer-not-found
>> helm-source-minibuffer-history helm-source-occur helm-source-session
>> helm-source-files-in-current-dir helm-source-files-in-all-dired
>> helm-source-etags-select helm-source-locate) and I'd like all of them to
>> save to `file-name-history' (and any other sources that return file
>> names). Basically I can't see a reason I wouldn't want to save files to
>> `file-name-history'.
>>
>> So I dug into it and I had two questions:
>>
>> 1) the `helm-files-save-history-extra-sources' customization needs work.
>> It's a "value menu" but presents as a string,

TV> No, it is a repeat => string (a list of strings IOW).

Right, that's what I meant :) But the customization interface is
*extremely* unhelpful to users. It should be a choice from the known
source names, which the software knows, right? Giving them a repeat
string is not much better than making it a defvar IMO.

I would also like a way to save for all sources, like I said. So ".*"
could work. Or just accept t as a valid setting for this, meaning all.

If you'd like a patch, I can try to improve this?

>> and it's not clear how to include something like "Recentf".

TV> You just go to customize menu and add Recentf.
TV> or
TV> (add-to-list 'helm-files-save-history-extra-sources "Recentf")

But how do I know to use "Recentf"? It's not obvious when I just want to
customize things. Think of this as a user who wants to customize the
variable after installing Helm from a package. They don't want this
level of engagement with the source code yet :)

>> 2) I think there should be a way to automatically save all file choices
>> to the Emacs `file-name-history'. Currently I accomplished this by
>> overriding the default setup. I only use `helm-mini' so this is
>> probably a dumb solution in general:
>>
>> (add-hook 'helm-exit-minibuffer-hook (lambda () (helm-files-save-file-name-history t)))

TV> This add twice the files to history.

Right, but it's the only way I found to save *all sources* which I said
was my goal :)

>> so, checking `helm-file-completion-source-p', I find that it checks
>>
>> (defvar helm--file-completion-sources
>> '("Find Files" "Read File Name" "Read File Name History")
>>
>> which doesn't include the "Recentf", "Locate", and "Files in Current
>> Directory" etc.

TV> `helm-files-save-history-extra-sources' contain by default locate and find.

OK, but not "Recentf" or "Files in Current Directory" or any others I
use, right?

>> If not, then I have to customize `helm-files-save-history-extra-sources'
>> which as I mentioned is not easy to customize and feels like an
>> unpleasant customization for every Helm user.

TV> Why, as stated above, it's easy, I don't understand what is difficult to
TV> customize this var.

I want to save any file choice I make into the `file-name-history'. The
source I use is irrelevant to me.

This is essential to me. I don't know how to say it more clearly. If
that use case can't be supported by Helm, I'll have to hack it to do so.

TV> BTW, you really should switch to helm-find-files for all your files
TV> task, it will allow you to switch from it to many differents action
TV> related to files (browse-project, locate, find, grep, file history,
TV> etc...), you can also bookmark these sessions.

I tried it before, but find `helm-mini' simpler. It gives me everything
I need in one place without remembering any keybindings.

TV> For file-history, try `C-x C-f C-c h' (assuming C-x C-f is
TV> helm-find-files).

Right, but `file-name-history' is standard across all of Emacs so I
prefer to use it. I don't override the default `C-x C-f' from
`find-file', which does know about `file-name-history'. Without my hack,
I'd hit `C-x C-f Up' and the last file I *opened* in `helm-mini' was not
there.

Let me put it differently: why would anyone *not* want to save their
file choices in `file-name-history'? Isn't that its purpose? Including
only some file sources from `file-name-history' seems like a design
decision, so I'm probably not aware of the original reasons for it.

TV> If you really want to keep helm-mini or helm-for-files, try instead
TV> helm-multi-files which allow to not kick-in locate when searching files:
TV> start typing a filename, if you have no result hit `C-c p' that switch
TV> to locate, hit C-c p again when you want to be back to other sources.

Thanks for the advice. I do prefer the simplicity of `helm-mini'.

Ted

Thierry Volpiatto

unread,
Apr 30, 2015, 2:49:08 PM4/30/15
to emacs...@googlegroups.com

Ted Zlatanov <t...@lifelogs.com> writes:

> TV> No, it is a repeat => string (a list of strings IOW).
>
> Right, that's what I meant :) But the customization interface is
> *extremely* unhelpful to users. It should be a choice from the known
> source names, which the software knows, right? Giving them a repeat
> string is not much better than making it a defvar IMO.

End users should not have to touch this, I have added
helm-files-save-history-extra-sources for experienced users.

> I would also like a way to save for all sources, like I said.

Doing this you will endup with unrelated entries (to files) in
file-name-history.

> So ".*" could work. Or just accept t as a valid setting for this,
> meaning all.

I would prefer 'all.

> If you'd like a patch, I can try to improve this?

PR are always welcome ;-)

But before I had like to know exactly which action from which source is not
adding to file-name-history.

Probably you should first report a bug to emacs-helm.

> TV> You just go to customize menu and add Recentf.
> TV> or
> TV> (add-to-list 'helm-files-save-history-extra-sources "Recentf")
>
> But how do I know to use "Recentf"? It's not obvious when I just want to
> customize things. Think of this as a user who wants to customize the
> variable after installing Helm from a package. They don't want this
> level of engagement with the source code yet :)

Of course, you have to know the source names, which is not so difficult,
the name are in the headers of sources.

> TV> This add twice the files to history.
>
> Right, but it's the only way I found to save *all sources* which I said
> was my goal :)
>
>
> TV> `helm-files-save-history-extra-sources' contain by default locate and find.
>
> OK, but not "Recentf" or "Files in Current Directory" or any others I
> use, right?

I have added these and file-cache too, but it is redundant IMO as emacs
regular commands that are used by helm are in charge of this (i.e
find-file).

> TV> Why, as stated above, it's easy, I don't understand what is difficult to
> TV> customize this var.
>
> I want to save any file choice I make into the `file-name-history'. The
> source I use is irrelevant to me.
>
> This is essential to me. I don't know how to say it more clearly. If
> that use case can't be supported by Helm, I'll have to hack it to do so.
>
> TV> BTW, you really should switch to helm-find-files for all your files
> TV> task, it will allow you to switch from it to many differents action
> TV> related to files (browse-project, locate, find, grep, file history,
> TV> etc...), you can also bookmark these sessions.
>
> I tried it before, but find `helm-mini' simpler. It gives me everything
> I need in one place without remembering any keybindings.

Too bad, if you get used to this you will see how powerful is the
workflow with helm-find-files.
All my work in helm for file handling go in this direction.
helm-for-filles and friends are deprecated IMO.

> TV> For file-history, try `C-x C-f C-c h' (assuming C-x C-f is
> TV> helm-find-files).
>
> Right, but `file-name-history' is standard across all of Emacs so I
> prefer to use it.

Yes, and C-c h IS file-name-history.

> I don't override the default `C-x C-f' from `find-file', which does
> know about `file-name-history'. Without my hack, I'd hit `C-x C-f Up'
> and the last file I *opened* in `helm-mini' was not there.

If you do M-x helm-find-files C-c h you should see your file on top.

> Let me put it differently: why would anyone *not* want to save their
> file choices in `file-name-history'?

I personally don't use recentf but only file-name-history.

> Isn't that its purpose? Including only some file sources from
> `file-name-history' seems like a design decision, so I'm probably not
> aware of the original reasons for it.

Normally the action from type file class use regular emacs function (i.e
find-file) which are in charge of adding to file-name-history.

> TV> If you really want to keep helm-mini or helm-for-files, try instead
> TV> helm-multi-files which allow to not kick-in locate when searching files:
> TV> start typing a filename, if you have no result hit `C-c p' that switch
> TV> to locate, hit C-c p again when you want to be back to other sources.
>
> Thanks for the advice. I do prefer the simplicity of `helm-mini'.

Too bad here too to run locate which is costly when not needed (most of
the time the file you are looking for is in file-name-history or recentf
or in an open buffer).
Reply all
Reply to author
Forward
0 new messages