core: add support for mode-line themes

New layer variable `dotspacemacs-mode-line-themes`:

Set the theme for the Spaceline. Supported themes are `spacemacs',
`all-the-icons', `custom', `vim-powerline' and `vanilla'. The first three
are spaceline themes. `vanilla' is default Emacs mode-line. `custom' is a
user defined themes, refer to the DOCUMENTATION.org for more info on how
to create your own spaceline theme."

See DOCUMENTATION.org changes for more info.

This commit adds support for `spaceline-all-the-icons` package.
This commit is contained in:
syl20bnr 2018-01-11 23:53:44 -05:00
parent 4ecd015fe8
commit a131c89909
9 changed files with 152 additions and 98 deletions

View File

@ -147,6 +147,13 @@ whenever you start Emacs.")
Press `SPC T n' to cycle to the next theme in the list (works great Press `SPC T n' to cycle to the next theme in the list (works great
with 2 themes variants, one dark and one light") with 2 themes variants, one dark and one light")
(defvar dotspacemacs-mode-line-theme 'spacemacs
"Set the theme for the Spaceline. Supported themes are `spacemacs',
`all-the-icons', `custom', `vim-powerline' and `vanilla'. The first three
are spaceline themes. `vanilla' is default Emacs mode-line. `custom' is a
user defined themes, refer to the DOCUMENTATION.org for more info on how
to create your own spaceline theme.")
(defvar dotspacemacs-frame-title-format "%I@%S" (defvar dotspacemacs-frame-title-format "%I@%S"
"Default format string for a frame title bar, using the "Default format string for a frame title bar, using the
original format spec, and additional customizations.") original format spec, and additional customizations.")
@ -741,11 +748,24 @@ error recovery."
(dotspacemacs||let-init-test (dotspacemacs||let-init-test
(dotspacemacs/init) (dotspacemacs/init)
(spacemacs//test-var (spacemacs//test-var
(lambda (x) (or (member x '(vim emacs hybrid)) (lambda (x)
(and (listp x) (or (member x '(vim
(spacemacs/mplist-get x :variables)))) emacs
hybrid))
(and (listp x)
(eq 'hybrid (car x))
(spacemacs/mplist-get x :variables))))
'dotspacemacs-editing-style 'dotspacemacs-editing-style
"is \'vim, \'emacs or \'hybrid or and list with `:variable' keyword") "is \'vim, \'emacs or \'hybrid or and list with `:variable' keyword")
(spacemacs//test-var
(lambda (x)
(member x '(spacemacs
all-the-icons
custom
vim-powerline
vanilla)))
'dotspacemacs-mode-line-theme
"is \'spacemacs, \'all-the-icons, \'custom, \'vim-powerline or 'vanilla")
(spacemacs//test-var (spacemacs//test-var
(lambda (x) (member x '(original cache nil))) (lambda (x) (member x '(original cache nil)))
'dotspacemacs-auto-save-file-location (concat "is one of \'original, " 'dotspacemacs-auto-save-file-location (concat "is one of \'original, "

View File

@ -135,6 +135,12 @@ It should only modify the values of Spacemacs settings."
;; with 2 themes variants, one dark and one light) ;; with 2 themes variants, one dark and one light)
dotspacemacs-themes '(spacemacs-dark dotspacemacs-themes '(spacemacs-dark
spacemacs-light) spacemacs-light)
;; Set the theme for the Spaceline. Supported themes are `spacemacs',
;; `all-the-icons', `custom', `vim-powerline' and `vanilla'. The first three
;; are spaceline themes. `vanilla' is default Emacs mode-line. `custom' is a
;; user defined themes, refer to the DOCUMENTATION.org for more info on how
;; to create your own spaceline theme.. (default 'spacemacs)
dotspacemacs-mode-line-theme 'spacemacs
;; If non-nil the cursor color matches the state color in GUI Emacs. ;; If non-nil the cursor color matches the state color in GUI Emacs.
;; (default t) ;; (default t)
dotspacemacs-colorize-cursor-according-to-state t dotspacemacs-colorize-cursor-according-to-state t

View File

@ -73,15 +73,15 @@
- [[#gui-toggles][GUI Toggles]] - [[#gui-toggles][GUI Toggles]]
- [[#global-line-numbers][Global line numbers]] - [[#global-line-numbers][Global line numbers]]
- [[#mode-line][Mode-line]] - [[#mode-line][Mode-line]]
- [[#powerline-font-installation-for-terminal-mode-users][Powerline font installation for terminal-mode users]] - [[#mode-line-themes][Mode-line themes]]
- [[#flycheck-integration][Flycheck integration]] - [[#spacemacs-mode-line-theme][Spacemacs mode-line theme]]
- [[#anzu-integration][Anzu integration]] - [[#powerline-font-installation-for-terminal-mode-users][Powerline font installation for terminal-mode users]]
- [[#battery-status-integration][Battery status integration]] - [[#flycheck-integration][Flycheck integration]]
- [[#powerline-separators][Powerline separators]] - [[#anzu-integration][Anzu integration]]
- [[#minor-modes][Minor Modes]] - [[#battery-status-integration][Battery status integration]]
- [[#customizing-the-mode-line][Customizing the mode-line]] - [[#powerline-separators][Powerline separators]]
- [[#spaceline][Spaceline]] - [[#minor-modes][Minor Modes]]
- [[#restore-lighters][Restore lighters]] - [[#custom-spaceline-theme][Custom spaceline theme]]
- [[#frame-title][Frame title]] - [[#frame-title][Frame title]]
- [[#iconified-tabified-title][Iconified (tabified) title]] - [[#iconified-tabified-title][Iconified (tabified) title]]
- [[#layouts-and-workspaces][Layouts and workspaces]] - [[#layouts-and-workspaces][Layouts and workspaces]]
@ -1261,6 +1261,31 @@ Enable line numbers only in programming modes, except for c-mode and c++ mode:
#+END_SRC #+END_SRC
** Mode-line ** Mode-line
*** Mode-line themes
Spacemacs supports different mode-line themes. The mode-line theme is set in the
dotfile with the variable =dotspacemacs-mode-line-theme=.
Currently supported themes are:
- spaceline themes: =spacemacs=, =all-the-icons=, =custom=
- a powerline theme: =vim-powerline=
- no theme at all: =vanilla=
The default theme is =spacemacs= and this theme is described in more detailed in
the next section.
=all-the-icons= is the theme defined in the package [[https://github.com/domtronn/spaceline-all-the-icons.el][spaceline-all-the-icons]].
=custom= is a user custom spaceline theme, see the guide in the following section.
=vim-powerline= is for the Vim users who are nostalgic of the good old Vim
powerline.
=vanilla= is the stock mode-line that comes with Emacs.
For now, a restart of Emacs is required whenever you change the theme of your
mode-line.
*** Spacemacs mode-line theme
The mode line is a heavily customized [[https://github.com/milkypostman/powerline][powerline]] with the following capabilities: The mode line is a heavily customized [[https://github.com/milkypostman/powerline][powerline]] with the following capabilities:
- show the window number - show the window number
- color code for current state - color code for current state
@ -1298,19 +1323,19 @@ Some elements can be dynamically toggled:
| ~SPC t m v~ | toggle the version control info | | ~SPC t m v~ | toggle the version control info |
| ~SPC t m V~ | toggle the new version lighter | | ~SPC t m V~ | toggle the new version lighter |
*** Powerline font installation for terminal-mode users **** Powerline font installation for terminal-mode users
Users who run Emacs in terminal mode may need to install the [[https://github.com/powerline/fonts][Powerline patched Users who run Emacs in terminal mode may need to install the [[https://github.com/powerline/fonts][Powerline patched
fonts]] and configure their terminal clients to use them to make the Powerline fonts]] and configure their terminal clients to use them to make the Powerline
separators render correctly. separators render correctly.
*** Flycheck integration **** Flycheck integration
When [[https://github.com/flycheck/flycheck][Flycheck]] minor mode is enabled, a new element appears showing the number of When [[https://github.com/flycheck/flycheck][Flycheck]] minor mode is enabled, a new element appears showing the number of
errors, warnings and info. errors, warnings and info.
[[file:img/powerline-wave.png]] [[file:img/powerline-wave.png]]
/Flycheck integration in mode-line/ /Flycheck integration in mode-line/
*** Anzu integration **** Anzu integration
[[https://github.com/syohex/emacs-anzu][Anzu]] shows the number of occurrence when performing a search. Spacemacs [[https://github.com/syohex/emacs-anzu][Anzu]] shows the number of occurrence when performing a search. Spacemacs
integrates the Anzu status nicely by displaying it temporarily when ~n~ or ~N~ integrates the Anzu status nicely by displaying it temporarily when ~n~ or ~N~
are being pressed. See the =5/6= segment on the screenshot below. are being pressed. See the =5/6= segment on the screenshot below.
@ -1318,7 +1343,7 @@ are being pressed. See the =5/6= segment on the screenshot below.
[[file:img/powerline-anzu.png]] [[file:img/powerline-anzu.png]]
/Anzu integration in mode-line/ /Anzu integration in mode-line/
*** Battery status integration **** Battery status integration
[[https://github.com/lunaryorn/fancy-battery.el][fancy-battery]] displays the percentage of total charge of the battery as well as [[https://github.com/lunaryorn/fancy-battery.el][fancy-battery]] displays the percentage of total charge of the battery as well as
the time remaining to charge or discharge completely the battery. the time remaining to charge or discharge completely the battery.
@ -1332,7 +1357,7 @@ A color code is used for the battery status:
*Note*: These colors may vary depending on your theme. *Note*: These colors may vary depending on your theme.
*** Powerline separators **** Powerline separators
It is possible to easily customize the =powerline separator= by setting the It is possible to easily customize the =powerline separator= by setting the
=powerline-default-separator= variable in your =~/.spacemacs= and then =powerline-default-separator= variable in your =~/.spacemacs= and then
recompiling the modeline. For instance, if you want to set back the separator to recompiling the modeline. For instance, if you want to set back the separator to
@ -1368,7 +1393,7 @@ powerline, here is an exhaustive set of screenshots:
| =zigzag= | [[file:img/powerline-zigzag.png]] | | =zigzag= | [[file:img/powerline-zigzag.png]] |
| =nil= | [[file:img/powerline-nil.png]] | | =nil= | [[file:img/powerline-nil.png]] |
*** Minor Modes **** Minor Modes
Spacemacs uses [[https://www.emacswiki.org/emacs/DiminishedModes][diminish]] mode to reduce the size of minor mode indicators: Spacemacs uses [[https://www.emacswiki.org/emacs/DiminishedModes][diminish]] mode to reduce the size of minor mode indicators:
The minor mode area can be toggled on and off with ~SPC t m m~ The minor mode area can be toggled on and off with ~SPC t m m~
@ -1419,33 +1444,27 @@ squared symbols like =🅿=.
| ~SPC t C-W~ | =Ⓦ= | W | automatic whitespace cleanup globally | | ~SPC t C-W~ | =Ⓦ= | W | automatic whitespace cleanup globally |
| ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode | | ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode |
*** Customizing the mode-line *** Custom spaceline theme
**** Spaceline You can create your own Spaceline theme by setting the variable
Spacemacs uses [[https://github.com/TheBB/spaceline][Spaceline]] to provide its mode-line. It consists of a number of =dotspacemacs-mode-line-theme= to =custom= and define a function called
/segments/ arranged on the left and right sides. These are defined in the =spaceline-custom-theme= in your =dotspacemacs/user-init= function of your
variables =spaceline-left= and =spaceline-right=. Segments can be defined using dotfile. This functions must accept a variadic number of arguments which are
=spaceline-define-segment=, and added to the appropriate location in the left or additional segments added by Spacemacs (like a segment to notify about available
right hand side variables. updates etc...).
Please see the Spaceline documentation for more information. Example:
**** Restore lighters
Lighters are abbreviations displayed in the mode-line to identify running minor
modes. Spacemacs diminishes most of them to make them more compact.
If you want to restore the original lighter of a mode then use the function
=spacemacs/diminish-undo= with the appropriate mode name.
For example to undo diminish for =company=:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(spacemacs|use-package-add-hook company (defun spaceline-custom-theme (&rest additional-segments)
:post-config (spacemacs/diminish-undo 'company-mode)) "My custom spaceline theme."
(spaceline-compile
`(major-mode (minor-modes :when active) buffer-id)
`((line-column :separator " | " :priority 3)
,@additional-segments))
(setq-default mode-line-format '("%e" (:eval (spaceline-ml-main)))))
#+END_SRC #+END_SRC
Note that we use a =use-package= post init hook to be sure to override any Restart Emacs and enjoy your very own mode-line!
lazily diminished lighters (see [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/LAYERS.org][layers documentation]] for more information
about lazy loading).
** Frame title ** Frame title
Default frame title displays name of current process and hostname of system. You Default frame title displays name of current process and hostname of system. You

View File

@ -51,3 +51,15 @@
unicode unicode
(if ascii ascii unicode)))) (if ascii ascii unicode))))
(diminish mode dim)))))))) (diminish mode dim))))))))
;; Vim powerline
(defun spacemacs//set-vimish-powerline-for-startup-buffers ()
"Set the powerline for buffers created when Emacs starts."
(dolist (buffer '("*Messages*" "*spacemacs*" "*Compile-Log*"))
(when (get-buffer buffer)
(with-current-buffer buffer
(setq-local mode-line-format (default-value 'mode-line-format))
(powerline-set-selected-window)
(powerline-reset)))))

View File

@ -11,11 +11,19 @@
(setq spacemacs-modeline-packages (setq spacemacs-modeline-packages
'( '(
anzu
fancy-battery fancy-battery
neotree
spaceline spaceline
spaceline-all-the-icons
symon symon
(vim-powerline :location local)
)) ))
(defun spacemacs-modeline/post-init-anzu ()
(when (eq 'all-the-icons dotspacemacs-mode-line-theme)
(spaceline-all-the-icons--setup-anzu)))
(defun spacemacs-modeline/init-fancy-battery () (defun spacemacs-modeline/init-fancy-battery ()
(use-package fancy-battery (use-package fancy-battery
:defer t :defer t
@ -27,8 +35,13 @@
:evil-leader "tmb") :evil-leader "tmb")
(setq-default fancy-battery-show-percentage t)))) (setq-default fancy-battery-show-percentage t))))
(defun spacemacs-modeline/post-init-neotree ()
(when (eq 'all-the-icons dotspacemacs-mode-line-theme)
(spaceline-all-the-icons--setup-neotree)))
(defun spacemacs-modeline/init-spaceline () (defun spacemacs-modeline/init-spaceline ()
(use-package spaceline-config (use-package spaceline-config
:if (memq dotspacemacs-mode-line-theme '(spaceline all-the-icons custom))
:init :init
(progn (progn
(add-hook 'spacemacs-post-user-config-hook 'spaceline-compile) (add-hook 'spacemacs-post-user-config-hook 'spaceline-compile)
@ -97,8 +110,9 @@
(spacemacs-powerline-new-version (spacemacs-powerline-new-version
(spacemacs/get-new-version-lighter-face (spacemacs/get-new-version-lighter-face
spacemacs-version spacemacs-new-version)))) spacemacs-version spacemacs-new-version))))
(apply #'spaceline-spacemacs-theme (let ((theme (intern (format "spaceline-%S-theme"
spacemacs-spaceline-additional-segments) dotspacemacs-mode-line-theme))))
(apply theme spacemacs-spaceline-additional-segments))
;; Additional spacelines ;; Additional spacelines
(when (package-installed-p 'helm) (when (package-installed-p 'helm)
(spaceline-helm-mode t)) (spaceline-helm-mode t))
@ -108,6 +122,19 @@
;; spaceline ;; spaceline
(spacemacs//set-powerline-for-startup-buffers)))) (spacemacs//set-powerline-for-startup-buffers))))
(defun spacemacs-modeline/pre-init-spaceline-all-the-icons ()
(when (eq 'all-the-icons dotspacemacs-mode-line-theme)
(spacemacs|use-package-add-hook spaceline-config
:pre-config
(progn
(require 'spaceline-all-the-icons)
(spaceline-all-the-icons--setup-git-ahead)))))
(defun spacemacs-modeline/init-spaceline-all-the-icons ()
(use-package spaceline-all-the-icons
:defer t
:init (setq spaceline-all-the-icons-separator-type 'cup)))
(defun spacemacs-modeline/init-symon () (defun spacemacs-modeline/init-symon ()
(use-package symon (use-package symon
:defer t :defer t
@ -118,3 +145,29 @@
(spacemacs|add-toggle minibuffer-system-monitor (spacemacs|add-toggle minibuffer-system-monitor
:mode symon-mode :mode symon-mode
:evil-leader "tms")))) :evil-leader "tms"))))
(defun spacemacs-modeline/init-vim-powerline ()
(when (eq 'vim-powerline dotspacemacs-mode-line-theme)
(require 'powerline)
(if (display-graphic-p)
(setq powerline-default-separator 'arrow)
(setq powerline-default-separator 'utf-8))
(defun powerline-raw (str &optional face pad)
"Render STR as mode-line data using FACE and optionally
PAD import on left (l) or right (r) or left-right (lr)."
(when str
(let* ((rendered-str (format-mode-line str))
(padded-str (concat
(when (and (> (length rendered-str) 0)
(or (eq pad 'l) (eq pad 'lr))) " ")
(if (listp str) rendered-str str)
(when (and (> (length rendered-str) 0)
(or (eq pad 'r) (eq pad 'lr))) " "))))
(if face
(pl/add-text-property padded-str 'face face)
padded-str))))
(require 'vim-powerline-theme)
(powerline-vimish-theme)
(add-hook 'emacs-startup-hook
'spacemacs//set-vimish-powerline-for-startup-buffers)))

View File

@ -1,13 +0,0 @@
#+TITLE: vim-powerline layer
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#install][Install]]
* Description
A powerline theme modeled after the vim powerline theme.
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =vim-powerline= to the existing =dotspacemacs-configuration-layers= list in this
file.

View File

@ -1,43 +0,0 @@
(setq vim-powerline-packages
'(
powerline
(vim-powerline :location local)
))
(defun vim-powerline/init-powerline ())
(defun vim-powerline/init-vim-powerline ()
(require 'powerline)
(if (display-graphic-p)
(setq powerline-default-separator 'arrow)
(setq powerline-default-separator 'utf-8))
(defun powerline-raw (str &optional face pad)
"Render STR as mode-line data using FACE and optionally
PAD import on left (l) or right (r) or left-right (lr)."
(when str
(let* ((rendered-str (format-mode-line str))
(padded-str (concat
(when (and (> (length rendered-str) 0)
(or (eq pad 'l) (eq pad 'lr))) " ")
(if (listp str) rendered-str str)
(when (and (> (length rendered-str) 0)
(or (eq pad 'r) (eq pad 'lr))) " "))))
(if face
(pl/add-text-property padded-str 'face face)
padded-str))))
(require 'vim-powerline-theme)
(powerline-vimish-theme)
(defun spacemacs//set-vimish-powerline-for-startup-buffers ()
"Set the powerline for buffers created when Emacs starts."
(dolist (buffer '("*Messages*" "*spacemacs*" "*Compile-Log*"))
(when (get-buffer buffer)
(with-current-buffer buffer
(setq-local mode-line-format (default-value 'mode-line-format))
(powerline-set-selected-window)
(powerline-reset)))))
(add-hook 'emacs-startup-hook
'spacemacs//set-vimish-powerline-for-startup-buffers))