[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master b75439e 2/5: Add "/" and "~" shortcuts while finding files
From: |
Oleh Krehel |
Subject: |
[elpa] master b75439e 2/5: Add "/" and "~" shortcuts while finding files |
Date: |
Fri, 17 Apr 2015 11:50:06 +0000 |
branch: master
commit b75439eabfed83671485359021533135e797313d
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add "/" and "~" shortcuts while finding files
* ivy.el (ivy--cd): New defun.
(ivy-backward-delete-char): Use `ivy--cd'.
(ivy--exhibit): When the file completion text ends in "/" or "~", move to
those dirs.
---
ivy.el | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ivy.el b/ivy.el
index ac631f6..7ab0ce8 100644
--- a/ivy.el
+++ b/ivy.el
@@ -188,18 +188,25 @@ If the input is empty, select the previous history
element instead."
(next-history-element arg)
(move-end-of-line 1))
+(defun ivy--cd (dir)
+ "When completing file names, move to directory DIR."
+ (if (null ivy--directory)
+ (error "Unexpected")
+ (setq ivy--old-cands nil)
+ (setq ivy--all-candidates
+ (let ((default-directory (setq ivy--directory dir)))
+ (all-completions "" 'read-file-name-internal)))
+ (setq ivy-text "")
+ (delete-minibuffer-contents)))
+
(defun ivy-backward-delete-char ()
"Forward to `backward-delete-char'.
On error (read-only), call `ivy-on-del-error-function'."
(interactive)
(if (and ivy--directory (= (minibuffer-prompt-end) (point)))
(progn
- (setq ivy--old-cands nil)
- (setq ivy--all-candidates
- (let ((default-directory (setq ivy--directory
- (file-name-directory
- (directory-file-name
ivy--directory)))))
- (all-completions "" 'read-file-name-internal)))
+ (ivy--cd (file-name-directory
+ (directory-file-name ivy--directory)))
(ivy--exhibit))
(condition-case nil
(backward-delete-char 1)
@@ -450,6 +457,11 @@ When non-nil, it should contain one %d.")
Should be run via minibuffer `post-command-hook'."
(setq ivy-text (ivy--input))
(ivy--cleanup)
+ (when ivy--directory
+ (if (string-match "/$" ivy-text)
+ (ivy--cd "/")
+ (if (string-match "~$" ivy-text)
+ (ivy--cd (expand-file-name "~/")))))
(let ((text (ivy-completions
ivy-text
ivy--all-candidates))