Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akicho8/string-inflection
underscore -> UPCASE -> CamelCase conversion of names
https://github.com/akicho8/string-inflection
emacs emacs-lisp inflection string utility
Last synced: 2 days ago
JSON representation
underscore -> UPCASE -> CamelCase conversion of names
- Host: GitHub
- URL: https://github.com/akicho8/string-inflection
- Owner: akicho8
- Created: 2012-10-11T14:20:57.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T05:33:56.000Z (4 months ago)
- Last Synced: 2024-12-16T00:02:59.795Z (9 days ago)
- Topics: emacs, emacs-lisp, inflection, string, utility
- Language: Emacs Lisp
- Homepage:
- Size: 149 KB
- Stars: 249
- Watchers: 6
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- Changelog: HISTORY.org
Awesome Lists containing this project
README
* underscore -> UPCASE -> CamelCase conversion of names
[[https://github.com/akicho8/string-inflection/blob/master/HISTORY.org][Change History]]
** Configuration Examples
*** Example 1
#+BEGIN_SRC elisp
(require 'string-inflection);; C-q C-u is similar to the keybinding used by Vz Editor.
(global-unset-key (kbd "C-q"))
(global-set-key (kbd "C-q C-u") 'my-string-inflection-cycle-auto)(defun my-string-inflection-cycle-auto ()
"switching by major-mode"
(interactive)
(cond
;; for emacs-lisp-mode
((eq major-mode 'emacs-lisp-mode)
(string-inflection-all-cycle))
;; for python
((eq major-mode 'python-mode)
(string-inflection-python-style-cycle))
;; for java
((eq major-mode 'java-mode)
(string-inflection-java-style-cycle))
;; for elixir
((eq major-mode 'elixir-mode)
(string-inflection-elixir-style-cycle))
(t
;; default
(string-inflection-ruby-style-cycle))))
#+END_SRC*** Example 2
#+BEGIN_SRC elisp
(require 'string-inflection);; default
(global-set-key (kbd "C-c C-u") 'string-inflection-all-cycle);; for ruby
(add-hook 'ruby-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-ruby-style-cycle)));; for elixir
(add-hook 'elixir-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-elixir-style-cycle)));; for java
(add-hook 'java-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-java-style-cycle)));; for python
(add-hook 'python-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-python-style-cycle)))#+END_SRC
** How to Use
For each of the following, place the cursor at =emacs_lisp= and type =C-q C-u=, the results will be as follows:
In the case of =string-inflection-ruby-style-cycle=
: emacs_lisp => EMACS_LISP => EmacsLisp => emacs_lisp
In the case of =string-inflection-elixir-style-cycle=
: emacs_lisp => EmacsLisp => emacs_lisp
In the case of =string-inflection-python-style-cycle=
: emacs_lisp => EMACS_LISP => EmacsLisp => emacs_lisp
In the case of =string-inflection-java-style-cycle=
: emacsLisp => EMACS_LISP => EmacsLisp => emacsLisp
In the case of =string-inflection-all-cycle=
: emacs_lisp => EMACS_LISP => EmacsLisp => emacsLisp => emacs-lisp => Emacs_Lisp => emacs_lisp
It is recommended that the major mode functions are used instead of =string-inflection-all-cycle=.
** Standalone Functions
#+BEGIN_SRC elisp
(string-inflection-underscore-function "EmacsLisp") ; => "emacs_lisp"
(string-inflection-pascal-case-function "emacs_lisp") ; => "EmacsLisp"
(string-inflection-camelcase-function "emacs_lisp") ; => "emacsLisp"
(string-inflection-upcase-function "emacs_lisp") ; => "EMACS_LISP"
(string-inflection-kebab-case-function "emacs_lisp") ; => "emacs-lisp"
(string-inflection-capital-underscore-function "emacs_lisp") ; => "Emacs_Lisp"(string-inflection-pascal-case-p "EmacsLisp") ; => t
(string-inflection-pascal-case-p "emacs_lisp") ; => nil
; etc...
#+END_SRC** Region usage
You can also use this library to convert a region's casing. That applies the
operation to all symbols of the region. If a symbol is only partially covered
by the region, the operation is performed only on that part.For that, simply select a region and perform =M-x string-inflection-kebab-case= (or any such other function).
** Other configuration options
You can configure where the cursor shall finish after the inflection operation
using the =string-inflection-final-position= customization option.