diff options
author | Case Duckworth | 2022-04-24 15:00:11 -0500 |
---|---|---|
committer | Case Duckworth | 2022-04-24 15:00:11 -0500 |
commit | 56b2c9fb541d7d538cc955ae93409710bd325e0f (patch) | |
tree | 251f03b85dac22bdd5634d956826c7e069a36b41 | |
parent | Merge branch 'main' of tildegit.org:acdw/emacs (diff) | |
download | emacs-56b2c9fb541d7d538cc955ae93409710bd325e0f.tar.gz emacs-56b2c9fb541d7d538cc955ae93409710bd325e0f.zip |
Correct backward-kill-word behavior
-rw-r--r-- | init.el | 4 | ||||
-rw-r--r-- | lisp/+emacs.el | 28 | ||||
-rw-r--r-- | lisp/+paredit.el | 26 |
3 files changed, 57 insertions, 1 deletions
diff --git a/init.el b/init.el index 4e353df..46f0071 100644 --- a/init.el +++ b/init.el | |||
@@ -41,6 +41,7 @@ | |||
41 | "C-x C-o" #'+open-paragraph | 41 | "C-x C-o" #'+open-paragraph |
42 | "C-w" #'+kill-word-backward-or-region | 42 | "C-w" #'+kill-word-backward-or-region |
43 | "C-x C-m" #'execute-extended-command ; original: coding systems | 43 | "C-x C-m" #'execute-extended-command ; original: coding systems |
44 | "C-<backspace>" #'+backward-kill-word | ||
44 | ;; Alright, Yegge... NOPE! C-x t is tab prefix ... (maybe F6 or something?) | 45 | ;; Alright, Yegge... NOPE! C-x t is tab prefix ... (maybe F6 or something?) |
45 | ;; "C-x t" #'beginning-of-buffer | 46 | ;; "C-x t" #'beginning-of-buffer |
46 | ;; "C-x e" #'end-of-buffer | 47 | ;; "C-x e" #'end-of-buffer |
@@ -2028,8 +2029,9 @@ See also `crux-reopen-as-root-mode'." | |||
2028 | (add-hook '+init-mode-hook #'flymake-mode-off)) | 2029 | (add-hook '+init-mode-hook #'flymake-mode-off)) |
2029 | 2030 | ||
2030 | (setup (:straight paredit) | 2031 | (setup (:straight paredit) |
2032 | (:also-load +paredit) | ||
2031 | (:bind "DEL" #'paredit-backward-delete | 2033 | (:bind "DEL" #'paredit-backward-delete |
2032 | "C-<backspace>" #'paredit-backward-kill-word | 2034 | "C-<backspace>" #'+paredit-backward-kill-word |
2033 | "C-w" (lambda (arg) (interactive "P") | 2035 | "C-w" (lambda (arg) (interactive "P") |
2034 | (+kill-word-backward-or-region arg | 2036 | (+kill-word-backward-or-region arg |
2035 | #'paredit-backward-kill-word)) | 2037 | #'paredit-backward-kill-word)) |
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. |
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'. | ||
17 | Wrapped in `+backward-kill-word-wrapper', which see. | ||
18 | |||
19 | Prefix 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 | ||