lv.el (lv-use-padding): New defcustom

Fixes #351
master
Oleh Krehel 6 years ago
parent 74b32f3ff0
commit 91f961d5d5
  1. 15
      lv.el

15
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))

Loading…
Cancel
Save