re-think file-name history #112

Closed
lewang opened this Issue Sep 3, 2012 · 16 comments

Comments

Projects
None yet
3 participants
Member

lewang commented Sep 3, 2012

Hi @thierryvolpiatto,

Helm has helm-file-name-history defined in "helm-locate.el". Why is this?
It seems to only be used for helm-locate? This variable name is too
generalized for this purpose?


For a point of reference, here is what I find useful in default Emacs.

  1. Any time you read a file-name in the minibuffer, it gets written to
    file-name-history.
  2. While reading a filename, filenames in this variable are accessible with M-p and M-n.

I make use of this history very frequently. For example, I'll rename a file
in dired, and want to open it later. I can just hit M-p a few times to find it.


Can you give some thought to this kind of consistent treatment of filenames in helm?

That is:

  1. Whenever a filename is read, add it to file-name-history (helm does not
    need to keep its own history, this is good enough.)

  2. Have a mechanism of grabbing a filename out of file-name-history whenever
    reading a filename.

    Much like if I disable helm-mode , I can complete against minibuffer
    input history with during minibuffer input.

Owner

thierryvolpiatto commented Sep 3, 2012

when you copy files from helm-find-files, the history used is helm-ff-history, which record not file names but the directories visited.

You can try:
M-x helm-find-files
enter a new directory name ending with "/"
Press enter, say yes to create a new dir.
Then navigate to some file and try to copy it to this directory, you will see as soon as you start typing the first completion that popup is this directory name.

Owner

thierryvolpiatto commented Sep 3, 2012

Also read the docstring of helm about the meaning of the history keyword.

Member

lewang commented Sep 3, 2012

The issue is that Emacs by default does a good job of keeping file-name-history consistent (every time a filename is completed, it gets added there), and accesssible (M-p).

I want to have the same thing in Helm. Is this possible with existing facilities?

I know about helm-ff-history, but it isn't exactly what I'm after. I just want a list of recently used filenames.

Owner

thierryvolpiatto commented Sep 3, 2012

Everything is possible ;-), just need to know what you exactly want to do.
Can you show me situation in helm where you need a different history?
I have developed in helm-find-files helm-ff-history that store DIRECTORIES, which is more efficient for copying/renaming purpose than an history of FILES and DIRECTORIES, but maybe you have an other idea in head?

Member

lewang commented Sep 20, 2012

As a first step, from helm-find-file or any other file-name completion, I'd like to be able to

  1. press C-c h to enter a mini helm-session to choose an element of file-name-history
  2. If I press enter then the default action is taken using that element, if I press C-e, then the entry is used as the new starting point for helm-find-file.

@thierryvolpiatto Can you comment on the feasibility of these steps?

Owner

thierryvolpiatto commented Sep 20, 2012

Le Wang notifications@github.com writes:

As a first step, from helm-find-file or any other file-name completion, I'd like to be able to

  1. press to enter a mini helm-session to choose an element of file-name-history
  2. If I press then the default action is taken using that element, if I press C-e, then the entry is used as the new starting point for helm-find-file.

@thierryvolpiatto Can you comment on the feasibility of these steps?
What about a new function used as action, called say
helm-ff-file-name-history that have two actions:

  1. the one you want when using RET.
  2. another one that switch to helm-find-files.
    Note that this second action would be redundant as it would be already
    available with C-x C-f.

Note also that when pressing C-g you will lost your initial
helm-find-files session.

OTOH you could run another helm-session on top of your existing one
using helm keyword :allow-nest, like this hitting C-g will return in
your initial helm-find-files session.

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

Owner

thierryvolpiatto commented Sep 21, 2012

Maybe something like this is what you need:

(defun helm-ff-file-name-history ()
  (interactive)
  (let ((src (copy-alist helm-c-source-file-name-history)))
    (helm-attrset 'action '(("find file" . (lambda (candidate)
                                             (helm-set-pattern
                                              (expand-file-name candidate))
                                             (run-with-idle-timer 0.1 nil 'helm-exit-minibuffer)))
                            ("find file in helm" . (lambda (candidate)
                                                     (helm-set-pattern
                                                      (expand-file-name candidate)))))
                  src)
    (helm :sources (quote src)
          :buffer "*helm-file-name-history*"
          :allow-nest t)))
(define-key helm-find-files-map (kbd "C-c h") 'helm-ff-file-name-history)

thierryvolpiatto added a commit that referenced this issue Sep 24, 2012

* helm-files.el: Issue #112 Add file history to helm-find-files.
(helm-c-source-ff-file-name-history): new source.
(helm-ff-file-name-history): New function, use it in *find-files.
Contributor

snarfed commented Nov 7, 2012

thanks for this! i'm happily using the new source.

i wanted the other part of @lewang's request too, though: updating file-name-history. i ended up using this, just fyi:

(defadvice helm-exit-minibuffer (before save-to-file-name-history activate)
  "If helm selected a filename, save it to file-name-history."
  (if (file-exists-p (helm-get-selection))
      (push (helm-get-selection) file-name-history)))
Owner

thierryvolpiatto commented Nov 7, 2012

Ryan Barrett notifications@github.com writes:

thanks for this! i'm happily using the new source.

i wanted the other part of @lewang's request too, though: updating file-name-history. i ended up using this, just fyi:

(defadvice helm-exit-minibuffer (before save-to-file-name-history activate)
  "If helm selected a filename, save it to file-name-history."
  (if (file-exists-p (helm-get-selection))
      (push (helm-get-selection) file-name-history)))

Instead of advicing helm-exit-minibuffer, you can use
helm-after-action-hook.

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

Owner

thierryvolpiatto commented Nov 7, 2012

You can also use helm-ff-file-name-history-use-recentf instead of file-name-history.
The problem with helm is that it doesn't use the contents of minibuffer when exiting but the selection, so what is saved in diverse history vars is an incomplete minibuffer contents (not always but mostly).

Contributor

snarfed commented Nov 7, 2012

thanks!

i tried a number of the helm hooks, including after-action and cleanup, but they always fired twice and ended up putting duplicate entries into file-name-history. not sure why.

helm's recentf support is good too, but i prefer file-name-history since it's much more widely integrated into emacs.

lewang pushed a commit to lewang/Emacs-helm that referenced this issue Nov 17, 2012

Member

lewang commented Nov 17, 2012

@thierryvolpiatto fbbbb5c removed the find-file as default action, it would be more consistent if it could be put back.

Owner

thierryvolpiatto commented Nov 17, 2012

Le Wang notifications@github.com writes:

@thierryvolpiatto fbbbb5c removed the find-file as default action, it would be more consistent if it could be put back.
Not yet, it is buggy on Windows, (I need a better way to defer such
actions)
so for now I stay like that, not a big
problem, just need to hit two times on RET.


Reply to this email directly or view it on GitHub:
#112 (comment)

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

lewang pushed a commit that referenced this issue Nov 18, 2012

Member

lewang commented Nov 18, 2012

@snarfed are you happy to close this based on the state of things?

Contributor

snarfed commented Nov 18, 2012

thanks for checking, and for the update! it doesn't actually work for me as is since i use other sources that aren't in helm-file-completion-sources, e.g. helm-c-source-file-name-history and helm-c-source-files-in-current-dir. i'm happy using my advice (above) though, so definitely don't block on me!

Member

lewang commented Nov 19, 2012

Emacs should take care of updating file-name-history through find-file.

@lewang lewang closed this Nov 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment