[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 92d5335 291/399: Add counsel-up-level command

From: Oleh Krehel
Subject: [elpa] master 92d5335 291/399: Add counsel-up-level command
Date: Sat, 20 Jul 2019 14:57:42 -0400 (EDT)

branch: master
commit 92d5335caee6c8240fc2e0123858d2b239bffe0d
Author: Chris Gregory <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add counsel-up-level command
    Fixes #1096
 counsel.el | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/counsel.el b/counsel.el
index c13a4b1..a835908 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1984,11 +1984,24 @@ If USE-IGNORE is non-nil, try to generate a command 
that respects
                   (counsel--elisp-to-pcre ivy--old-re)
                 (counsel--file-name-filter t)))))))
+(defvar counsel-up-directory-level t
+  "Control whether `counsel-up-directory' goes up a level or always a 
+If non-nil, then `counsel-up-directory' will remove the final level of the 
+For example: /a/long/path/file.jpg => /a/long/path/
+             /a/long/path/     =>     /a/long/
+If nil, then `counsel-up-directory' will go up a directory.
+For example: /a/long/path/file.jpg => /a/long/
+             /a/long/path/     =>     /a/long/")
 (defun counsel-up-directory ()
   "Go to the parent directory preselecting the current one.
 If the current directory is remote and it's not possible to go up any
-further, make the remote prefix editable"
+further, make the remote prefix editable.
+See variable `counsel-up-directory-level'."
   (let* ((cur-dir (directory-file-name (expand-file-name ivy--directory)))
          (up-dir (file-name-directory cur-dir)))
@@ -2003,9 +2016,11 @@ further, make the remote prefix editable"
           (setq ivy-text "")
           (insert up-dir))
-      (ivy--cd up-dir)
-      (setf (ivy-state-preselect ivy-last)
-            (file-name-as-directory (file-name-nondirectory cur-dir))))))
+      (if (and counsel-up-directory-level (not (string= ivy-text "")))
+          (delete-region (line-beginning-position) (line-end-position))
+        (ivy--cd up-dir)
+        (setf (ivy-state-preselect ivy-last)
+              (file-name-as-directory (file-name-nondirectory cur-dir)))))))
 (defun counsel-down-directory ()
   "Descend into the current directory."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]