Add README and optimize
This commit is contained in:
parent
8be306de13
commit
5f7020ec4c
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# format-region.el
|
||||
|
||||
Transform region in different formats: camelCase, kebap-case or lisp-case, PascalCase or snake_case.
|
||||
|
||||
![format-region](demo.gif)
|
||||
|
||||
## Usage
|
||||
|
||||
Select region and call:
|
||||
|
||||
### camelCase
|
||||
|
||||
```
|
||||
M-x format-to-camel-case-region
|
||||
```
|
||||
|
||||
### kebap-case o lisp-case
|
||||
|
||||
```
|
||||
M-x format-to-kebap-case-region
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
M-x format-to-lisp-case-region
|
||||
```
|
||||
|
||||
### PascalCase
|
||||
|
||||
```
|
||||
M-x format-to-pascal-case-region
|
||||
```
|
||||
|
||||
### snake_case
|
||||
|
||||
```
|
||||
M-x format-to-snake-case-region
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download `format-region.el` file.
|
||||
|
||||
2. Add this to your `~/.emacs` file:
|
||||
|
||||
```elisp
|
||||
(add-to-list 'load-path "/path/to/format-region.el")
|
||||
(require 'format-region)
|
||||
```
|
@ -32,38 +32,42 @@ IS-ALL-WORDS-CAPITALIZED is a boolean that indicates if all words should be capi
|
||||
|
||||
;; Define functions
|
||||
(setq to-camel-case (curried-format nil nil t)) ; camelCase
|
||||
(setq to-kebab-case (curried-format "-" nil nil)) ; kebab-case
|
||||
(setq to-kebab-case (curried-format "-" nil nil)) ; kebab-case or lisp-case
|
||||
(setq to-pascal-case (curried-format nil t t)) ; PascalCase
|
||||
(setq to-snake-case (curried-format "_" nil nil)) ; snake_case
|
||||
|
||||
(defun format-region (fn-format)
|
||||
"Format the selected region with FN-FORMAT."
|
||||
(interactive)
|
||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (funcall fn-format text))))
|
||||
|
||||
;; Interactive functions
|
||||
|
||||
(defun format-to-camel-case-region ()
|
||||
"Convert the selected text to camelCase."
|
||||
(interactive)
|
||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (funcall to-camel-case text))))
|
||||
(format-region to-camel-case))
|
||||
|
||||
(defun format-to-kebab-case-region ()
|
||||
"Convert the selected text to kebab-case."
|
||||
"Convert the selected text to kebab-case or lisp-case."
|
||||
(interactive)
|
||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (funcall to-kebab-case text))))
|
||||
(format-region to-kebab-case))
|
||||
|
||||
(defun format-to-lisp-case-region ()
|
||||
"Convert the selected text to kebab-case or lisp-case."
|
||||
(interactive)
|
||||
(format-region to-kebab-case))
|
||||
|
||||
(defun format-to-pascal-case-region ()
|
||||
"Convert the selected text to PascalCase."
|
||||
(interactive)
|
||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (funcall to-pascal-case text))))
|
||||
(format-region to-pascal-case))
|
||||
|
||||
(defun format-to-snake-case-region ()
|
||||
"Convert the selected text to snake_case."
|
||||
(interactive)
|
||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (funcall to-snake-case text))))
|
||||
(format-region to-snake-case))
|
||||
|
||||
;;; transform-texts-to-formats.el ends here
|
||||
|
Loading…
x
Reference in New Issue
Block a user