summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-06-28 04:19:48 +0300
committerThanos Apollo <[email protected]>2024-06-28 04:19:48 +0300
commit949e2f01a74c24b18cf07d77eb8cba1443111dcf (patch)
tree8510ec80e9bd7a3eb8591f78f6362c153be6fdad
parentbe12c1ac92df9f0236915119a275d92c97a34cf1 (diff)
Add gnosis-center-string
-rw-r--r--gnosis.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/gnosis.el b/gnosis.el
index 8123510..3be0881 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -329,6 +329,19 @@ History is disabled."
(padding (max (/ (- (window-width) (length text)) 2) 0)))
(delete-region start end)
(insert (make-string padding ? ) text)))
+
+(defun gnosis-center-string (input-string)
+ "Center each line of the given INPUT-STRING in the current window width."
+ (let* ((lines (split-string input-string "\n"))
+ (window-width (window-width)))
+ (mapconcat
+ (lambda (line)
+ (let* ((text (string-trim line))
+ (padding (/ (max 0 (- window-width (length text))) 2)))
+ (concat (make-string padding ? ) text)))
+ lines
+ "\n")))
+
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\*\\([^*]+\\)\\*" nil t)