summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+emacs.el28
-rw-r--r--lisp/+paredit.el26
2 files changed, 54 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.
diff --git a/lisp/+paredit.el b/lisp/+paredit.el new file mode 100644 index 0000000..0c65328 --- /dev/null +++ b/lisp/+paredit.el
@@ -0,0 +1,26 @@
1;;; +paredit.el --- bespoke paredit stuffs -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;;; Code:
6
7(require '+emacs) ; `+backward-kill-word-wrapper'
8
9(defun +paredit--backward-kill-word (&optional n)
10 "Perform `paredit-backward-kill-word' N times."
11 (interactive "p")
12 (dotimes (_ (or n 1))
13 (paredit-backward-kill-word)))
14
15(defun +paredit-backward-kill-word (&optional arg)
16 "Kill a word backward using `paredit-backward-kill-word'.
17Wrapped in `+backward-kill-word-wrapper', which see.
18
19Prefix ARG means to just call `paredit-backward-kill-word'."
20 ;; Of course, `paredit-backward-kill-word' doesn't TAKE an argument ... :///
21 ;; So I had to write the wrapper above.
22 (interactive)
23 (+backward-kill-word-wrapper #'+paredit--backward-kill-word arg))
24
25(provide '+paredit)
26;;; +paredit.el ends here