From 1429d2c03b08b59a1cf268c6ef90cbd8ce5bb141 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Mon, 12 Jun 2023 13:00:22 +0200 Subject: [PATCH] Fix format --- format-region.el | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/format-region.el b/format-region.el index 4bd20ac..e2941ab 100644 --- a/format-region.el +++ b/format-region.el @@ -21,11 +21,17 @@ IS-FIRST-WORD-CAPITALIZED is a boolean that indicates if the first word should be capitalized. 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 (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 (if is-first-word-capitalized sentence-with-new-separator (concat (downcase (substring sentence-with-new-separator 0 1)) (substring sentence-with-new-separator 1)))) ; Capitalize first letter of first word + (let* ((words-lower-case (downcase sentence)) ; To lowercase. + (words (split-string words-lower-case " ")) ; Split sentence into words + ; by spaces. + (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 (if is-first-word-capitalized + sentence-with-new-separator (concat (downcase + (substring sentence-with-new-separator 0 1)) + (substring sentence-with-new-separator 1)))) ; Capitalize first letter of first word. ) sentence-with-first-word-capitalized)) @@ -33,7 +39,8 @@ if all words should be capitalized." (defmacro format-region-curried (separator is-first-word-capitalized is-all-words-capitalized) - "Curry the function to-format with SEPARATOR, IS-FIRST-WORD-CAPITALIZED and IS-ALL-WORDS-CAPITALIZED." + "Curry the function to-format: +SEPARATOR, IS-FIRST-WORD-CAPITALIZED and IS-ALL-WORDS-CAPITALIZED." `(lambda (sentence) (format-region-to-format sentence ,separator ,is-first-word-capitalized ,is-all-words-capitalized))) ;; Define functions