Skip to content

Instantly share code, notes, and snippets.

@johnmastro
Created April 30, 2015 02:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmastro/508fb22a2b4e1ce754e0 to your computer and use it in GitHub Desktop.
Save johnmastro/508fb22a2b4e1ce754e0 to your computer and use it in GitHub Desktop.
;; An attempt at this Emacs SX question:
;; https://emacs.stackexchange.com/questions/10359/delete-portion-of-isearch-string-that-does-not-match-or-last-char-if-complete-m
(defun isearch-delete-something ()
"Delete non-matching text or the last character."
;; Mostly copied from `isearch-del-char' and Drew's answer on the page above
(interactive)
(if (= 0 (length isearch-string))
(ding)
(setq isearch-string
(substring isearch-string
0
(or (isearch-fail-pos) (1- (length isearch-string)))))
(setq isearch-message
(mapconcat #'isearch-text-char-description isearch-string "")))
(if isearch-other-end (goto-char isearch-other-end))
(isearch-search)
(isearch-push-state)
(isearch-update))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment