;;; scule.el --- -scule twiddling -*- lexical-binding: t; -*- ;; Copyright (C) 2022 Case Duckworth ;; Author: Case Duckworth ;; Keywords: convenience ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; DWIM functions for twiddling "scule", or text case (a fancy word for "upper ;; case" is "magiscule", for example, and "lower case" is "miniscule"). ;;; Code: (require 'thingatpt) ;;; Utility macro ;;;###autoload (defmacro defscule (name &optional region-fn word-fn) (let ((fn-name (intern (format "scule-%s" name))) (region-fn (or region-fn (intern (format "%s-region" name)))) (word-fn (or word-fn (intern (format "%s-word" name))))) `(defun ,fn-name (arg) ,(concat (capitalize (symbol-name name)) " words in the region if active, or word at point.\n" "If the region is active, call `" (symbol-name region-fn) "'.\n" "Otherwise, it calls `" (symbol-name word-fn) "' on the word at point and\n" "the following ARG - 1 words.") (interactive "*p") (if (use-region-p) (,region-fn (region-beginning) (region-end) (region-noncontiguous-p)) (let ((word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) (when (and (car word-bound) (cdr word-bound)) (,region-fn (car word-bound) (cdr word-bound)) (goto-char (cdr word-bound)) (,word-fn (1- arg)))))))) ;;;###autoload (progn (defscule upcase) (autoload 'scule-upcase "scule" nil t) (defscule downcase) (autoload 'scule-downcase "scule" nil t) (defscule capitalize) (autoload 'scule-capitalize "scule" nil t)) (provide 'scule) ;;; scule.el ends here