branch: master commit 66e00eda6cf0d89280194bd5017392b0fa9b1fd7 Author: justbur <jus...@burkett.cc> Commit: Oleh Krehel <ohwoeo...@gmail.com>
counsel: Add counsel-up-directory to find-file-map New function that moves up to the parent directory and at the same time preselects the current directory. This is useful for moving up and down a file tree quickly. Fixes #343 --- counsel.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/counsel.el b/counsel.el index 4a734d4..6a97b70 100644 --- a/counsel.el +++ b/counsel.el @@ -457,7 +457,20 @@ INITIAL-INPUT can be given as the initial minibuffer input." (declare-function ffap-guesser "ffap") -(defvar counsel-find-file-map (make-sparse-keymap)) +(defvar counsel-find-file-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-DEL") 'counsel-up-directory) + (define-key map (kbd "C-<backspace>") 'counsel-up-directory) + map)) + +(defun counsel-up-directory () + "Go to the parent directory preselecting the current one." + (interactive) + (let ((dir-file-name + (directory-file-name (expand-file-name ivy--directory)))) + (ivy--cd (file-name-directory dir-file-name)) + (setf (ivy-state-preselect ivy-last) + (file-name-as-directory (file-name-nondirectory dir-file-name))))) ;;;###autoload (defun counsel-find-file (&optional initial-input)