From 4cf60c3fea16b60eb18c9a7d8403b75c89aeffef Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 21 Oct 2022 21:37:30 -0500 Subject: blhe --- lisp/scule.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lisp/scule.el (limited to 'lisp/scule.el') diff --git a/lisp/scule.el b/lisp/scule.el new file mode 100644 index 0000000..3ed58bb --- /dev/null +++ b/lisp/scule.el @@ -0,0 +1,61 @@ +;;; 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 -- cgit 1.4.1-21-gabe81