summary refs log tree commit diff stats
path: root/lisp/+emacs.el
diff options
context:
space:
mode:
authorCase Duckworth2022-04-24 15:00:11 -0500
committerCase Duckworth2022-04-24 15:00:11 -0500
commit56b2c9fb541d7d538cc955ae93409710bd325e0f (patch)
tree251f03b85dac22bdd5634d956826c7e069a36b41 /lisp/+emacs.el
parentMerge branch 'main' of tildegit.org:acdw/emacs (diff)
downloademacs-56b2c9fb541d7d538cc955ae93409710bd325e0f.tar.gz
emacs-56b2c9fb541d7d538cc955ae93409710bd325e0f.zip
Correct backward-kill-word behavior
Diffstat (limited to 'lisp/+emacs.el')
-rw-r--r--lisp/+emacs.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/lisp/+emacs.el b/lisp/+emacs.el index b7e31e2..a0627cf 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el
@@ -244,6 +244,34 @@ backward. It defaults to `backward-kill-word'."
244 #'kill-region 244 #'kill-region
245 (or backward-kill-word-fn #'backward-kill-word)))) 245 (or backward-kill-word-fn #'backward-kill-word))))
246 246
247(defun +backward-kill-word-wrapper (fn &optional arg)
248 "Kill backward using FN until the beginning of a word, smartly.
249If point is on at the beginning of a line, kill the previous new
250line. If the only thing before point on the current line is
251whitespace, kill that whitespace.
252
253With argument ARG: if ARG is a number, just call FN
254ARG times. Otherwise, just call FN."
255 ;; I want this to be a wrapper so that I can call other word-killing functions
256 ;; with it. It's *NOT* advice because those functions probably use
257 ;; `backward-kill-word' under the hood (looking at you, paredit), so advice
258 ;; will make things weird.
259 (if (null arg)
260 (cond
261 ((looking-back "^" 1)
262 (let ((delete-active-region nil))
263 (delete-backward-char 1)))
264 ((looking-back "^[ ]*")
265 (delete-horizontal-space :backward-only))
266 (t (call-interactively fn)))
267 (funcall fn (if (listp arg) 1 arg))))
268
269(defun +backward-kill-word (&optional arg)
270 "Kill word backward using `backward-kill-word'.
271ARG is passed to `backward-kill-word'."
272 (interactive "P")
273 (+backward-kill-word-wrapper #'backward-kill-word arg))
274
247;; ... and advice 275;; ... and advice
248 276
249;; Indent the region after a yank. 277;; Indent the region after a yank.