diff options
Diffstat (limited to 'lisp/scule.el')
-rw-r--r-- | lisp/scule.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lisp/scule.el b/lisp/scule.el new file mode 100644 index 0000000..3ed58bb --- /dev/null +++ b/lisp/scule.el | |||
@@ -0,0 +1,61 @@ | |||
1 | ;;; scule.el --- -scule twiddling -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;; Copyright (C) 2022 Case Duckworth | ||
4 | |||
5 | ;; Author: Case Duckworth <case@bob> | ||
6 | ;; Keywords: convenience | ||
7 | |||
8 | ;; This program is free software; you can redistribute it and/or modify | ||
9 | ;; it under the terms of the GNU General Public License as published by | ||
10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
11 | ;; (at your option) any later version. | ||
12 | |||
13 | ;; This program is distributed in the hope that it will be useful, | ||
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | ;; GNU General Public License for more details. | ||
17 | |||
18 | ;; You should have received a copy of the GNU General Public License | ||
19 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
20 | |||
21 | ;;; Commentary: | ||
22 | |||
23 | ;; DWIM functions for twiddling "scule", or text case (a fancy word for "upper | ||
24 | ;; case" is "magiscule", for example, and "lower case" is "miniscule"). | ||
25 | |||
26 | ;;; Code: | ||
27 | |||
28 | (require 'thingatpt) | ||
29 | |||
30 | ;;; Utility macro | ||
31 | ;;;###autoload | ||
32 | (defmacro defscule (name &optional region-fn word-fn) | ||
33 | (let ((fn-name (intern (format "scule-%s" name))) | ||
34 | (region-fn (or region-fn (intern (format "%s-region" name)))) | ||
35 | (word-fn (or word-fn (intern (format "%s-word" name))))) | ||
36 | `(defun ,fn-name (arg) | ||
37 | ,(concat (capitalize (symbol-name name)) " words in the region if active, or word at point.\n" | ||
38 | "If the region is active, call `" (symbol-name region-fn) "'.\n" | ||
39 | "Otherwise, it calls `" (symbol-name word-fn) "' on the word at point and\n" | ||
40 | "the following ARG - 1 words.") | ||
41 | (interactive "*p") | ||
42 | (if (use-region-p) | ||
43 | (,region-fn (region-beginning) (region-end) (region-noncontiguous-p)) | ||
44 | (let ((word-bound (save-excursion | ||
45 | (skip-chars-forward "^[:word:]") | ||
46 | (bounds-of-thing-at-point 'word)))) | ||
47 | (when (and (car word-bound) (cdr word-bound)) | ||
48 | (,region-fn (car word-bound) (cdr word-bound)) | ||
49 | (goto-char (cdr word-bound)) | ||
50 | (,word-fn (1- arg)))))))) | ||
51 | |||
52 | ;;;###autoload | ||
53 | (progn (defscule upcase) | ||
54 | (autoload 'scule-upcase "scule" nil t) | ||
55 | (defscule downcase) | ||
56 | (autoload 'scule-downcase "scule" nil t) | ||
57 | (defscule capitalize) | ||
58 | (autoload 'scule-capitalize "scule" nil t)) | ||
59 | |||
60 | (provide 'scule) | ||
61 | ;;; scule.el ends here | ||