From d187b2b8cbf19ec387c800df37d2669a9d520448 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 11 Aug 2021 22:03:54 -0500 Subject: Add acdw-compat.el --- lisp/acdw-compat.el | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lisp/acdw-compat.el (limited to 'lisp') 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 @@ +;;; acdw-compat.el -*- lexical-binding: t; coding: utf-8-unix -*- + +;; Author: Case Duckworth +;; 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 -- cgit 1.4.1-21-gabe81