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

select previous directory on ivy--cd #1257

Pitometsu opened this issue Oct 29, 2017 · 6 comments

select previous directory on ivy--cd #1257

Pitometsu opened this issue Oct 29, 2017 · 6 comments


Copy link

When I call counsel-find-file, and jump to parent directory,
I actually see first item . selected.
What I expect to see is previous directory selected (like helm-find-file does).
Is it possible to customize swiper this way?

Copy link

abo-abo commented Oct 30, 2017

Thanks, please test.

Copy link

Pitometsu commented Oct 30, 2017

Confirm. Nice, thank you!

abo-abo added a commit that referenced this issue Nov 3, 2017
This reverts commit 31e801f.

Reason: the new change conflicts with the common use-case of using
"R" (`dired-do-rename') to move a folder in dired to a parent folder.
With the new change, the first item selected after "DEL" is the start
folder inside the parent folder.

Re #1257
Copy link

abo-abo commented Nov 3, 2017

Sorry, but I had to revert the change. The same code is used for basically all completion. With this change, moving a file to its parent's parent became harder. I don't think it's a worthwhile trade-off for one-item history.

We can add a better history later if it's required, but it won't be on DEL.

Copy link

Pitometsu commented Nov 5, 2017

@abo-abo could you reopen this issue then?

Didn't know that counsel able to move files. How can I do it to check several variants for compatibility?

For now I just use additional command based on your changes:

(defun ivy-backward-directory ()
  "Forward to `kill-start-of-line'.
On error (read-only), call `ivy-on-del-error-function'."
  (if (and ivy--directory (= (minibuffer-prompt-end) (point)))
        (let ((old-dir (file-name-nondirectory
                        (directory-file-name ivy--directory)))
          (ivy--cd (file-name-directory
          (when (setq idx (cl-position
                           (file-name-as-directory old-dir)
                           :test 'equal))
            (ivy-set-index idx))))
    (condition-case nil
        (kill-start-of-line) ; a little different here
       (when ivy-on-del-error-function
         (funcall ivy-on-del-error-function))))))

(eval-after-load 'ivy
     (define-key ivy-minibuffer-map (kbd "C-l") 'ivy-backward-directory)

Copy link

Pitometsu commented Nov 5, 2017

Perhaps as common solution it would be better to add separate keymap for counsel-find-file (inherit it from general counsel keymap). It would let define additional behavior e.g. for arrow keys when point reaches begin/end of filename to do ivy-backward-directory and ivy-alt-done respectively.

Copy link

abo-abo commented Nov 6, 2017

Since you asked, I reopen the issue. I try my best to make available the necessary facilities for customization. But without special care, more customization can mean less consistency: just like we saw in the above commit.

counsel-find-file-map is already available for customization. You can customize whatever key you want and:

  • either keep it in your config
  • if it's reusable and useful to others, open a PR to counsel.el
  • start your own package based on ivy or counsel (nice examples are ivy-rich and counsel-projectile)

@abo-abo abo-abo reopened this Nov 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants