Created
May 23, 2015 01:34
-
-
Save johnmastro/173c6718e603ca4d27ad to your computer and use it in GitHub Desktop.
cycle-case.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'pcase) | |
;; Based on Xah Lee's: http://ergoemacs.org/emacs/modernization_upcase-word.html | |
(defun cycle-case (beg end) | |
"Cycle the word case of the active region or word at point." | |
(interactive | |
(pcase-let ((`(,beg . ,end) (if (use-region-p) | |
(cons (region-beginning) (region-end)) | |
(bounds-of-thing-at-point 'word)))) | |
(list beg end))) | |
(let (deactivate-mark case-fold-search) | |
(unless (eq this-command last-command) | |
(save-excursion | |
(goto-char beg) | |
(put this-command 'state (cond ((looking-at "[[:upper:]][[:lower:]]") | |
'caps) | |
((looking-at "[[:upper:]]") | |
'upper) | |
(t | |
'lower))))) | |
(pcase (get this-command 'state) | |
(`lower (upcase-initials-region beg end) | |
(put this-command 'state 'caps)) | |
(`caps (upcase-region beg end) | |
(put this-command 'state 'upper)) | |
(_ (downcase-region beg end) | |
(put this-command 'state 'lower))))) | |
;; (global-set-key (kbd "M-C") #'cycle-case) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment