Created
December 23, 2014 17:54
-
-
Save abo-abo/29f581cac2f615fd709d to your computer and use it in GitHub Desktop.
Emacs word toggles
This file contains hidden or 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
;;;###autoload | |
(defun capitalize-word-toggle () | |
(interactive) | |
(let ((start (car | |
(save-excursion | |
(backward-word) | |
(bounds-of-thing-at-point 'symbol))))) | |
(if start | |
(save-excursion | |
(goto-char start) | |
(funcall | |
(if (char-upcasep (char-after)) | |
'downcase-region | |
'upcase-region) | |
start (1+ start))) | |
(capitalize-word -1)))) | |
;;;###autoload | |
(defun upcase-word-toggle () | |
(interactive) | |
(let ((bounds (bounds-of-thing-at-point 'symbol)) | |
beg end | |
regionp) | |
(if (eq this-command last-command) | |
(setq regionp (get this-command 'regionp)) | |
(put this-command 'regionp nil)) | |
(cond | |
((or (region-active-p) regionp) | |
(setq beg (region-beginning) | |
end (region-end)) | |
(put this-command 'regionp t)) | |
(bounds | |
(setq beg (car bounds) | |
end (cdr bounds))) | |
(t | |
(setq beg (point) | |
end (1+ beg)))) | |
(save-excursion | |
(goto-char (1- beg)) | |
(and (re-search-forward "[A-Za-z]" end t) | |
(funcall (if (char-upcasep (char-before)) | |
'downcase-region | |
'upcase-region) | |
beg end))))) | |
(defun char-upcasep (letter) | |
(eq letter (upcase letter))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment