From be93fbccf5509920732120888d30d0675ab0f161 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Jan 2022 14:39:54 -0600 Subject: Add +casing --- init.el | 6 ++++++ lisp/+casing.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 lisp/+casing.el diff --git a/init.el b/init.el index bb6006d..f15bf31 100644 --- a/init.el +++ b/init.el @@ -23,6 +23,12 @@ (setq debug-on-error (memq system-type '(msdos windows-nt))) +(setup (:require +casing) + (define-key +key-mode-map (kbd "C-c c") +casing-map) + ;; Unbind default casing bindings + (:global "M-u" nil "M-c" nil "M-l" nil + "C-x C-u" nil "C-x C-l" nil)) + (setup (:require +emacs) ;; +emacs.el contains super-basic defaults that are basically necessary for ;; good functioning. In this block, I add extra things or more "experimental" diff --git a/lisp/+casing.el b/lisp/+casing.el new file mode 100644 index 0000000..bcab7fa --- /dev/null +++ b/lisp/+casing.el @@ -0,0 +1,62 @@ +;;; +casing.el --- Word-case-twiddling things -*- lexical-binding: t; -*- + +;;; Code: + +(require 'thingatpt) + +(defvar +casing-map (let ((map (make-sparse-keymap))) + (define-key map "u" #'+upcase-dwim) + (define-key map "l" #'+downcase-dwim) + (define-key map "c" #'+capitalize-dwim) + map) + "Keymap for word-casing.") + +;;;###autoload +(defun +upcase-dwim (arg) + "Upcase words in the region, or upcase word at point. +If the region is active, this function calls `upcase-region'. +Otherwise, it calls `upcase-word' on the word at point (using +`thingatpt'), and the following ARG - 1 words." + (interactive "*p") + (if (use-region-p) + (upcase-region (region-beginning) (region-end) (region-noncontiguous-p)) + (let ((following (1- arg)) + (word-bound (bounds-of-thing-at-point 'word))) + (upcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (upcase-word following)))) + +;;;###autoload +(defun +downcase-dwim (arg) + "Downcase words in the region, or downcase word at point. +If the region is active, this function calls `downcase-region'. +Otherwise, it calls `downcase-word' on the word at point (using +`thingatpt'), and the following ARG - 1 words." + (interactive "*p") + (if (use-region-p) + (downcase-region (region-beginning) (region-end) (region-noncontiguous-p)) + (let ((following (1- arg)) + (word-bound (bounds-of-thing-at-point 'word))) + (downcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (downcase-word following)))) + +;;;###autoload +(defun +capitalize-dwim (arg) + "Capitalize words in the region, or capitalize word at point. +If the region is active, this function calls `capitalize-region'. +Otherwise, it calls `capitalize-word' on the word at point (using +`thingatpt'), and the following ARG - 1 words." + (interactive "*p") + (if (use-region-p) + (capitalize-region (region-beginning) (region-end) (region-noncontiguous-p)) + (let ((following (1- arg)) + (word-bound (bounds-of-thing-at-point 'word))) + (capitalize-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (capitalize-word following)))) + +;; Later on, I'll add repeat maps and stuff in here... + +(provide '+casing) +;;; +casing.el ends here -- cgit 1.4.1-21-gabe81