TheBB / spaceline

Powerline theme from Spacemacs
GNU General Public License v3.0
539 stars 60 forks source link

+TITLE: Spaceline

[[https://melpa.org/#/spaceline][http://melpa.org/packages/spaceline-badge.svg]] [[https://stable.melpa.org/#/spaceline][https://stable.melpa.org/packages/spaceline-badge.svg]] [[https://travis-ci.org/TheBB/spaceline][https://travis-ci.org/TheBB/spaceline.svg]] [[https://github.com/syl20bnr/spacemacs][file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]]

This package provides features for three kinds of users.

  1. You just want to use the Spacemacs mode-line theme and forget about it.
  2. You want to use something similar to the Spacemacs mode-line theme, but with a handful of easy tweaks.
  3. You want an easy-to-use library for building your own mode-line from scratch, and you think the Spacemacs theme looks good.

The functionality for each are described in the following sections.

The files in this package are organized as follows. Choose which you want to load based on what you want to do.

+BEGIN_SRC emacs-lisp

(require 'spaceline-config) (spaceline-spacemacs-theme)

+END_SRC

The package comes bundled with two themes:

In addition, Spaceline supports custom themes for Info+ and Helm. These can be enabled through global minor modes:

These are also defined in =spaceline-config.el=.

** Optional dependencies These themes include several segments that depend on third-party packages. If these packages are not installed, these segments will be invisible and not show any output. As such, they can be considered /optional/ dependencies.

Here follows a brief list of these dependencies. For more information consult the upstream sources.

*** Persp-mode [[https://github.com/Bad-ptr/persp-mode.el][Persp-mode]] is a powerful workspace-like package. Spaceline shows the current workspace name.

*** Eyebrowse [[https://github.com/wasamasa/eyebrowse][Eyebrowse]] is a simpler workspace-like package. If it is installed, The Spacemacs theme will show the current workspace number. The Emacs theme uses the workspace number as a fallback for the perspective name: thus if persp-mode is installed, the Eyebrowse workspace will not be shown.

*** Winum [[https://github.com/deb0ch/winum.el][Winum]] shows a number for each window, and it works with both themes.

To prevent =winum= from inserting its own number in the mode-line, you have to set =winum-auto-setup-mode-line= to nil before activating =winum-mode=:

+BEGIN_SRC emacs-lisp

(setq winum-auto-setup-mode-line nil) (winum-mode)

+END_SRC

*** Auto-compile [[https://github.com/tarsius/auto-compile][Auto-compile]] automatically compiles Emacs Lisp files on save if there is an older byte-compiled file. Spaceline shows warnings when they occur.

*** Anzu [[https://github.com/syohex/emacs-anzu][Anzu]] shows the current match and the total number of matches while searching.

Note that Anzu inserts itself in the modeline, to let spaceline handle the modeline, make sure to =(setq anzu-cons-mode-line-p nil)= or customize it.

*** Flycheck [[https://github.com/flycheck/flycheck/][Flycheck]] is a powerful syntax-checking package. Spaceline shows errors, warnings and notifications from it.

*** ERC [[http://www.emacswiki.org/emacs/ERC][ERC]] is an IRC client built in to Emacs. Spaceline shows channels with new messages if you have =erc-track= turned on.

*** Org Spaceline shows the currently clocking [[http://orgmode.org/][org-mode]] task.

*** Org-pomodoro Spaceline integrates with [[HTtps://github.com/lolownia/org-pomodoro][org-pomodoro]] by showing its clocks.

*** Python virtual environments The currently active environments as reported by [[https://github.com/proofit404/pyenv-mode][pyenv-mode]] or [[https://github.com/jorgenschaefer/pyvenv][pyvenv]] are shown in Spaceline.

*** Nyan cat [[https://github.com/TeMPOraL/nyan-mode][Nyan-mode]] shows the current position in the buffer with kittens and rainbows.

*** Fancy battery [[https://github.com/lunaryorn/fancy-battery.el][Fancy-battery]] shows battery information in the modeline.

*** Evil [[https://bitbucket.org/lyro/evil/wiki/Home][Evil]] makes Emacs behave like Vim. The first segment in the Spacemacs theme shows the current Evil state if all the other dependencies do not report information (i.e. no perspective, workspace or window number). The Emacs theme does not include any information from Evil.

You can color the modeline according to the current Evil state by setting =spaceline-highlight-face-func= to =spaceline-highlight-face-evil-state=.

** Troubleshooting There are a number of reasons why Spaceline might look different on your setup compared to Spacemacs proper. Some of the most important ones are addressed here.

** Turning segments on and off Each segment has a variable =spaceline-NAME-p= that can switch the segment off by setting it to =nil=. There are also three convenient interactive functions for toggling:

These can be bound to whichever keys you like.

Here is a complete list of segments bundled with Spacemacs.

In addition, the following segments are defined, but are not used in the default themes.

For the custom helm modeline, the following segments are used.

For the custom info modeline, the following segments are used.

** The highlight face The highlight face is the face that (by default) is a sharp orange, used e.g. by the HUD segment on the far right, and the first segment on the left (note that it may be invisible if you are using the Spacemacs theme but not some of its optional dependencies). The actual face used as a highlight face is determined by a function, which can be configured by setting the value of =spaceline-highlight-face-func=. Spaceline comes with three choices, but of course you can write your own:

Note that the highlight face is only used in the active window.

** Other faces In the active window, the mode-line will use these faces:

And in inactive windows:

To override this, you can set the variable =spaceline-face-func=. This should be a function that accepts two arguments and returns a face symbol. The arguments are:

If this function is not set, Spaceline delegates the highlight face to =spaceline-highlight-face-func= (see above), and picks the others according to the above scheme.

** Powerline separators Set =powerline-default-separator= to configure this. The docstring for that variable enumerates the choices.

Each separator comes in two directions: left and right. The variables =spaceline-separator-dir-left= and =spaceline-separator-dir-right= specify which directions to alternate between on the left and right side, respectively.

By default these variables are set to =nil=, which means Spaceline will choose the directions that look best for your chosen separator style. However, you can set to override this, for example:

+BEGIN_SRC emacs-lisp

(setq spaceline-separator-dir-left '(left . left)) (setq spaceline-separator-dir-right '(right . right))

+END_SRC

Note that you must recompile the modelines after changing the separators, by calling =M-x spaceline-compile=.

** Hooks The hook =spaceline-pre-hook= is executed before rendering the modeline. Don’t put any performance-intensive functions here!

** Unicode numbers By default, Spacemacs displays window numbers and workspace numbers in nice unicode symbols. To do this in Spaceline, set =spaceline-window-numbers-unicode= or =spaceline-workspace-numbers-unicode= to true, respectively.

Spacemacs also does this with most minor modes. This is a feature that has not been ported to Spaceline. To do this, use [[https://github.com/emacsmirror/diminish][Diminish]].

** Minor modes separator To configure the separator between the minor modes, use =spaceline-minor-modes-separator=.

** Org clock The displayed value of the =org-clock= segment is determined by the function =org-clock-get-clock-string= by default. To configure another function, use =spaceline-org-clock-format-function=.

** Segments A /segment/ is any part of the mode-line that produces some kind of visible output. Typically, segments have been defined ahead of time using =spaceline-define-segment=, in which case the segment is referred to by a symbol, but segments may also be literals (strings or numbers, say) or lists of other segments.

These are all valid segments, provided =my-segment= has been defined:

+BEGIN_SRC emacs-lisp

my-segment "alfa" (my-segment 89)

+END_SRC

Segments may also have properties associated with them. Spaceline supports a variety of properties. They can be applied as follows, for a ‘singleton’ segment:

+BEGIN_SRC emacs-lisp

(my-segment :prop-a value-a :prop-b value-b)

+END_SRC

Or for a list of segments:

+BEGIN_SRC emacs-lisp

((my-segment 89) :prop-a value-a :prop-b value-b)

+END_SRC

** Defining a segment Use =spaceline-define-segment= to define a segment and associate it to a symbol.

+BEGIN_SRC emacs-lisp

(spaceline-define-segment name "Docstring" ;; A single form whose value is the value of the segment. ;; It may return a string, an image or a list of such. (when condition output)

;; Additional keyword properties go here
:prop-a value-a
:prop-b value-b)

+END_SRC

In addition to storing the segment, this macro produces a variable called =spaceline-NAME-p= whose value may be set to switch the segment off or on manually. Three interactive functions are also defined:

These are convenient to bind to keys, and they do what it says on the tin.

Note that if you redefine a segment, you more than likely have to recompile the modelines with =M-x spaceline-compile= for the changes to take effect.

** Properties The valid properties are

All of these are valid both in =spaceline-define-segment= as well as directly in the segment spec, with the excption of =:when=.

Additionally, =spaceline-define-segment= allows two additional properties.

The properties which take effect for any given segment are, in order of priority:

The exceptions are =:when=, which must be true on all levels for a segment to be displayed, and =:fallback= which does not pass through from the parent segment.

** Bindings When evaluating a segment, its =:when= condition or its =:face= property, the following bindings are available for convenience.

Note that the segment code runs in an environment with many local variables, therefore it’s a good idea to write segments as pure functions that do not change state.

** Compiling a mode-line Finally, call the function =spaceline-compile=. It accepts three arguments: a modeline name, and two lists of segments, for the left and right sides.

This produces a function =spaceline-ml-NAME= that evaluates the mode-line. To use it, set =mode-line-format= to

+BEGIN_SRC emacs-lisp

("%e" (:eval (spaceline-ml-NAME)))

+END_SRC

If you do not specify a name, the modeline will be installed as =main=.

If you do not specify segment lists, it will either recompile the given modeline with the segments specified last time, or recompile /all/ modelines if the name is not specified.

When called interactively, the latter behaviour takes effect, that is, all modelines are recompiled.

The variable =spaceline-byte-compile= decides whether the resulting function will be byte-compiled. This is recommended for regular usage, as it involves potentially significant performance benefits.

For instance, to use Spacemac's mode-line definition as a starting point to your own, add this to your =.emacs= or =.spacemacs= and tweak it:

+BEGIN_SRC emacs-lisp

(spaceline-compile ; left side '(((persp-name workspace-number window-number) :fallback evil-state :face highlight-face :priority 100) (anzu :priority 95) auto-compile ((buffer-modified buffer-size buffer-id remote-host) :priority 98) (major-mode :priority 79) (process :when active) ((flycheck-error flycheck-warning flycheck-info) :when active :priority 89) (minor-modes :when active :priority 9) (mu4e-alert-segment :when active) (erc-track :when active) (version-control :when active :priority 78) (org-pomodoro :when active) (org-clock :when active) nyan-cat) ; right side '(which-function (python-pyvenv :fallback python-pyenv) (purpose :priority 94) (battery :when active) (selection-info :priority 95) input-method ((buffer-encoding-abbrev point-position line-column) :separator " | " :priority 96) (global :when active) (buffer-position :priority 99) (hud :priority 99)))

+END_SRC