Converting from camelcase to _ in emacs

camelcasing, elisp, emacs

Is there an emacs function to convert a camel-cased word to underscore? Something, like:

longVariableName

M-x to-underscore

long_variable_name

Best Solution

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 :

;; Cycle between snake case, camel case, etc.(require 'string-inflection)(global-set-key (kbd "C-c i") 'string-inflection-cycle)(global-set-key (kbd "C-c C") 'string-inflection-camelcase)        ;; Force to CamelCase(global-set-key (kbd "C-c L") 'string-inflection-lower-camelcase)  ;; Force to lowerCamelCase(global-set-key (kbd "C-c J") 'string-inflection-java-style-cycle) ;; Cycle through Java styles