summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-compat.el71
1 files changed, 71 insertions, 0 deletions
diff --git a/lisp/acdw-compat.el b/lisp/acdw-compat.el new file mode 100644 index 0000000..b77527c --- /dev/null +++ b/lisp/acdw-compat.el
@@ -0,0 +1,71 @@
1;;; acdw-compat.el -*- lexical-binding: t; coding: utf-8-unix -*-
2
3;; Author: Case Duckworth <acdw@acdw.net>
4;; Created: 2021-08-11
5;; Keywords: configuration
6;; URL: https://tildegit.org/acdw/emacs
7
8;; This file is NOT part of GNU Emacs.
9
10;;; License:
11;; Everyone is permitted to do whatever with this software, without
12;; limitation. This software comes without any warranty whatsoever,
13;; but with two pieces of advice:
14;; - Don't hurt yourself.
15;; - Make good choices.
16
17;;; Commentary:
18
19;; This file contains functions, variables, and other code that might not be in
20;; every version of Emacs I use.
21
22;;; Code:
23
24;; Convenience macro
25(defmacro safe-defun (name arglist &optional docstring &rest body)
26 "Like `defun', but only if the function doesn't already exist.
27
28Is it necessary? Who knows!
29
30\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
31 (declare (doc-string 3)
32 (indent 2))
33 `(unless (fboundp (function ,name))
34 (defun ,name ,@body)))
35
36
37;;; Functions for changing capitalization that Do What I Mean
38;; Defined in /usr/share/emacs/28.0.50/lisp/simple.el
39
40(safe-defun upcase-dwim (arg)
41 "Upcase words in the region, if active; if not, upcase word at point.
42If the region is active, this function calls `upcase-region'.
43Otherwise, it calls `upcase-word', with prefix argument passed to it
44to upcase ARG words."
45 (interactive "*p")
46 (if (use-region-p)
47 (upcase-region (region-beginning) (region-end) (region-noncontiguous-p))
48 (upcase-word arg)))
49
50(safe-defun downcase-dwim (arg)
51 "Downcase words in the region, if active; if not, downcase word at point.
52If the region is active, this function calls `downcase-region'.
53Otherwise, it calls `downcase-word', with prefix argument passed to it
54to downcase ARG words."
55 (interactive "*p")
56 (if (use-region-p)
57 (downcase-region (region-beginning) (region-end) (region-noncontiguous-p))
58 (downcase-word arg)))
59
60(safe-defun capitalize-dwim (arg)
61 "Capitalize words in the region, if active; if not, capitalize word at point.
62If the region is active, this function calls `capitalize-region'.
63Otherwise, it calls `capitalize-word', with prefix argument passed to it
64to capitalize ARG words."
65 (interactive "*p")
66 (if (use-region-p)
67 (capitalize-region (region-beginning) (region-end) (region-noncontiguous-p))
68 (capitalize-word arg)))
69
70(provide 'acdw-compat)
71;;; acdw-compat.el ends here