From 31d2dfee13c33fa6ba4d36e09d808968b11c528d Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Wed, 27 Sep 2023 08:37:03 +0200 Subject: [PATCH] New command to delete char backward When deleting char backward very fast (keep pressing DEL), cursor hit prompt and we have a read-only error; Helm in this case doesn't have the time to update according to minibuffer contents. This command ensure this is done. --- helm-core.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/helm-core.el b/helm-core.el index af785fb0c..5ea0954e7 100644 --- a/helm-core.el +++ b/helm-core.el @@ -427,6 +427,7 @@ i.e. the loop is not entered after running COMMAND." (define-key map (kbd "M-(") #'helm-prev-visible-mark) (define-key map (kbd "M-)") #'helm-next-visible-mark) (define-key map (kbd "C-k") #'helm-delete-minibuffer-contents) + (define-key map (kbd "DEL") #'helm-delete-char-backward) (define-key map (kbd "C-x C-f") #'helm-quit-and-find-file) (define-key map (kbd "M-m") #'helm-toggle-all-marks) (define-key map (kbd "M-a") #'helm-mark-all) @@ -4014,16 +4015,29 @@ Update is reenabled when idle 1s." (with-helm-alive-p (unless helm--suspend-update-interactive-flag (helm-suspend-update 1)) - (delete-char (- arg)) + (helm-delete-char-backward arg) (run-with-idle-timer 1 nil (lambda () (unless helm--suspend-update-interactive-flag (helm-suspend-update -1) (helm-check-minibuffer-input) - (helm-force-update)))))) + ;; Already done by helm-delete-char-backward. + (unless (string= (minibuffer-contents) "") + (helm-force-update))))))) (put 'helm-delete-backward-no-update 'helm-only t) +(defun helm-delete-char-backward (arg) + "Delete char backward and update when reaching prompt." + (interactive "p") + (condition-case _err + (delete-char (- arg)) + (buffer-read-only + (progn + (helm-update) + (helm-reset-yank-point))))) +(put 'helm-delete-char-backward 'helm-only t) + (defun helm--suspend-read-passwd (old--fn &rest args) "Suspend Helm while reading password. This is used to advice `tramp-read-passwd', `ange-ftp-get-passwd'