From 620a06e41bb04eb7633c867e67d94042a20d013b Mon Sep 17 00:00:00 2001 From: 45mg <45mm.cartridge421@slmail.me> Date: Sat, 12 Oct 2024 06:54:09 +0000 Subject: [PATCH] Add `meow(-backward)-kill-{word,symbol}` (#644) * add: meow(-backward)-kill-word Versions of `kill-word` and `backward-kill-word` that respect `meow-word-thing`. * revise: meow-(backward-)kill-{word,symbol} We should have commands for both `meow-word-thing` and `meow-symbol-thing`. --------- Co-authored-by: 45mg <45mg@no.mail> --- COMMANDS.org | 6 ++++++ CUSTOMIZATIONS.org | 5 +++++ meow-command.el | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/COMMANDS.org b/COMMANDS.org index 3edf31f6..d485fdd5 100644 --- a/COMMANDS.org +++ b/COMMANDS.org @@ -195,6 +195,12 @@ Call the command on ~C-k~. Call the command on ~C-d~. +*** meow-kill-word, meow-backward-kill-word, meow-kill-symbol, meow-backward-kill-symbol + +Versions of ~kill-word~ and ~backward-kill-word~ that respect ~meow-word-thing~ +and ~meow-symbol-thing~. May be bound to M-d and M-DEL in place of ~kill-word~ +and ~backward-kill-word~. + *** meow-save Copy. diff --git a/CUSTOMIZATIONS.org b/CUSTOMIZATIONS.org index 3c5918e4..f0c089ef 100644 --- a/CUSTOMIZATIONS.org +++ b/CUSTOMIZATIONS.org @@ -183,6 +183,7 @@ Default: ='((?c . ?c) (?h . ?h) (?x . ?x))= Alist of keys to begin keypad translation. For instance, given the default value, pressing "c" in keypad mode will look up it's value in the alist, and add "C-c" to the keypad. + ** meow-keypad-self-insert-undefined Default: =t= @@ -225,6 +226,7 @@ Default: #+end_src A association list of state symbols to strings describing the state. + ** meow-indicator-face-alist Default: @@ -410,3 +412,6 @@ to Vim's - (setq meow-word-thing 'vimlike-word) #+end_src + +Meow also provides ~meow-kill-word~ and ~meow-backward-kill-word~, versions of +~kill-word~ and ~backward-kill-word~ that respect ~meow-word-thing~. diff --git a/meow-command.el b/meow-command.el index 919ad4ce..38f039b6 100644 --- a/meow-command.el +++ b/meow-command.el @@ -299,6 +299,43 @@ This command supports `meow-selection-command-fallback'." (interactive) (meow--execute-kbd-macro meow--kbd-delete-char)) +(defun meow-backward-kill-word (arg) + "Kill characters backward until the beginning of a `meow-word-thing'. +With argument ARG, do this that many times." + (interactive "p") + (meow-kill-word (- arg))) + +(defun meow-kill-word (arg) + "Kill characters forward until the end of a `meow-word-thing'. +With argument ARG, do this that many times." + (interactive "p") + (meow-kill-thing meow-word-thing arg)) + +(defun meow-backward-kill-symbol (arg) + "Kill characters backward until the beginning of a `meow-symbol-thing'. +With argument ARG, do this that many times." + (interactive "p") + (meow-kill-symbol (- arg))) + +(defun meow-kill-symbol (arg) + "Kill characters forward until the end of a `meow-symbol-thing'. +With argument ARG, do this that many times." + (interactive "p") + (meow-kill-thing meow-symbol-thing arg)) + + +(defun meow-kill-thing (thing arg) + "Kill characters forward until the end of a THING. +With argument ARG, do this that many times." + (let ((start (point)) + (end (progn (forward-thing thing arg) (point)))) + (condition-case _ + (kill-region start end) + ((text-read-only buffer-read-only) + (condition-case err + (meow--delete-region start end) + (t (signal (car err) (cdr err)))))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; PAGE UP&DOWN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;