diff options
Diffstat (limited to 'lisp/+emacs.el')
-rw-r--r-- | lisp/+emacs.el | 28 |
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. | ||
249 | If point is on at the beginning of a line, kill the previous new | ||
250 | line. If the only thing before point on the current line is | ||
251 | whitespace, kill that whitespace. | ||
252 | |||
253 | With argument ARG: if ARG is a number, just call FN | ||
254 | ARG 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'. | ||
271 | ARG 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. |