From 94e952edf07199198f22e7c3c375a61112d059ad Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Thu, 5 Oct 2023 20:24:35 +0100 Subject: [PATCH] =?UTF-8?q?Improve=20ivy--magic-file-slash=20to=20not=20at?= =?UTF-8?q?tempt=20to=20visit=20directory=20we=E2=80=99re=20already=20in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I found an issue where current directory is being visited repeatedly on pressing / without doing any progress. It was an empty directory and I wanted to get literal ‘/’ inserted. In any case visiting the directory we’re already in serves no purpose. --- ivy.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ivy.el b/ivy.el index c0d2a062..5ddbe64e 100644 --- a/ivy.el +++ b/ivy.el @@ -3268,7 +3268,8 @@ Possible choices are `ivy-magic-slash-non-match-cd-selected', (eolp)) (eq this-command #'ivy-partial-or-done)) (let ((canonical (expand-file-name ivy-text ivy--directory)) - (magic (not (string= ivy-text "/")))) + (magic (not (string= ivy-text "/"))) + dest-dir) (cond ((member ivy-text ivy--all-candidates) (ivy--cd canonical)) ((and (eq system-type 'windows-nt) (string= ivy-text "//"))) @@ -3292,9 +3293,12 @@ Possible choices are `ivy-magic-slash-non-match-cd-selected', (file-directory-p (ivy-state-current ivy-last)) (or (eq ivy-magic-slash-non-match-action 'ivy-magic-slash-non-match-cd-selected) - (eq this-command #'ivy-partial-or-done)))) - (ivy--cd - (expand-file-name (ivy-state-current ivy-last) ivy--directory))) + (eq this-command #'ivy-partial-or-done)) + ;; No point in visiting directory we’re already in. + (not (equal ivy--directory + (setf dest-dir + (expand-file-name (ivy-state-current ivy-last) ivy--directory)))))) + (ivy--cd dest-dir)) ((and (eq ivy-magic-slash-non-match-action 'ivy-magic-slash-non-match-create) magic)