Skip to content

Instantly share code, notes, and snippets.

@Philonous
Created January 5, 2014 01:32
Show Gist options
  • Save Philonous/8263168 to your computer and use it in GitHub Desktop.
Save Philonous/8263168 to your computer and use it in GitHub Desktop.
(defun zap-up-to-char (arg char)
"Kill up to, but not including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
Ignores CHAR at point."
(interactive "p\ncZap up to char: ")
(let ((direction (if (>= arg 0) 1 -1)))
(kill-region (point)
(progn
(forward-char direction)
(unwind-protect
(search-forward (char-to-string char) nil nil arg)
(backward-char direction))
(point)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment