aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason2017-06-30 18:42:24 -0600
committerjason2017-06-30 18:46:07 -0600
commitbfb30ab9ff71bc63d95c4eabbf9add6dd42cb460 (patch)
treee01d336967132199498858390b6470eaf7b88240
parentd471ae48795673ed03f35d3b50b4eb4082457c79 (diff)
downloaddotemacs-bfb30ab9ff71bc63d95c4eabbf9add6dd42cb460.tar.gz
dotemacs-bfb30ab9ff71bc63d95c4eabbf9add6dd42cb460.zip
Treat whitespace as a word when removing by word
-rw-r--r--config.org11
-rw-r--r--local-lib/zzq-funcs.el37
2 files changed, 48 insertions, 0 deletions
diff --git a/config.org b/config.org
index f658ab9..de3dc0b 100644
--- a/config.org
+++ b/config.org
@@ -138,6 +138,17 @@ to it.
138;; Use ibuffer for the buffer list 138;; Use ibuffer for the buffer list
139(global-set-key (kbd "C-x C-b") 'ibuffer) 139(global-set-key (kbd "C-x C-b") 'ibuffer)
140#+END_SRC 140#+END_SRC
141
142I want to treat whitespace as a word when removing words because I end
143up reformatting new lines and indents a lot (python doc strings).
144
145#+BEGIN_SRC emacs-lisp
146(global-set-key (kbd "<C-backspace>") 'maybe-backward-kill-word)
147(global-set-key (kbd "<M-delete>") 'maybe-backward-kill-word)
148(global-set-key (kbd "M-d") 'maybe-kill-word)
149(global-set-key (kbd "<C-delete>") 'maybe-kill-word)
150#+END_SRC
151
141* Package Initalization 152* Package Initalization
142Define the package repositories 153Define the package repositories
143 154
diff --git a/local-lib/zzq-funcs.el b/local-lib/zzq-funcs.el
index 3d38b11..c1bb4a9 100644
--- a/local-lib/zzq-funcs.el
+++ b/local-lib/zzq-funcs.el
@@ -14,4 +14,41 @@
14 "Convert the output of (current-time) to epoch in milliseconds" 14 "Convert the output of (current-time) to epoch in milliseconds"
15 (truncate (* 1000 (+ (+ (* (nth 0 time) (expt 2 16)) (nth 1 time)) (* (nth 2 time) (expt 10 -6)))))) 15 (truncate (* 1000 (+ (+ (* (nth 0 time) (expt 2 16)) (nth 1 time)) (* (nth 2 time) (expt 10 -6))))))
16 16
17(defun kill-whitespace ()
18 "Remove all whitepspace seperating two non-whitespace characters"
19 (interactive "*")
20 (save-excursion
21 (save-restriction
22 (progn
23 ;; Move backward to the last non-whitespace character
24 (re-search-backward "[^ \t\r\n]" nil)
25 ;; Then search for all whitespace to the next non-whitespace character
26 (re-search-forward "[ \t\r\n]+")
27 ;; Replace everything from the last match (all whitespace) with nothing
28 (replace-match "")))))
29
30(defun maybe-backward-kill-word (arg)
31 "Removes all whitespace backward up to the next non-whitespace character. If
32the first character left of the cursor is not whitespace then remove the word. I
33like to bind this to C-backspace."
34 (interactive "p")
35 (if (looking-back "[ \t\r\n]")
36 (let ((start (point)))
37 (re-search-backward "[^ \t\r\n]" nil)
38 (forward-char 1)
39 (delete-region (point) start))
40 (backward-kill-word arg)))
41
42(defun maybe-kill-word (arg)
43 "Removes all whitespace up to the next non-whitespace character. If the first
44character right of the cursor is not whitespace then remove the word. I like to
45bind this to C-delete and M-d"
46 (interactive "p")
47 (if (looking-at "[ \t\r\n]")
48 (let ((start (point)))
49 (re-search-forward "[\t\r\n]+" nil)
50 (delete-region (point) start))
51 (kill-word arg)))
52
53
17(provide 'zzq-funcs) 54(provide 'zzq-funcs)