forked from redguardtoo/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-writting.el
48 lines (43 loc) · 1.53 KB
/
init-writting.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;; @see http://endlessparentheses.com/super-smart-capitalization.html
(defun endless/convert-punctuation (rg rp)
"Look for regexp RG around point, and replace with RP.
Only applies to text-mode."
(let ((f "\\(%s\\)\\(%s\\)")
(space "?:[[:blank:]\n\r]*"))
;; We obviously don't want to do this in prog-mode.
(if (and (derived-mode-p 'text-mode)
(or (looking-at (format f space rg))
(looking-back (format f rg space))))
(replace-match rp nil nil nil 1))))
(defun endless/capitalize ()
"Capitalize region or word.
Also converts commas to full stops, and kills
extraneous space at beginning of line."
(interactive)
(endless/convert-punctuation "," ".")
(if (use-region-p)
(call-interactively 'capitalize-region)
;; A single space at the start of a line:
(when (looking-at "^\\s-\\b")
;; get rid of it!
(delete-char 1))
(call-interactively 'subword-capitalize)))
(defun endless/downcase ()
"Downcase region or word.
Also converts full stops to commas."
(interactive)
(endless/convert-punctuation "\\." ",")
(if (use-region-p)
(call-interactively 'downcase-region)
(call-interactively 'subword-downcase)))
(defun endless/upcase ()
"Upcase region or word."
(interactive)
(if (use-region-p)
(call-interactively 'upcase-region)
(call-interactively 'subword-upcase)))
;; these bindings are fine
(global-set-key "\M-c" 'endless/capitalize)
(global-set-key "\M-l" 'endless/downcase)
(global-set-key "\M-u" 'endless/upcase)
(provide 'init-writting)