branch: externals/vertico
commit eaf09597241eb820ed090ed4cbb91746d9f9a4fc
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
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