Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making minibuffer (editing) behaviour during counsel-find-file more like default find-file #1333

Closed
nordlow opened this issue Nov 29, 2017 · 13 comments

Comments

@nordlow
Copy link

commented Nov 29, 2017

I really love swiper except for one thing.

The changed behaviour (especially editing) of counsel-find-file compared to find-file and alikes.

  1. Is there customization available for making the behaviour more like default find-file?
  2. How do I disable just this remapping while still having counsel-mode active?

@nordlow nordlow changed the title Disable counsel-find-file remap Making (editing) behaviour counsel-find-file more like default find-file Nov 29, 2017

@nordlow nordlow changed the title Making (editing) behaviour counsel-find-file more like default find-file Making minibuffer (editing) behaviour during counsel-find-file more like default find-file Nov 29, 2017

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Nov 29, 2017

You mean you can't edit the directory path? Here's a work-around binding: C-M-o w C-y.
Maybe something a bit better could be hacked together. Why exactly do you need to edit the full path?

@basil-conto

This comment has been minimized.

Copy link
Collaborator

commented Nov 29, 2017

Why exactly do you need to edit the full path?

Does opening a URL with url-handler-mode enabled count? For example:

  1. emacs -Q
  2. M-x url-handler-mode RET https://gnu.org RET

Which, as far as I can tell, isn't compatible with ivy-mode.

Edit

Woops, I meant to write

  1. emacs -Q
  2. M-x url-handler-mode RET
  3. C-x C-f C-a C-k https://gnu.org RET
@abo-abo

This comment has been minimized.

Copy link
Owner

commented Nov 29, 2017

Which, as far as I can tell, isn't compatible with ivy-mode.

True. The most common pattern with URLs for me is to navigate there and C-x C-f M-n.

@nordlow

This comment has been minimized.

Copy link
Author

commented Nov 29, 2017

Many navigation C/-M-f/b and editing bindings are disabled. I cannot backspace single letter or sub-word of path directory, etc etc etc. Behaviour of going up to root directory has changed. Cannot use/complete/expand env variables having paths as values doesn't work etc etc etc.

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Nov 29, 2017

That's a lot of stuff. Let's try to divide it in points:

  1. Many navigation C/-M-f/b and editing bindings are disabled.

C-f, M-f, C-b, M-b all work.

  1. I cannot backspace single letter or sub-word of path directory

This is supposed to be a feature. In the end, we want to open a real file name. Makes sense to me that a real file name is located in a real path, which is already selected. Once you allow to edit the path, you can enter a path that doesn't exist, then the file name part doesn't make sense as well.

  1. Behavior of going up to root directory has changed.

// is very similar to the default completion.

  1. Cannot use/complete/expand env variables having paths as values doesn't work

This perhaps is a possible feature that could be added. Though the most common env variable is $HOME and that is already available with ~.

@jchang10

This comment has been minimized.

Copy link

commented Dec 13, 2017

IMHO. Specifically for issue #2, i find this "feature" frustrating as well. The behavior is modal in that when a directory name is matched, hitting backspace deletes the entire directory name. Whereas when the directory name is not matched, the backspace works as normal and only deletes a character at a time. Often times, I hit backspace a few times and find myself back at the root directory by accident.

I cant recall anywhere else, that the backspace behavior is changed in such a way: deletes a single character vs. deleting the entire word. Usually, when I delete the entire word, I default to M-<backspace> anyway when I want that behavior.

Any way that C-x C-f then backspace just unmatches the current directory and goes back to deleting single char at a time, instead of deleting the entire directory?

Hope that made sense.

@rhashimoto

This comment has been minimized.

Copy link

commented Feb 11, 2018

Here's another use case for getting a fully editable path. In some languages, the convention is to put source and tests in parallel directory trees. For example, Java has this convention.

If I'm editing a source file and I want to open its test, what I'd like to do is use my current path as a starting point and change 'main' to 'test' higher in the directory hierarchy.

A similar use case is having different source control branches of a project under a root project directory. While editing a file under one branch I sometimes want to open the same file in a different branch. I'd like to do that just by editing the branch name on the current path.

C-M-o w C-y does work, thanks for that!

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Feb 11, 2018

I cant recall anywhere else, that the backspace behavior is changed in such a way

This is my directory navigation experience in bash: cd .. or cd ../.. is exactly like this - you go up a directory atomically, there's no way to go to a directory that's a substring of the current one.

Anyway, I've added C-M-y as a fall back button. I tried to avoid this pattern for the longest time, because I think a similar feature was a crutch in Ido. But since people keep asking for it, here it is :)

@danil

This comment has been minimized.

Copy link

commented Nov 8, 2018

workaround for find-file command:

(define-key counsel-find-file-map (kbd "C-x C-f") 'counsel-find-file-fallback-command)
(defun counsel-find-file-fallback-command ()
  "Fallback to non-counsel version of current command."
  (interactive)
  (when (bound-and-true-p ivy-mode)
    (ivy-mode -1)
    (add-hook 'minibuffer-setup-hook
              'counsel-find-file-fallback-command--enable-ivy))
  (ivy-set-action
   (lambda (current-path)
     (let ((old-default-directory default-directory))
       (let ((i (length current-path)))
         (while (> i 0)
           (push (aref current-path (setq i (1- i))) unread-command-events)))
       (let ((default-directory "")) (call-interactively 'find-file))
       (setq default-directory old-default-directory))))
  (ivy-done))
(defun counsel-find-file-fallback-command--enable-ivy ()
  (remove-hook 'minibuffer-setup-hook
               'counsel-find-file-fallback-command--enable-ivy)
  (ivy-mode t))

workaround for cd command:

(define-key ivy-minibuffer-map (kbd "C-x C-f") 'minibuffer-ivy-fallback)
(defun minibuffer-ivy-fallback ()
  "Fallback to non ivy version of current command."
  (interactive)
  (when (bound-and-true-p ivy-mode)
    (ivy-mode -1)
    (add-hook 'minibuffer-setup-hook
              'minibuffer-ivy-fallback--enable-ivy))
  (ivy-set-action
   (lambda (current-path)
     (let ((old-default-directory default-directory))
       (when (not (member last-command '(
                                         dired-create-directory
                                         dired-do-copy
                                         dired-do-rename
                                         )))
         (let ((i (length current-path)))
           (while (> i 0)
             (push (aref current-path (setq i (1- i))) unread-command-events))))
       (let ((default-directory "")) (call-interactively last-command))
       (setq default-directory old-default-directory))))
  (ivy-done))
(defun minibuffer-ivy-fallback--enable-ivy  ()
  (remove-hook 'minibuffer-setup-hook
               'minibuffer-ivy-fallback--enable-ivy )
  (ivy-mode t))
@joaocortes

This comment has been minimized.

Copy link

commented Jan 10, 2019

Would It be simple to extend this to dired commands?
For instance, when renaming a file with dired-rename-file, I would like to press C-M-y and get the same result of counsel-find-file

@unmanifest

This comment has been minimized.

Copy link

commented Feb 19, 2019

Recently switched to counsel/swiper/ivy from ido mode. Is there a plan to add such a feature (much like the ido-fallback-command)? The sample code from @danil probably works but curious to know if there is something already in place that I should be using. Thanks @abo-abo for the great work on these packages.

@vindarel

This comment has been minimized.

Copy link

commented Apr 4, 2019

same here :) I'm quite new to ivy, I'm used to ido-find-file, where I can type C-f to get the raw, default find-file. My use case is 1) creating a new file or directory (with an additional snippet given above) and 2) quickly erasing the path and accessing directories in /.

Regards

(defun my-create-non-existent-directory ()
      (let ((parent-directory (file-name-directory buffer-file-name)))
        (when (and (not (file-exists-p parent-directory))
                   (y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory)))
          (make-directory parent-directory t))))

(add-to-list 'find-file-not-found-functions #'my-create-non-existent-directory)
@abo-abo

This comment has been minimized.

Copy link
Owner

commented Apr 4, 2019

Dear all, please don't pile things onto a closed issue from 2017. This repo is already at 2001 issues. I've read through all of them. But I don't like having to read through a zombie issue for the fifth or tenth time, restoring all the context from 2017, seeing what was improved or fixed in the meantime.

If some part of a closed issue is not yet solved, please open a new issue, copy-pasting only the necessary relevant parts of the old issue.

I really appreciate the community and the contributions, but let's try to work together in a way that saves each other's time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.