Created
June 4, 2014 20:14
-
-
Save Philonous/16ace93247515c3d29a8 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 underscore-to-camelcase () | |
| "Convert underscores to camelCase" | |
| (interactive) | |
| (destructuring-bind (beg . end) (bounds-of-thing-at-point 'word) | |
| (goto-char beg) | |
| (while (re-search-forward "_\\([a-z]\\)" end t) | |
| (replace-match (upcase (match-string 1)))))) | |
| (defun camelcase-to-underscore () | |
| "Convert underscores to camelCase" | |
| (interactive) | |
| (let ((case-fold-search nil)) | |
| (destructuring-bind (beg . end) (bounds-of-thing-at-point 'word) | |
| (goto-char beg) | |
| (while (re-search-forward "\\([a-z0-9]\\)\\([A-Z]\\)" end t) | |
| (replace-match (concat (match-string-no-properties 1) | |
| "_" | |
| (downcase (match-string-no-properties 2)))))))) | |
| (defun swap-underscore-camelcase () | |
| "convert udnerscores to camelCase if word contains underscores | |
| and the other way around otherwise" | |
| (interactive) | |
| (save-excursion | |
| (destructuring-bind (beg . end) (bounds-of-thing-at-point 'word) | |
| (goto-char beg) | |
| (cond | |
| ((save-excursion (re-search-forward "_" end t)) | |
| (underscore-to-camelcase)) | |
| (t (camelcase-to-underscore)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment