Converting from camelcase to _ in emacs

前端 未结 7 1979

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

longVariableName

M-x to-underscore

7条回答
  •  时光取名叫无心
    2021-02-05 03:41

    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:

    1. whatever case to snake case(underscore seperated):

      (s-snake-case "some words") ;; => "some_words"
      (s-snake-case "dashed-words") ;; => "dashed_words"
      (s-snake-case "camelCasedWords") ;; => "camel_cased_words"
      
    2. whatever case to lower camel case:

      (s-lower-camel-case "some words") ;; => "someWords"
      (s-lower-camel-case "dashed-words") ;; => "dashedWords"
      (s-lower-camel-case "under_scored_words") ;; => "underScoredWords"
      

    see more examples at its repo.

提交回复
热议问题