diff options
author | Thanos Apollo <[email protected]> | 2024-06-28 04:19:48 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-06-28 04:19:48 +0300 |
commit | 949e2f01a74c24b18cf07d77eb8cba1443111dcf (patch) | |
tree | 8510ec80e9bd7a3eb8591f78f6362c153be6fdad /gnosis.el | |
parent | be12c1ac92df9f0236915119a275d92c97a34cf1 (diff) |
Add gnosis-center-string
Diffstat (limited to 'gnosis.el')
-rw-r--r-- | gnosis.el | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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) |