Ah yes. Isearch reads the keys you type, looks them up in isearch-mode-map
, and invokes them in the current buffer.
Isearch does not, in spite of appearances, use the minibuffer. It uses the echo area. That is, what you see there is actually output messages, including echoes of the characters you type.
This should do what you ask:
(defun mydelete ()
"Delete the failed portion of the search string, or the last char if successful."
(interactive)
(with-isearch-suspended
(setq isearch-new-string
(substring
isearch-string 0 (or (isearch-fail-pos) (1- (length isearch-string))))
isearch-new-message
(mapconcat 'isearch-text-char-description isearch-new-string ""))))
(define-key isearch-mode-map (kbd "DEL") 'mydelete)
(BTW, your question says the delete
character, but you wrote DEL
, which is the backspace character.)