例如,我想将“CamelCasedName”转换为“camel_cased_name”。有没有办法在 emacs 中做到这一点?
本页中的这一小段代码带有包装函数和下划线(用下划线替换连字符),可以轻松地将其转换为执行此操作的命令。(检查它是否处理适合您的前导大写):
用于取消驼峰命名法的字符串的示例 EmacsLisp 代码(来自http://www.friendsnippets.com/snippet/101/):
(defun un-camelcase-string (s &optional sep start)
"Convert CamelCase string S to lower case with word separator SEP.
Default for SEP is a hyphen \"-\".
If third argument START is non-nil, convert words after that
index in STRING."
(let ((case-fold-search nil))
(while (string-match "[A-Z]" s (or start 1))
(setq s (replace-match (concat (or sep "-")
(downcase (match-string 0 s)))
t nil s)))
(downcase s)))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1785 次 |
最近记录: |