Helm: TAB will create new file if no alternative found when using helm-find-files

Created on 10 Jul 2017  路  26Comments  路  Source: emacs-helm/helm

Note that by default, TAB will do nothing but creating a *helm action* list for you to choose one action, so I put

(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)

in my init.el to complete what I typed, and this is the line that affects the wrong TAB behavior like I said in the title of this issue.

Expected behavior

If helm gives no valid result according what I type, TAB should do nothing (since if I want to create the new file, I can use Enter key).

Actual behavior from emacs-helm.sh if possible (See note at bottom)

Yes, the same wrong behavior, if using this:

(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)

Steps to reproduce (recipe)

M-x helm-find-files to find a file in any directory, type anything such as "abc" in the minibuffer, if no valid is in the list, type TAB, a new buffer named "abc" will be created, but the pointer is still in minibuffer, it leaves that way like before you hit TAB, type TAB again, the buffer of current window will change "abc" buffer to another existed buffer in emacs session, keep hitting TAB, the buffer will keep changing.

Note that if the buffer of current window is not "abc", a message Buffer 'abc' killed is in minibuffer, if the buffer of current window is "abc" again since I hit TAB, there will be a message (New file) in the minibuffer.

Backtraces if some (M-x toggle-debug-on-error)

No info.

Describe versions of helm, emacs, operating system etc.

  • GNU Emacs 25.2.1 (i686-pc-linux-gnu, GTK+ Version 2.20.1)
  • helm-20170529.2236, but this happens a long time ago.
  • CentOS6.5 32bit

Most helpful comment

You can now use:

(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)

Which will allow you loosing nice default behavior of helm-find-files PA...

All 26 comments

c02y notifications@github.com writes:

Note that by default, TAB will do nothing but create a helm action
list for you to choose one action, so I put

(define-key helm-map (kbd "") 'helm-execute-persistent-action)

in my init.el, and this is the line that affects the wrong TAB
behavior like I said in the title of this issue.

I don't see why this would affect PA.

Expected behavior

If helm gives no valid result according what I type, TAB should do
nothing (since if I want to create the new file, I can use Enter key).

Why do you want to limit this feature to RET and not PA ?
One may want to create several buffers without quitting helm, or create
a new buffer and do something else like go to another file etc...

The current behavior is what is expected, if it is not what you want to
do why are you using persistent action in this place ?

>

Actual behavior from emacs-helm.sh if possible (See note at bottom)

Yes, the same wrong behavior, if using this:

(define-key helm-map (kbd "") 'helm-execute-persistent-action)

Steps to reproduce (recipe)

M-x helm-find-files to find a file in any directory, type anything
such as "abc" in the minibuffer, if no valid is in the list, type TAB,
a new buffer named "abc" will be created,

That's correct

but the pointer is still in minibuffer, it leaves that way like before
you hit TAB, type TAB again, the buffer of current window will change
"abc" buffer to another existed buffer in emacs session, keep hitting
TAB, the buffer will keep changing.

What happen here is your buffer is not yet a file until you save it.
When using persistent action, first hit open buffer, second hit kill it
etc...
Again that's the expected behavior.

Note that if the buffer of current window is not "abc", a message
Buffer 'abc' killed is in minibuffer, if the buffer of current window
is "abc" again since I hit TAB, there will be a message (New file) in
the minibuffer.

Correct.

--
Thierry
Gpg Key fingerprint = 6CEC 7081 AB33 E251 4AB8 5FC2 28D1 7F53 59F2 9997

One may want to create several buffers without quitting helm, or create a new buffer and do something else like go to another file etc...

I rarely do this.

The current behavior is what is expected, if it is not what you want to do why are you using persistent action in this place ?

I use this because when I started to use helm which is a long time ago, I googled how to use TAB to complete file/directory path and I got this configuration (such as #1630), so I used it, but the unexpected behavior when no completion available occurred to me is really annoying.

Like you said, since helm-execute-persistent-action is designed to do so, are there other options here, to be bound to TAB? What I want is , hitting TAB will complete the string I typed according to the items in the list, if nothing to complete, do nothing.

c02y notifications@github.com writes:

Like you said, since helm-execute-persistent-action is designed to do
so, are there other options here, to be bound to TAB? What I want is ,
hitting TAB will complete the string I typed according to the items in
the list,

At this point you don't have items in the list but ONE item remaining
that can easily identified as a non existing file, so why are you trying
to complete at this point, just don't hit TAB or C-j and that's all.

if nothing to complete, do nothing.

No, it is up to you to understand that when there is only one file
remaining in helm-buffer which is not a directory there is no more thing
to complete, and the next action persistent-action is doing is showing
the buffer representing file.

--
Thierry
Gpg Key fingerprint = 6CEC 7081 AB33 E251 4AB8 5FC2 28D1 7F53 59F2 9997

At this point you don't have items in the list but ONE item remaining that can easily identified as a non existing file, so why are you trying to complete at this point, just don't hit TAB or C-j and that's all.

This happens because I type and hit TAB too fast, or sometimes I mistype a letter and realize that there is no completion available, but I already hit TAB and a new buffer will be created. Since today I noticed that I can just hit TAB again to kill the new created buffer, but this is still a little annoying to hit TAB again.

If there is no such configuration that TAB will just complete the path and not create new file, and no plan for writing new code for that, I guess I have to spend some to getting used to it, or maybe I can tweak the helm-execute-persistent-action.

c02y notifications@github.com writes:

If there is no such configuration that TAB will just complete the path
and not create new file, and no plan for writing new code for that,

The current behavior is fine for most people, I never had any complains
about this, so yes I guess you will have to get used of it.

--
Thierry
Gpg Key fingerprint = 6CEC 7081 AB33 E251 4AB8 5FC2 28D1 7F53 59F2 9997

You can now use:

(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)

Which will allow you loosing nice default behavior of helm-find-files PA...

I tried:

(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)
But I still get the behavior of creating new file with tab when there is no existing match.
Am I missing something?

hisnawi notifications@github.com writes:

I tried:

(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)
But I still get the behavior of creating new file with tab when there is no existing match.
Am I missing something?

This have nothing to do with new file, also I don't know what TAB is
doing (it is menu action by default).
What do you want to do exactly?

--
Thierry

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

When finding a file/directory with helm-find-files and when mistakenly entering a name that is not existing, hitting tab (which is usually used for autocomplete) will open a new file.
I want to continue using tab to autocomplete, but not open a new file when entering a new file name.

It is basically what the title of this post says "TAB will create new file if no alternative found when using helm-find-files".

hisnawi notifications@github.com writes:

When finding a file/directory with helm-find-files and when mistakenly entering a name that is not existing, hitting tab (which is usually used for autocomplete) will open
a new file.
I want to continue using tab to autocomplete, but not open a new file when entering a new file name.

Still don't know on what TAB is bound (what is autocomplete) in your
configuration, please use emacs-helm.sh and tell exactly what you expect
from there.

Thanks.

--
Thierry

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

@thierryvolpiatto I did not clone the repo and so can't use the script.
But here is my emacs setup:

  (use-package helm
    :ensure t
    :bind (
           ("M-x"       . helm-M-x)
           ("M-Z"       . helm-mini)
           ("C-x b"     . helm-mini)
           ("C-h a"     . helm-apropos)
           ("C-x C-f"   . helm-find-files)
           ("C-c C-r"   . helm-resume)
           :map helm-map
           ("<S-left>"  . helm-beginning-of-buffer)
           ("<S-right>" . helm-end-of-buffer)
           ("<S-up>"    . helm-previous-page)
           ("<S-down>"  . helm-next-page)
           ("<tab>"     . helm-execute-persistent-action)
           ("C-z"       . helm-select-action)
           )
    :diminish helm-mode
    :config
    (helm-adaptive-mode 1)                         ;; Sort buffers based on usage frequency
    (setq helm-ag-insert-at-point             'symbol
          helm-ff-ido-style-backspace         'always
          helm-ff--auto-update-state          t
          helm-ff-newfile-prompt-p            nil
          helm-ff-skip-boring-files           t
          helm-mp-highlight-delay             0.3       ;; Highlighting of token matches is a tad slow, let鈥檚 speed it up
          helm-display-function               'pop-to-buffer
          helm-display-header-line            nil
          helm-autoresize-max-height          30
          helm-autoresize-min-height          30
          helm-split-window-in-side-p         t
          helm-echo-input-in-header-line      t
          helm-ff-guess-ffap-urls             nil  ;; Disable guessing URL at point
          helm-ff-kill-or-find-buffer-fname-fn 'ignore 
          )
)

So tab is mapped to helm-execute-persistent-action.
I just don't want it to start a new file if there are no matching candidates.

hisnawi notifications@github.com writes:

@thierryvolpiatto I did not clone the repo and so can't use the script.
But here is my emacs setup:

(use-package helm
:ensure t
:bind (
("M-x" . helm-M-x)
("M-Z" . helm-mini)
("C-x b" . helm-mini)
("C-h a" . helm-apropos)
("C-x C-f" . helm-find-files)
("C-c C-r" . helm-resume)
:map helm-map
("" . helm-beginning-of-buffer)
("" . helm-end-of-buffer)
("" . helm-previous-page)
("" . helm-next-page)
("" . helm-execute-persistent-action)
("C-z" . helm-select-action)
)
:diminish helm-mode
:config
(helm-adaptive-mode 1) ;; Sort buffers based on usage frequency
(setq helm-ag-insert-at-point 'symbol
helm-ff-ido-style-backspace 'always
helm-ff--auto-update-state t
helm-ff-newfile-prompt-p nil
helm-ff-skip-boring-files t
helm-mp-highlight-delay 0.3 ;; Highlighting of token matches is a tad slow, let鈥檚 speed it up
helm-display-function 'pop-to-buffer
helm-display-header-line nil
helm-autoresize-max-height 30
helm-autoresize-min-height 30
helm-split-window-in-side-p t
helm-echo-input-in-header-line t
helm-ff-guess-ffap-urls nil ;; Disable guessing URL at point
helm-ff-kill-or-find-buffer-fname-fn 'ignore
)
)

So tab is mapped to helm-execute-persistent-action.
I just don't want it to start a new file if there are no matching candidates.

So why are you pressing persistent action? What do you expect?

--
Thierry

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

I thought that this setting:
(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)
Would change the helm-execute-persistent-action to not create a new file if no match is found.

hisnawi notifications@github.com writes:

I thought that this setting: (setq
helm-ff-kill-or-find-buffer-fname-fn 'ignore) Would change the
helm-execute-persistent-action to not create a new file if no match is
found.

It does, at least here, otherwise with default-setting, first hit on C-j
(tab for you) open a new buffer, second hit kill the created buffer.

NOTE: Your setting is deprecated, some variables have been removed years
ago.

--
Thierry

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

Interesting. For me a second tab doesn't close the newly created buffer. I have to kill the buffer with a shortcut.
Just to confirm, a second hit you mean clicking tab again.

Thanks for the tip, I had my configuration for over 5 years now. Time to clean it up.

hisnawi notifications@github.com writes:

@thierryvolpiatto I did not clone the repo and so can't use the
script.

You can even from Melpa installation.

--
Thierry

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

FWIW, I am on latest Helm (from Git) and with (setq helm-ff-kill-or-find-buffer-fname-fn #'ignore) and TAB bound to helm-execute-persistent-action I get the behaviour @hisnawi wants.

@manuel-uberti thanks for confirming. Could you share your helm configuration?

Also could you describe what happens when you click tab with new unmatched name? Does it open a new buffer and another tab deletes it?

Sorry, it's more than 700 files of code for Helm and its related packages, I prefer not to paste it here.

I can assure you though that besides binding TAB to helm-execute-persistent-action in helm-map and setting helm-ff-kill-or-find-buffer-fname-fn to #'ignore the rest is not relevant to this discussion. :)

Also could you describe what happens when you click tab with new unmatched name? Does it open a new buffer and another tab deletes it?

In this situation, nothing happens when I press TAB with the aforementioned settings.

So you mean pressing tab on an unmatched name "won't" open a new buffer, it just wont do anything. Correct?

hisnawi notifications@github.com writes:

Interesting. For me a second doesn't close the newly created buffer. I have to kill the buffer with a shortcut.
Just to confirm, a second hit you mean clicking again.

From emacs-helm.sh:

C-j open a new buffer, C-j again kill this buffer.

Thanks for the tip, I had my configuration for over 5 years now. Time to clean it up.

Also most people use for their config (use-package helm) which is
wrong, this just load helm.el and none of the other helm files.
Use (require 'helm-config) as specified in helm wiki.

--
Thierry

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

So you mean pressing tab on an unmatched name "won't" open a new buffer, it just wont do anything. Correct?

Exactly.

Exactly.

This is not the behavior @thierryvolpiatto mentioned. So I am confused now.
@thierryvolpiatto says hitting tab should open a new buffer and hitting tab again should delete it.
@manuel-uberti says hitting tab wont do anything on the unmatched name.
I see a third behavior where the new buffer is open but not getting canceled when clicking tab again.

You can now use:

(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)

Which will allow you loosing nice default behavior of helm-find-files PA...

I followed this suggestion by @thierryvolpiatto, and I did already have TAB bound to helm-execute-persistent-action. Without setting helm-ff-kill-or-find-buffer-fname-fn I get the behaviour @thierryvolpiatto describes when using emacs-helm.sh.

Apologies for the false negative. It was this code. After removing it, things worked as expected.

    ;; Proper backspace and forward movement in find-files
    (defun fu/helm-find-files-navigate-forward (orig-fun &rest args)
      (if (and (equal "Find Files" (assoc-default 'name (helm-get-current-source)))
               (equal args nil)
               (stringp (helm-get-selection))
               (not (file-directory-p (helm-get-selection))))
          (helm-maybe-exit-minibuffer)
        (apply orig-fun args)))
    (defun fu/helm-find-files-navigate-back (orig-fun &rest args)
      (if (= (length helm-pattern) (length (helm-find-files-initial-input)))
          (helm-find-files-up-one-level 1)
        (apply orig-fun args)))
    (with-eval-after-load 'helm-files
      (advice-add 'helm-ff-delete-char-backward :around #'fu/helm-find-files-navigate-back)
      (advice-add 'helm-execute-persistent-action :around #'fu/helm-find-files-navigate-forward)
      )

Was this page helpful?
0 / 5 - 0 ratings