From 789a91219f4e33d617a65fa5888ab71c732cdd6c Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Thu, 6 Oct 2022 10:24:25 -0800 Subject: [PATCH] Stabilize directory backspace in minibuffer, see link in comment --- lisp/mitch-packages.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 0c43bd7..db3d7f3 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -198,13 +198,15 @@ This is taken from a website that I can't remember at the moment." (add-hook 'minibuffer-setup-hook 'turn-off-line-numbers) (defun backspace-in-minibuffer () "If previous character is `/', kill to the previous `/'. -Otherwise, kill back 1 letter." +Otherwise, kill back 1 letter. + +see https://www.reddit.com/r/emacs/comments/xq6rpa/comment/iqynyu9/?utm_source=share&utm_medium=web2x&context=3" (interactive) - (if (= (string-to-char "/") (preceding-char)) - (progn - (delete-region (- (point) 1) - (search-backward "/" nil nil 2)) - (goto-char (1+ (point)))) + (if (string-match-p "/." (minibuffer-contents)) + (let ((end (point))) + (re-search-backward "/.") + (forward-char) + (delete-region (point) end)) (backward-delete-char 1))) :general (general-define-key