From 78f350af02f2a7d5253f65b7fb41cc3775cfbcfe Mon Sep 17 00:00:00 2001 From: fpi Date: Sun, 5 Apr 2020 13:20:26 +0200 Subject: Add function to zap-to-char excluding char --- emacs-init.org | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'emacs-init.org') diff --git a/emacs-init.org b/emacs-init.org index 60a4c4d..a3120e9 100644 --- a/emacs-init.org +++ b/emacs-init.org @@ -946,7 +946,26 @@ This was inspired from [[http://endlessparentheses.com/the-toggle-map-and-wizard ** Base commands (simple.el) #+begin_src emacs-lisp (use-package simple - :delight (visual-line-mode)) + :delight (visual-line-mode) + :config + (defun zap-up-to-char (arg char) + "Kill up to and excluding 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." + (interactive (list (prefix-numeric-value current-prefix-arg) + (read-char "Zap to char: " t))) + ;; Avoid "obsolete" warnings for translation-table-for-input. + (with-no-warnings + (if (char-table-p translation-table-for-input) + (setq char (or (aref translation-table-for-input char) char)))) + (kill-region (point) (progn + (search-forward (char-to-string char) nil nil arg) + (if (>= arg 0) + (backward-char) + (forward-char)) + (point)))) + :bind (:map global-map + ("M-z" . zap-up-to-char))) #+end_src * Selection and search methods ** Completion frameworks -- cgit v1.2.3