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
|
;; Define functions
|
||||||
(setq to-camel-case (curried-format nil nil t)) ; camelCase
|
(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-pascal-case (curried-format nil t t)) ; PascalCase
|
||||||
(setq to-snake-case (curried-format "_" nil nil)) ; snake_case
|
(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
|
;; Interactive functions
|
||||||
|
|
||||||
(defun format-to-camel-case-region ()
|
(defun format-to-camel-case-region ()
|
||||||
"Convert the selected text to camelCase."
|
"Convert the selected text to camelCase."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
(format-region to-camel-case))
|
||||||
(delete-region (region-beginning) (region-end))
|
|
||||||
(insert (funcall to-camel-case text))))
|
|
||||||
|
|
||||||
(defun format-to-kebab-case-region ()
|
(defun format-to-kebab-case-region ()
|
||||||
"Convert the selected text to kebab-case."
|
"Convert the selected text to kebab-case or lisp-case."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
(format-region to-kebab-case))
|
||||||
(delete-region (region-beginning) (region-end))
|
|
||||||
(insert (funcall to-kebab-case text))))
|
(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 ()
|
(defun format-to-pascal-case-region ()
|
||||||
"Convert the selected text to PascalCase."
|
"Convert the selected text to PascalCase."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
(format-region to-pascal-case))
|
||||||
(delete-region (region-beginning) (region-end))
|
|
||||||
(insert (funcall to-pascal-case text))))
|
|
||||||
|
|
||||||
(defun format-to-snake-case-region ()
|
(defun format-to-snake-case-region ()
|
||||||
"Convert the selected text to snake_case."
|
"Convert the selected text to snake_case."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
|
(format-region to-snake-case))
|
||||||
(delete-region (region-beginning) (region-end))
|
|
||||||
(insert (funcall to-snake-case text))))
|
|
||||||
|
|
||||||
;;; transform-texts-to-formats.el ends here
|
;;; transform-texts-to-formats.el ends here
|
||||||
|
Loading…
Reference in New Issue
Block a user