Remove the camel-to-snake-case function

string-inflection (soon to be added) already does this for me.
This commit is contained in:
Gergely Polonkai 2023-10-20 15:55:20 +02:00
parent f006617927
commit 2bc338371e
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -399,31 +399,6 @@ Copied from http://whattheemacsd.com/editing-defuns.el-01.html
(indent-for-tab-command)) (indent-for-tab-command))
#+END_SRC #+END_SRC
*** Convert ~camelCase~ to ~snake_case~
#+BEGIN_SRC emacs-lisp
(defun camel-to-snake-case (arg)
"Convert a camelCase word to snake_case.
If the prefix argument ARG is non-nil, convert the text to uppercase."
(interactive "p")
(progn
(let ((start (region-beginning))
(end (region-end))
(case-fold-search nil)
(had-initial-underscore nil))
(goto-char start)
(when (looking-at "_") (setq had-initial-underscore t))
(while (re-search-forward "\\([A-Z]\\)" end t)
(replace-match "_\\1")
(setq end (1+ end)))
(if arg
(upcase-region start end)
(downcase-region start end))
(goto-char start)
(unless had-initial-underscore (delete-char 1)))))
#+END_SRC
*** Insert two spaces after specific characters *** Insert two spaces after specific characters
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp