]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel: Add counsel-up-directory to find-file-map
authorjustbur <justin@burkett.cc>
Tue, 12 Jan 2016 00:26:09 +0000 (19:26 -0500)
committerOleh Krehel <ohwoeowho@gmail.com>
Tue, 12 Jan 2016 08:00:53 +0000 (09:00 +0100)
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

index 4a734d492960c4d6fb6850fed6bece12d62720f5..6a97b70180fcc80826ee6bc14330ea674cbe45da 100644 (file)
@@ -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)