Is there an emacs function to convert a camel-cased word to underscore? Something, like:
longVariableName
M-x
to-underscore
long_variable_name
Is there an emacs function to convert a camel-cased word to underscore? Something, like:
longVariableName
M-x
to-underscore
long_variable_name
There is now another general way in 2018: magnars/s.el: The long lost Emacs string manipulation library. - github.com, some examples regarding OP's question:
whatever case to snake case(underscore seperated):
whatever case to lower camel case:
see more examples at its repo.
Use the string-inflection package, available on MELPA, or at https://github.com/akicho8/string-inflection.
Useful keyboard shortcuts, copied from https://www.emacswiki.org/emacs/CamelCase :
@ens' answer was close, but a little buggy for me on Emacs 26.1. I fixed the bug and added the ability, via C-u prefix arg, to specify if you want the first letter of camel case to be lower case:
I use this when converting C# code to PHP.
And then in my php-mode fn:
I use the following for toggling between camelcase and underscores:
If you want to get complete code using s.el: