From 9e46efac61fc4246b810c8b19127248ed7b3080e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jan 2022 17:12:32 -0600 Subject: Lots of changes, maybe breaking something I have to do a big debugging tonight. Keybinds aren't getting picked up, idk what's going on. --- lisp/+casing.el | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'lisp/+casing.el') diff --git a/lisp/+casing.el b/lisp/+casing.el index fe97310..a21e710 100644 --- a/lisp/+casing.el +++ b/lisp/+casing.el @@ -3,17 +3,7 @@ ;;; Code: (require 'thingatpt) - -(defvar +casing-map (make-sparse-keymap) - "Keymap for word-casing.") - -(let ((map +casing-map)) - (define-key map "u" #'+upcase-dwim) - (define-key map (kbd "M-u") #'+upcase-dwim) - (define-key map "l" #'+downcase-dwim) - (define-key map (kbd "M-l") #'+downcase-dwim) - (define-key map "c" #'+capitalize-dwim) - (define-key map (kbd "M-c") #'+capitalize-dwim)) +(require '+key) ;;;###autoload (defun +upcase-dwim (arg) @@ -28,9 +18,10 @@ Otherwise, it calls `upcase-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (upcase-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (upcase-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (upcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (upcase-word following))))) ;;;###autoload (defun +downcase-dwim (arg) @@ -45,9 +36,10 @@ Otherwise, it calls `downcase-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (downcase-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (downcase-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (downcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (downcase-word following))))) ;;;###autoload (defun +capitalize-dwim (arg) @@ -62,11 +54,26 @@ Otherwise, it calls `capitalize-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (capitalize-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (capitalize-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (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... +(define-minor-mode +casing-mode + "Enable easy case-twiddling commands." + :lighter " cC" + :keymap (let ((map (make-sparse-keymap))) + (define-key map "u" #'+upcase-dwim) + (define-key map (kbd "M-u") #'+upcase-dwim) + (define-key map "l" #'+downcase-dwim) + (define-key map (kbd "M-l") #'+downcase-dwim) + (define-key map "c" #'+capitalize-dwim) + (define-key map (kbd "M-c") #'+capitalize-dwim) + map) + (define-key +key-mode-map (kbd "M-c") (when +casing-mode + +casing-mode-map))) + (provide '+casing) ;;; +casing.el ends here -- cgit 1.4.1-21-gabe81