ui/doom-modeline: define bar once

A little faster (and simpler) than memoizing the xpm generator.
This commit is contained in:
Henrik Lissner 2018-01-28 21:38:17 -05:00
parent 15da107e04
commit 3146513442
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -4,10 +4,7 @@
:config :config
(defun +doom-modeline-eldoc (text) (defun +doom-modeline-eldoc (text)
(concat (when (display-graphic-p) (concat (when (display-graphic-p)
(+doom-modeline--make-xpm (+doom-modeline--make-xpm 'doom-modeline-eldoc-bar))
(face-background 'doom-modeline-eldoc-bar nil t)
+doom-modeline-height
+doom-modeline-bar-width))
text)) text))
;; Show eldoc in the mode-line with `eval-expression' ;; Show eldoc in the mode-line with `eval-expression'
@ -176,12 +173,13 @@ active."
(eq (selected-window) +doom-modeline-current-window)) (eq (selected-window) +doom-modeline-current-window))
;; Inspired from `powerline's `pl/make-xpm'. ;; Inspired from `powerline's `pl/make-xpm'.
(def-memoized! +doom-modeline--make-xpm (color height width) (defun +doom-modeline--make-xpm (face &optional height width)
"Create an XPM bitmap." "Create an XPM bitmap."
(propertize (propertize
" " 'display " " 'display
(let ((data (make-list height (make-list width 1))) (let ((data (make-list (or height +doom-modeline-height)
(color (or color "None"))) (make-list (or width +doom-modeline-bar-width) 1)))
(color (or (face-background face nil t) "None")))
(create-image (create-image
(concat (concat
(format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\"," (format "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\","
@ -557,17 +555,15 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
(image-size (image-get-display-property) :pixels) (image-size (image-get-display-property) :pixels)
(format " %dx%d " width height))))) (format " %dx%d " width height)))))
(defvar +doom-modeline--bar-active nil)
(defvar +doom-modeline--bar-inactive nil)
(def-modeline-segment! bar (def-modeline-segment! bar
"The bar regulates the height of the mode-line in GUI Emacs. "The bar regulates the height of the mode-line in GUI Emacs.
Returns \"\" to not break --no-window-system." Returns \"\" to not break --no-window-system."
(if (display-graphic-p) (if window-system
(+doom-modeline--make-xpm (if (active)
(face-background (if (active) +doom-modeline--bar-active
'doom-modeline-bar +doom-modeline--bar-inactive)
'doom-modeline-inactive-bar)
nil t)
+doom-modeline-height
+doom-modeline-bar-width)
"")) ""))
@ -601,6 +597,10 @@ Returns \"\" to not break --no-window-system."
;; ;;
(defun +doom-modeline|init () (defun +doom-modeline|init ()
;; Create bars
(setq +doom-modeline--bar-active (+doom-modeline--make-xpm 'doom-modeline-bar)
+doom-modeline--bar-inactive (+doom-modeline--make-xpm 'doom-modeline-inactive-bar))
;; These buffers are already created and don't get modelines. For the love of ;; These buffers are already created and don't get modelines. For the love of
;; Emacs, someone give the man a modeline! ;; Emacs, someone give the man a modeline!
(dolist (bname '("*scratch*" "*Messages*")) (dolist (bname '("*scratch*" "*Messages*"))