2017-04-12 03:09:27 +00:00
|
|
|
|
;;; funcs.el --- Spacemacs Mode-line Layer functions File
|
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2017-04-12 03:09:27 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
;;
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
;;
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2017-04-12 03:09:27 +00:00
|
|
|
|
|
2018-01-17 03:59:29 +00:00
|
|
|
|
(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."
|
2020-09-20 23:04:11 +00:00
|
|
|
|
(let ((separator (when (listp dotspacemacs-mode-line-theme)
|
|
|
|
|
(plist-get (cdr dotspacemacs-mode-line-theme) :separator))))
|
|
|
|
|
;; `utf-8' separator is not supported by all-the-icons font
|
|
|
|
|
;; we force `utf-8' to be `arrow'
|
|
|
|
|
(if (and (eq 'utf-8 separator)
|
|
|
|
|
(eq 'all-the-icons (spacemacs/get-mode-line-theme-name)))
|
|
|
|
|
'arrow
|
|
|
|
|
separator)))
|
2018-01-17 03:59:29 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/mode-line-separator-scale ()
|
|
|
|
|
"Return the separator scale for the mode-line.
|
|
|
|
|
Return nil if no scale is defined."
|
2018-06-03 05:48:26 +00:00
|
|
|
|
(if (eq 'utf-8 (spacemacs/mode-line-separator))
|
|
|
|
|
1
|
|
|
|
|
(when (listp dotspacemacs-mode-line-theme)
|
|
|
|
|
(plist-get (cdr dotspacemacs-mode-line-theme) :separator-scale))))
|
2018-01-17 03:59:29 +00:00
|
|
|
|
|
2017-04-12 03:09:27 +00:00
|
|
|
|
|
|
|
|
|
;; spaceline
|
|
|
|
|
|
2020-09-19 19:17:33 +00:00
|
|
|
|
(defun spacemacs/spaceline-config-startup-hook ()
|
|
|
|
|
"Install a transient hook to delay spaceline config after Emacs starts."
|
|
|
|
|
(spacemacs|add-transient-hook window-configuration-change-hook
|
|
|
|
|
(lambda () (spacemacs/spaceline-config-startup)) lazy-load-spaceline))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/spaceline-config-startup ()
|
|
|
|
|
"Compile the spaceline config."
|
|
|
|
|
(setq spaceline-byte-compile t)
|
|
|
|
|
;; this must also be set in this hook because
|
|
|
|
|
;; (spacemacs/compute-mode-line-height) returns incorrect
|
|
|
|
|
;; results if it is called before the display system is
|
|
|
|
|
;; initialized. see issue for details:
|
|
|
|
|
;; https://github.com/syl20bnr/spacemacs/issues/10181
|
|
|
|
|
(setq powerline-height
|
|
|
|
|
(spacemacs/compute-mode-line-height))
|
|
|
|
|
(spaceline-compile))
|
|
|
|
|
|
|
|
|
|
|
2017-04-12 03:09:27 +00:00
|
|
|
|
(defun spacemacs/customize-powerline-faces ()
|
|
|
|
|
"Alter powerline face to make them work with more themes."
|
|
|
|
|
(when (boundp 'powerline-inactive2)
|
|
|
|
|
(set-face-attribute 'powerline-inactive2 nil
|
|
|
|
|
:inherit 'font-lock-comment-face)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//evil-state-face ()
|
|
|
|
|
(let ((state (if (eq 'operator evil-state) evil-previous-state evil-state)))
|
|
|
|
|
(intern (format "spacemacs-%S-face" state))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//restore-powerline (buffer)
|
|
|
|
|
"Restore the powerline in buffer"
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(setq-local mode-line-format (default-value 'mode-line-format))
|
|
|
|
|
(powerline-set-selected-window)
|
|
|
|
|
(powerline-reset)))
|
|
|
|
|
|
2018-06-14 05:10:44 +00:00
|
|
|
|
(defun spacemacs//restore-buffers-powerline ()
|
2019-04-15 06:54:35 +00:00
|
|
|
|
"Restore the powerline in the buffers.
|
|
|
|
|
Excluding which-key."
|
2018-06-14 05:10:44 +00:00
|
|
|
|
(dolist (buffer (buffer-list))
|
2019-04-15 06:54:35 +00:00
|
|
|
|
(unless (string-match-p "\\*which-key\\*" (buffer-name buffer))
|
|
|
|
|
(spacemacs//restore-powerline buffer))))
|
2017-04-12 03:09:27 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//prepare-diminish ()
|
|
|
|
|
(when spaceline-minor-modes-p
|
|
|
|
|
(let ((unicodep (dotspacemacs|symbol-value
|
|
|
|
|
dotspacemacs-mode-line-unicode-symbols)))
|
|
|
|
|
(setq spaceline-minor-modes-separator
|
|
|
|
|
(if unicodep (if (display-graphic-p) "" " ") "|"))
|
|
|
|
|
(dolist (mm spacemacs--diminished-minor-modes)
|
|
|
|
|
(let ((mode (car mm)))
|
|
|
|
|
(when (and (boundp mode) (symbol-value mode))
|
|
|
|
|
(let* ((unicode (cadr mm))
|
|
|
|
|
(ascii (caddr mm))
|
|
|
|
|
(dim (if unicodep
|
|
|
|
|
unicode
|
|
|
|
|
(if ascii ascii unicode))))
|
|
|
|
|
(diminish mode dim))))))))
|
2018-01-12 04:53:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 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)))))
|