diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+casing.el | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lisp/+casing.el b/lisp/+casing.el new file mode 100644 index 0000000..bcab7fa --- /dev/null +++ b/lisp/+casing.el | |||
@@ -0,0 +1,62 @@ | |||
1 | ;;; +casing.el --- Word-case-twiddling things -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (require 'thingatpt) | ||
6 | |||
7 | (defvar +casing-map (let ((map (make-sparse-keymap))) | ||
8 | (define-key map "u" #'+upcase-dwim) | ||
9 | (define-key map "l" #'+downcase-dwim) | ||
10 | (define-key map "c" #'+capitalize-dwim) | ||
11 | map) | ||
12 | "Keymap for word-casing.") | ||
13 | |||
14 | ;;;###autoload | ||
15 | (defun +upcase-dwim (arg) | ||
16 | "Upcase words in the region, or upcase word at point. | ||
17 | If the region is active, this function calls `upcase-region'. | ||
18 | Otherwise, it calls `upcase-word' on the word at point (using | ||
19 | `thingatpt'), and the following ARG - 1 words." | ||
20 | (interactive "*p") | ||
21 | (if (use-region-p) | ||
22 | (upcase-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
23 | (let ((following (1- arg)) | ||
24 | (word-bound (bounds-of-thing-at-point 'word))) | ||
25 | (upcase-region (car word-bound) (cdr word-bound)) | ||
26 | (goto-char (cdr word-bound)) | ||
27 | (upcase-word following)))) | ||
28 | |||
29 | ;;;###autoload | ||
30 | (defun +downcase-dwim (arg) | ||
31 | "Downcase words in the region, or downcase word at point. | ||
32 | If the region is active, this function calls `downcase-region'. | ||
33 | Otherwise, it calls `downcase-word' on the word at point (using | ||
34 | `thingatpt'), and the following ARG - 1 words." | ||
35 | (interactive "*p") | ||
36 | (if (use-region-p) | ||
37 | (downcase-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
38 | (let ((following (1- arg)) | ||
39 | (word-bound (bounds-of-thing-at-point 'word))) | ||
40 | (downcase-region (car word-bound) (cdr word-bound)) | ||
41 | (goto-char (cdr word-bound)) | ||
42 | (downcase-word following)))) | ||
43 | |||
44 | ;;;###autoload | ||
45 | (defun +capitalize-dwim (arg) | ||
46 | "Capitalize words in the region, or capitalize word at point. | ||
47 | If the region is active, this function calls `capitalize-region'. | ||
48 | Otherwise, it calls `capitalize-word' on the word at point (using | ||
49 | `thingatpt'), and the following ARG - 1 words." | ||
50 | (interactive "*p") | ||
51 | (if (use-region-p) | ||
52 | (capitalize-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
53 | (let ((following (1- arg)) | ||
54 | (word-bound (bounds-of-thing-at-point 'word))) | ||
55 | (capitalize-region (car word-bound) (cdr word-bound)) | ||
56 | (goto-char (cdr word-bound)) | ||
57 | (capitalize-word following)))) | ||
58 | |||
59 | ;; Later on, I'll add repeat maps and stuff in here... | ||
60 | |||
61 | (provide '+casing) | ||
62 | ;;; +casing.el ends here | ||