;;; 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