Is there an emacs function to convert a camel-cased word to underscore? Something, like:
longVariableName
M-x
to-underscore
I use this when converting C# code to PHP.
(defun un-camelcase-word-at-point ()
"un-camelcase the word at point, replacing uppercase chars with
the lowercase version preceded by an underscore.
The first char, if capitalized (eg, PascalCase) is just
downcased, no preceding underscore.
"
(interactive)
(save-excursion
(let ((bounds (bounds-of-thing-at-point 'word)))
(replace-regexp "\\([A-Z]\\)" "_\\1" nil
(1+ (car bounds)) (cdr bounds))
(downcase-region (car bounds) (cdr bounds)))))
And then in my php-mode fn:
(local-set-key "\M-\C-C" 'un-camelcase-word-at-point)