emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/hydra 91f961d5d5 11/35: lv.el (lv-use-padding): New def


From: ELPA Syncer
Subject: [elpa] externals/hydra 91f961d5d5 11/35: lv.el (lv-use-padding): New defcustom
Date: Tue, 25 Oct 2022 22:59:05 -0400 (EDT)

branch: externals/hydra
commit 91f961d5d5e49765247e6e376c57bb695c9d4e17
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    lv.el (lv-use-padding): New defcustom
    
    Fixes #351
---
 lv.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lv.el b/lv.el
index 306adf7edd..af78610316 100644
--- a/lv.el
+++ b/lv.el
@@ -43,6 +43,11 @@
   :group 'lv
   :type 'boolean)
 
+(defcustom lv-use-padding nil
+  "Wheter to use horizontal padding in the LV window."
+  :group 'lv
+  :type 'boolean)
+
 (defface lv-separator
   '((((class color) (background light)) :background "grey80")
     (((class color) (background  dark)) :background "grey30"))
@@ -89,6 +94,14 @@ Only the background color is significant."
 (defvar lv-force-update nil
   "When non-nil, `lv-message' will refresh even for the same string.")
 
+(defun lv--pad-to-center (str width)
+  "Pad STR with spaces on the left to be centered to WIDTH."
+  (let* ((strs (split-string str "\n"))
+         (padding (make-string
+                   (/ (- width (length (car strs))) 2)
+                   ?\ )))
+    (mapconcat (lambda (s) (concat padding s)) strs "\n")))
+
 (defun lv-message (format-string &rest args)
   "Set LV window contents to (`format' FORMAT-STRING ARGS)."
   (let* ((str (apply #'format format-string args))
@@ -96,6 +109,8 @@ Only the background color is significant."
          deactivate-mark
          golden-ratio-mode)
     (with-selected-window (lv-window)
+      (when lv-use-padding
+        (setq str (lv--pad-to-center str (window-width))))
       (unless (and (string= (buffer-string) str)
                    (null lv-force-update))
         (delete-region (point-min) (point-max))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]