emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/vertico eaf0959724 1/2: vertico-directory-enter: Handle


From: ELPA Syncer
Subject: [elpa] externals/vertico eaf0959724 1/2: vertico-directory-enter: Handle ./ and ../ properly
Date: Wed, 21 Dec 2022 09:58:19 -0500 (EST)

branch: externals/vertico
commit eaf09597241eb820ed090ed4cbb91746d9f9a4fc
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    vertico-directory-enter: Handle ./ and ../ properly
    
    Instead of backspace (vertico-directory-up) the user can also enter .. RET 
to go
    up one directory.
---
 extensions/vertico-directory.el | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/extensions/vertico-directory.el b/extensions/vertico-directory.el
index 9d845b1efc..5b6d84dc4e 100644
--- a/extensions/vertico-directory.el
+++ b/extensions/vertico-directory.el
@@ -39,20 +39,29 @@
 ;;; Code:
 
 (require 'vertico)
+(eval-when-compile (require 'subr-x))
 
 ;;;###autoload
 (defun vertico-directory-enter ()
   "Enter directory or exit completion with current candidate."
   (interactive)
-  (if (and (>= vertico--index 0)
-           (let ((cand (vertico--candidate)))
-             (or (string-suffix-p "/" cand)
+  (if-let* (((>= vertico--index 0))
+            ((eq 'file (vertico--metadata-get 'category)))
+            ;; Check vertico--base for stepwise file path completion
+            ((not (equal vertico--base "")))
+            (cand (vertico--candidate))
+            ((or (string-suffix-p "/" cand)
                  (and (vertico--remote-p cand)
-                      (string-suffix-p ":" cand))))
-           ;; Check vertico--base for stepwise file path completion
-           (not (equal vertico--base ""))
-           (eq 'file (vertico--metadata-get 'category)))
-      (vertico-insert)
+                      (string-suffix-p ":" cand)))))
+      (progn
+        ;; Handle ./ and ../ manually instead of via `expand-file-name' and
+        ;; `abbreviate-file-name', such that we don't accidentially perform
+        ;; unwanted substitutions in the existing completion.
+        (setq cand (replace-regexp-in-string "/\\./" "/" cand))
+        (unless (string-suffix-p "/../../" cand)
+          (setq cand (replace-regexp-in-string "/[^/|:]+/\\.\\./\\'" "/" 
cand)))
+        (delete-minibuffer-contents)
+        (insert cand))
     (vertico-exit)))
 
 ;;;###autoload



reply via email to

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