From be12c1ac92df9f0236915119a275d92c97a34cf1 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 28 Jun 2024 04:19:33 +0300 Subject: Add gnosis-center-current-line --- gnosis.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gnosis.el b/gnosis.el index 413e146..8123510 100644 --- a/gnosis.el +++ b/gnosis.el @@ -320,6 +320,15 @@ History is disabled." (defun gnosis-apply-overlays () "Apply custom font overlays for syntax highlighting." +(defun gnosis-center-current-line () + "Center text in the current line ignoring leading spaces." + (interactive) + (let* ((start (line-beginning-position)) + (end (line-end-position)) + (text (string-trim (buffer-substring start end))) + (padding (max (/ (- (window-width) (length text)) 2) 0))) + (delete-region start end) + (insert (make-string padding ? ) text))) (save-excursion (goto-char (point-min)) (while (re-search-forward "\\*\\([^*]+\\)\\*" nil t) -- cgit v1.2.3