From 0f646b884dd9164f923839ed59898c56020e34cc Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Tue, 16 Jan 2018 22:59:29 -0500 Subject: [PATCH] Add properties for mode-line theme, remove powerline-scale Since we have now a variable for the mode-line theme, it makes sense to move the scaling of the mode-line to this variable. Thus the property =:powerline-scale= of variable dotspacemacs-default-font has been removed and it is replace by the property =:separator-scale= used in the variable =dotspacemacs-mode-line-theme=. This commit also adds a the property =:sperator= for the variable =dotspacemacs-mode-line-theme= which allows to set the separator type. Example of the final result: dotspacemacs-mode-line-theme '(all-the-icons :separator cup :separator-scale 1.5) Documentation has been updated to reflect the changes. --- core/core-dotspacemacs.el | 15 +-- core/core-fonts-support.el | 9 +- core/templates/.spacemacs.template | 6 +- doc/DOCUMENTATION.org | 115 +++++++++--------- doc/FAQ.org | 5 +- layers/+spacemacs/spacemacs-modeline/funcs.el | 18 +++ .../+spacemacs/spacemacs-modeline/packages.el | 28 +++-- .../+spacemacs/spacemacs-navigation/funcs.el | 2 +- layers/+spacemacs/spacemacs-visual/funcs.el | 2 +- 9 files changed, 113 insertions(+), 87 deletions(-) diff --git a/core/core-dotspacemacs.el b/core/core-dotspacemacs.el index 3a66429a3..5f7aa7a95 100644 --- a/core/core-dotspacemacs.el +++ b/core/core-dotspacemacs.el @@ -147,12 +147,13 @@ whenever you start Emacs.") Press `SPC T n' to cycle to the next theme in the list (works great with 2 themes variants, one dark and one light") -(defvar dotspacemacs-mode-line-theme 'spacemacs +(defvar dotspacemacs-mode-line-theme '(spacemacs :separator wave :separator-scale 1.5) "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.") +to create your own spaceline theme. Value can be a symbol or a list with +additional properties like '(all-the-icons :separator-scale 1.5).") (defvar dotspacemacs-frame-title-format "%I@%S" "Default format string for a frame title bar, using the @@ -197,13 +198,9 @@ emacs.") (defvar dotspacemacs-default-font '("Source Code Pro" :size 13 :weight normal - :width normal - :powerline-scale 1.1) - "Default font, or prioritized list of fonts. `powerline-scale' -allows to quickly tweak the mode-line size to make separators -look not too crappy. - -Has no effect when running Emacs in terminal.") + :width normal) + "Default font, or prioritized list of fonts. This setting has no effect when +running Emacs in terminal.") (defvar dotspacemacs-remap-Y-to-y$ nil "If non nil `Y' is remapped to `y$' in Evil states.") diff --git a/core/core-fonts-support.el b/core/core-fonts-support.el index cf4a22496..34fcf1191 100644 --- a/core/core-fonts-support.el +++ b/core/core-fonts-support.el @@ -28,16 +28,15 @@ The return value is nil if no font was found, truthy otherwise." (when (find-font (font-spec :name (car plist))) (let* ((font (car plist)) (props (cdr plist)) - (scale (plist-get props :powerline-scale)) (font-props (spacemacs/mplist-remove + ;; although this keyword does not exist anymore + ;; we keep it for backward compatibility (spacemacs/mplist-remove props :powerline-scale) :powerline-offset)) (fontspec (apply 'font-spec :name font font-props))) (spacemacs-buffer/message "Setting font \"%s\"..." font) (set-frame-font fontspec nil t) (push `(font . ,(frame-parameter nil 'font)) default-frame-alist) - (setq-default powerline-scale scale) - (setq-default powerline-height (spacemacs/compute-powerline-height)) ;; fallback font for unicode characters used in spacemacs (pcase system-type (`gnu/linux @@ -83,8 +82,8 @@ The return value is nil if no font was found, truthy otherwise." (throw 'break t))) nil)) -(defun spacemacs/compute-powerline-height () - "Return an adjusted powerline height." +(defun spacemacs/compute-mode-line-height () + "Return an adjusted mode-line height." (let ((scale (if (and (boundp 'powerline-scale) powerline-scale) powerline-scale 1))) (truncate (* scale (frame-char-height))))) diff --git a/core/templates/.spacemacs.template b/core/templates/.spacemacs.template index 1a8322103..809e25a0c 100644 --- a/core/templates/.spacemacs.template +++ b/core/templates/.spacemacs.template @@ -139,8 +139,10 @@ It should only modify the values of Spacemacs settings." ;; `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 + ;; to create your own spaceline theme. Value can be a symbol or list with\ + ;; additional properties. + ;; (default '(spacemacs :separator wave :separator-scale 1.5)) + dotspacemacs-mode-line-theme '(spacemacs :separator wave :separator-scale 1.5) ;; If non-nil the cursor color matches the state color in GUI Emacs. ;; (default t) dotspacemacs-colorize-cursor-according-to-state t diff --git a/doc/DOCUMENTATION.org b/doc/DOCUMENTATION.org index 6b3ea168a..f579126a3 100644 --- a/doc/DOCUMENTATION.org +++ b/doc/DOCUMENTATION.org @@ -74,12 +74,12 @@ - [[#global-line-numbers][Global line numbers]] - [[#mode-line][Mode-line]] - [[#mode-line-themes][Mode-line themes]] + - [[#separators][Separators]] + - [[#separator-scale][Separator scale]] - [[#spacemacs-mode-line-theme][Spacemacs mode-line theme]] - - [[#powerline-font-installation-for-terminal-mode-users][Powerline font installation for terminal-mode users]] - [[#flycheck-integration][Flycheck integration]] - [[#anzu-integration][Anzu integration]] - [[#battery-status-integration][Battery status integration]] - - [[#powerline-separators][Powerline separators]] - [[#all-the-icons-theme][All-the-Icons theme]] - [[#custom-spaceline-theme][Custom spaceline theme]] - [[#minor-modes][Minor Modes]] @@ -1109,8 +1109,7 @@ To change the default font set the variable =dotspacemacs-default-font= in your (setq-default dotspacemacs-default-font '("Source Code Pro" :size 13 :weight normal - :width normal - :powerline-scale 1.1)) + :width normal)) #+END_SRC If the specified font is not found, the fallback one will be used (depends on @@ -1156,13 +1155,6 @@ property of a [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Low_00 'iso8859-1'. The value should be a string or a symbol. - =:script= The script that the font must support (a symbol). -The special property =:powerline-scale= is Spacemacs specific and it is for -quick tweaking of the mode-line height in order to avoid crappy rendering of the -separators like on the following screenshot (default value is 1.1). - -[[file:img/crappy-powerline-separators.png]] -/Ugly separators/ - ** GUI Toggles Some graphical UI indicators can be toggled on and off (toggles start with ~t~ and ~T~): @@ -1286,8 +1278,62 @@ powerline. For now, a restart of Emacs is required whenever you change the theme of your mode-line. +*** Separators +For =spacemacs=, =all-the-icons= and =custom= themes you can specify the type +of separator you want with the property =:separator=. + +#+BEGIN_SRC emacs-lisp +(setq dotspacemacs-mode-line-theme '(all-the-icons :separator 'slant)) +#+END_SRC + +Supported separators and preview: + +| Separator | Spacemacs | All-the-icons | Screenshot | +|--------------+-----------+---------------+-----------------------------------| +| =alternate= | X | | [[file:img/powerline-alternate.png]] | +| =arrow= | X | X | [[file:img/powerline-arrow.png]] | +| =arrow-fade= | X | | [[file:img/powerline-arrow-fade.png]] | +| =bar= | X | | [[file:img/powerline-bar.png]] | +| =box= | X | | [[file:img/powerline-box.png]] | +| =brace= | X | | [[file:img/powerline-brace.png]] | +| =butt= | X | | [[file:img/powerline-butt.png]] | +| =chamfer= | X | | [[file:img/powerline-chamfer.png]] | +| =contour= | X | | [[file:img/powerline-contour.png]] | +| =cup= | | X | | +| =curve= | X | | [[file:img/powerline-curve.png]] | +| =rounded= | X | | [[file:img/powerline-rounded.png]] | +| =roundstub= | X | | [[file:img/powerline-roundstub.png]] | +| =slant= | X | X | [[file:img/powerline-slant.png]] | +| =wave= | X | X | [[file:img/powerline-wave.png]] | +| =zigzag= | X | | [[file:img/powerline-zigzag.png]] | +| =nil= | X | | [[file:img/powerline-nil.png]] | +| =none= | | X | | + +A last special separator is supported, it is =utf-8= which uses actual font +glyphs so it can be rendered in a terminal. You'll need a font patched for the +Vim powerline to be able to use it. The default font used by Spacemacs =Source +Code Pro= already contains the glyphs. + +*** Separator scale +For =spacemacs=, =all-the-icons= and =custom= themes you can specify the size of +the separator with the property =:separator-scale=. It allows to avoid crappy +rendering of the separators like on the following screenshot. + +[[file:img/crappy-powerline-separators.png]] +/Ugly separators/ + +Example: + +#+BEGIN_SRC elisp +(setq dotspacemacs-mode-line-theme '(all-the-icons :separator-scale 1.5)) +#+END_SRC + +Note that this setting won't work correctly when the separator is =utf-8=, if +you use this separator then it is recommended to set =:separator-scale= to =1.0=. + *** Spacemacs mode-line theme -The mode line is a heavily customized [[https://github.com/milkypostman/powerline][powerline]] with the following capabilities: +This theme is a heavily customized [[https://github.com/milkypostman/powerline][powerline]] using [[https://github.com/TheBB/spaceline][spaceline]]. +It has the following capabilities among others: - show the window number - color code for current state - show the number of search occurrences via anzu @@ -1324,11 +1370,6 @@ Some elements can be dynamically toggled: | ~SPC t m v~ | toggle the version control info | | ~SPC t m V~ | toggle the new version lighter | -**** 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 -fonts]] and configure their terminal clients to use them to make the Powerline -separators render correctly. - **** Flycheck integration When [[https://github.com/flycheck/flycheck][Flycheck]] minor mode is enabled, a new element appears showing the number of errors, warnings and info. @@ -1358,50 +1399,10 @@ A color code is used for the battery status: *Note*: These colors may vary depending on your theme. -**** Powerline separators -It is possible to easily customize the =powerline separator= by setting the -=powerline-default-separator= variable in your =~/.spacemacs= and then -recompiling the modeline. For instance, if you want to set back the separator to -the well-known =arrow= separator add the following snippet to your configuration -file: - -#+BEGIN_SRC emacs-lisp -(defun dotspacemacs/user-config () - "This is were you can ultimately override default Spacemacs configuration. -This function is called at the very end of Spacemacs initialization." - (setq powerline-default-separator 'arrow)) -#+END_SRC - -To save you the time to try all the possible separators provided by the -powerline, here is an exhaustive set of screenshots: - -| Separator | Screenshot | -|--------------+-----------------------------------| -| =alternate= | [[file:img/powerline-alternate.png]] | -| =arrow= | [[file:img/powerline-arrow.png]] | -| =arrow-fade= | [[file:img/powerline-arrow-fade.png]] | -| =bar= | [[file:img/powerline-bar.png]] | -| =box= | [[file:img/powerline-box.png]] | -| =brace= | [[file:img/powerline-brace.png]] | -| =butt= | [[file:img/powerline-butt.png]] | -| =chamfer= | [[file:img/powerline-chamfer.png]] | -| =contour= | [[file:img/powerline-contour.png]] | -| =curve= | [[file:img/powerline-curve.png]] | -| =rounded= | [[file:img/powerline-rounded.png]] | -| =roundstub= | [[file:img/powerline-roundstub.png]] | -| =slant= | [[file:img/powerline-slant.png]] | -| =wave= | [[file:img/powerline-wave.png]] | -| =zigzag= | [[file:img/powerline-zigzag.png]] | -| =nil= | [[file:img/powerline-nil.png]] | - *** All-the-Icons theme If you want to use this theme you need to make sure to install the required fonts from the package repository, see [[https://github.com/domtronn/all-the-icons.el/tree/master/fonts][all-the-icons fonts directory]]. -To change the separator type set the variable -=spaceline-all-the-icons-separator-type=. Supported powerline separators are -=slant=, =wave=, =cup=, =arrow= and =none= (see table above). - *** Custom spaceline theme You can create your own Spaceline theme by setting the variable =dotspacemacs-mode-line-theme= to =custom= and define a function called diff --git a/doc/FAQ.org b/doc/FAQ.org index 2e7218c8b..eac9ad61f 100644 --- a/doc/FAQ.org +++ b/doc/FAQ.org @@ -113,8 +113,9 @@ Install the default font supported by Spacemacs or choose a fixed width font. More information in the font section of the [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/DOCUMENTATION.org][documentation]]. ** The powerline separators are ugly, how can I fix them? -Use the property =:powerline-scale= of the variable =dotspacemacs-default-font=. -See font section of the [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/DOCUMENTATION.org][documentation]] for more details. +Use the property =:separator-scale= of the variable +=dotspacemacs-mode-line-theme=. See mode-line section of the [[https://github.com/syl20bnr/spacemacs/blob/develop/doc/DOCUMENTATION.org][documentation]] for +more details. ** The powerline separators have no anti-aliasing, what can I do? Emacs powerline uses XMP images to draw the separators in a graphical diff --git a/layers/+spacemacs/spacemacs-modeline/funcs.el b/layers/+spacemacs/spacemacs-modeline/funcs.el index 6ce8b2528..d9957f7b6 100644 --- a/layers/+spacemacs/spacemacs-modeline/funcs.el +++ b/layers/+spacemacs/spacemacs-modeline/funcs.el @@ -9,6 +9,24 @@ ;; ;;; License: GPLv3 +(defun spacemacs/get-mode-line-theme-name () + "Return the mode-line theme name." + (if (listp dotspacemacs-mode-line-theme) + (car dotspacemacs-mode-line-theme) + dotspacemacs-mode-line-theme)) + +(defun spacemacs/mode-line-separator () + "Return the separator type for the mode-line. +Return nil if no separator is defined." + (when (listp dotspacemacs-mode-line-theme) + (plist-get (cdr dotspacemacs-mode-line-theme) :separator))) + +(defun spacemacs/mode-line-separator-scale () + "Return the separator scale for the mode-line. +Return nil if no scale is defined." + (when (listp dotspacemacs-mode-line-theme) + (plist-get (cdr dotspacemacs-mode-line-theme) :separator-scale))) + ;; spaceline diff --git a/layers/+spacemacs/spacemacs-modeline/packages.el b/layers/+spacemacs/spacemacs-modeline/packages.el index f5a8a480b..0ae0d8a6d 100644 --- a/layers/+spacemacs/spacemacs-modeline/packages.el +++ b/layers/+spacemacs/spacemacs-modeline/packages.el @@ -21,7 +21,7 @@ )) (defun spacemacs-modeline/post-init-anzu () - (when (eq 'all-the-icons dotspacemacs-mode-line-theme) + (when (eq 'all-the-icons (spacemacs/get-mode-line-theme-name)) (spaceline-all-the-icons--setup-anzu))) (defun spacemacs-modeline/init-fancy-battery () @@ -36,22 +36,22 @@ (setq-default fancy-battery-show-percentage t)))) (defun spacemacs-modeline/post-init-neotree () - (when (eq 'all-the-icons dotspacemacs-mode-line-theme) + (when (eq 'all-the-icons (spacemacs/get-mode-line-theme-name)) (spaceline-all-the-icons--setup-neotree))) (defun spacemacs-modeline/init-spaceline () (use-package spaceline-config - :if (memq dotspacemacs-mode-line-theme '(spacemacs all-the-icons custom)) + :if (memq (spacemacs/get-mode-line-theme-name) '(spacemacs all-the-icons custom)) :init (progn (add-hook 'spacemacs-post-user-config-hook 'spaceline-compile) (add-hook 'spacemacs-post-theme-change-hook 'spacemacs/customize-powerline-faces) (add-hook 'spacemacs-post-theme-change-hook 'powerline-reset) - (setq-default powerline-default-separator 'utf-8) + (setq powerline-default-separator (or (spacemacs/mode-line-separator) 'wave) + powerline-scale (or (spacemacs/mode-line-separator-scale) 1.5) + powerline-height (spacemacs/compute-mode-line-height)) (spacemacs|do-after-display-system-init - (when (and (eq 'utf-8 powerline-default-separator)) - (setq-default powerline-default-separator 'wave)) ;; seems to be needed to avoid weird graphical artefacts with the ;; first graphical client (require 'spaceline) @@ -111,7 +111,7 @@ (spacemacs/get-new-version-lighter-face spacemacs-version spacemacs-new-version)))) (let ((theme (intern (format "spaceline-%S-theme" - dotspacemacs-mode-line-theme)))) + (spacemacs/get-mode-line-theme-name))))) (apply theme spacemacs-spaceline-additional-segments)) ;; Additional spacelines (when (package-installed-p 'helm) @@ -123,7 +123,7 @@ (spacemacs//set-powerline-for-startup-buffers)))) (defun spacemacs-modeline/pre-init-spaceline-all-the-icons () - (when (eq 'all-the-icons dotspacemacs-mode-line-theme) + (when (eq 'all-the-icons (spacemacs/get-mode-line-theme-name)) (spacemacs|use-package-add-hook spaceline-config :pre-config (progn @@ -133,7 +133,15 @@ (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))) + :init + (progn + (setq + spaceline-all-the-icons-separator-type + (or (spacemacs/mode-line-separator) + 'wave) + spaceline-all-the-icons-separator-scale + (or (spacemacs/mode-line-separator-scale) + spaceline-all-the-icons-separator-scale))))) (defun spacemacs-modeline/init-symon () (use-package symon @@ -147,7 +155,7 @@ :evil-leader "tms")))) (defun spacemacs-modeline/init-vim-powerline () - (when (eq 'vim-powerline dotspacemacs-mode-line-theme) + (when (eq 'vim-powerline (spacemacs/get-mode-line-theme-name)) (require 'powerline) (if (display-graphic-p) (setq powerline-default-separator 'arrow) diff --git a/layers/+spacemacs/spacemacs-navigation/funcs.el b/layers/+spacemacs/spacemacs-navigation/funcs.el index 29de7eb1f..95dabe58b 100644 --- a/layers/+spacemacs/spacemacs-navigation/funcs.el +++ b/layers/+spacemacs/spacemacs-navigation/funcs.el @@ -199,7 +199,7 @@ (defun spacemacs//zoom-frm-powerline-reset () (when (fboundp 'powerline-reset) - (setq-default powerline-height (spacemacs/compute-powerline-height)) + (setq-default powerline-height (spacemacs/compute-mode-line-height)) (powerline-reset))) (defun spacemacs//zoom-frm-do (arg) diff --git a/layers/+spacemacs/spacemacs-visual/funcs.el b/layers/+spacemacs/spacemacs-visual/funcs.el index e7869cd21..26d30f5ab 100644 --- a/layers/+spacemacs/spacemacs-visual/funcs.el +++ b/layers/+spacemacs/spacemacs-visual/funcs.el @@ -32,7 +32,7 @@ (defun spacemacs//zoom-frm-powerline-reset () (when (fboundp 'powerline-reset) - (setq-default powerline-height (spacemacs/compute-powerline-height)) + (setq-default powerline-height (spacemacs/compute-mode-line-height)) (powerline-reset))) (defun spacemacs//zoom-frm-do (arg)