From c9b381656a395fbc3823cb496be711a5da7fab6d Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Fri, 2 Jun 2023 18:14:04 +0200 Subject: [PATCH] Add interactive functions --- transform-texts-to-formats.el | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/transform-texts-to-formats.el b/transform-texts-to-formats.el index 69980e8..fb24f15 100644 --- a/transform-texts-to-formats.el +++ b/transform-texts-to-formats.el @@ -19,9 +19,9 @@ IS-FIRST-WORD-CAPITALIZED is a boolean that indicates if the first word should b IS-ALL-WORDS-CAPITALIZED is a boolean that indicates if all words should be capitalized." (let* ((words-lower-case (downcase sentence)) ; To lowercase (words (split-string words-lower-case " ")) ; Split sentence into words by spaces - (words-case (when is-all-words-capitalized (mapcar #'capitalize words))) ; Capitalize first letter of each word + (words-case (if is-all-words-capitalized (mapcar #'capitalize words) words)) ; Capitalize first letter of each word (sentence-with-new-separator (mapconcat 'identity words-case separator)) ; Join words with separator - (sentence-with-first-word-capitalized (when is-first-word-capitalized (capitalize sentence-with-new-separator))) ; Capitalize first letter of first word + (sentence-with-first-word-capitalized (if is-first-word-capitalized (concat (capitalize (substring sentence-with-new-separator 0 1)) (substring sentence-with-new-separator 1)) sentence-with-new-separator)) ; Capitalize first letter of first word ) sentence-with-first-word-capitalized)) @@ -32,10 +32,31 @@ 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 (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 -(message "%s" (funcall to-camel-case "hola que tal")) +;; Interactive functions + +(defun format-to-camel-case () + "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)))) + +(defun format-to-kebab-case () + "Convert the selected text to kebab-case." + (interactive) + (let ((text (buffer-substring-no-properties (region-beginning) (region-end)))) + (delete-region (region-beginning) (region-end)) + (insert (funcall to-kebab-case text)))) + +(defun format-to-pascal-case () + "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)))) ;;; transform-texts-to-formats.el ends here