Created
April 29, 2014 14:17
-
-
Save til/11401729 to your computer and use it in GitHub Desktop.
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
(defun downcase-word-with-camelcase () | |
"This works similar to downcase-word, but additionally inserts | |
an underscore before upper case chars within camel cased words, so that: | |
FooBar => foo_bar" | |
(interactive) | |
(progn | |
(if (looking-at-p "\\>") (search-forward-regexp "\\<")) | |
(let ((start (point))) | |
(search-forward-regexp "\\>") | |
(let ((end (point))) | |
(let ((word (buffer-substring start end))) | |
(delete-region start end) | |
(insert | |
(downcase (let ((case-fold-search nil)) | |
(replace-regexp-in-string "\\([a-z]\\)\\([A-Z]\\)" "\\1_\\2" word)))) | |
))))) | |
(global-set-key (kbd "M-l") 'downcase-word-with-camelcase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment