about summary refs log tree commit diff stats
path: root/lisp/acdw-compat.el
blob: b77527caf6f3aada7486040e99a6509104bbe261 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;;; acdw-compat.el -*- lexical-binding: t; coding: utf-8-unix -*-

;; Author: Case Duckworth <acdw@acdw.net>
;; Created: 2021-08-11
;; Keywords: configuration
;; URL: https://tildegit.org/acdw/emacs

;; This file is NOT part of GNU Emacs.

;;; License:
;; Everyone is permitted to do whatever with this software, without
;; limitation.  This software comes without any warranty whatsoever,
;; but with two pieces of advice:
;; - Don't hurt yourself.
;; - Make good choices.

;;; Commentary:

;; This file contains functions, variables, and other code that might not be in
;; every version of Emacs I use.

;;; Code:

;; Convenience macro
(defmacro safe-defun (name arglist &optional docstring &rest body)
  "Like `defun', but only if the function doesn't already exist.

Is it necessary?  Who knows!

\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
  (declare (doc-string 3)
           (indent 2))
  `(unless (fboundp (function ,name))
     (defun ,name ,@body)))


;;; Functions for changing capitalization that Do What I Mean
;; Defined in /usr/share/emacs/28.0.50/lisp/simple.el

(safe-defun upcase-dwim (arg)
  "Upcase words in the region, if active; if not, upcase word at point.
If the region is active, this function calls `upcase-region'.
Otherwise, it calls `upcase-word', with prefix argument passed to it
to upcase ARG words."
  (interactive "*p")
  (if (use-region-p)
      (upcase-region (region-beginning) (region-end) (region-noncontiguous-p))
    (upcase-word arg)))

(safe-defun downcase-dwim (arg)
  "Downcase words in the region, if active; if not, downcase word at point.
If the region is active, this function calls `downcase-region'.
Otherwise, it calls `downcase-word', with prefix argument passed to it
to downcase ARG words."
  (interactive "*p")
  (if (use-region-p)
      (downcase-region (region-beginning) (region-end) (region-noncontiguous-p))
    (downcase-word arg)))

(safe-defun capitalize-dwim (arg)
  "Capitalize words in the region, if active; if not, capitalize word at point.
If the region is active, this function calls `capitalize-region'.
Otherwise, it calls `capitalize-word', with prefix argument passed to it
to capitalize ARG words."
  (interactive "*p")
  (if (use-region-p)
      (capitalize-region (region-beginning) (region-end) (region-noncontiguous-p))
    (capitalize-word arg)))

(provide 'acdw-compat)
;;; acdw-compat.el ends here