This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+spacemacs/spacemacs-ui-visual/packages.el

453 lines
18 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Spacemacs UI Visual Layer packages File
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq spacemacs-ui-visual-packages
'(fancy-battery
golden-ratio
leuven-theme
neotree
smooth-scrolling
spaceline
vi-tilde-fringe
(zoom-frm :location local)))
(defun spacemacs-ui-visual/init-fancy-battery ()
(use-package fancy-battery
:defer t
:init
(progn
(spacemacs|add-toggle mode-line-battery
:status fancy-battery-mode
:on (fancy-battery-mode)
:off (fancy-battery-mode -1)
:documentation "Display battery info in mode-line."
:evil-leader "tmb")
(setq-default fancy-battery-show-percentage t))))
(defun spacemacs-ui-visual/init-golden-ratio ()
(use-package golden-ratio
:defer t
:init
(spacemacs|add-toggle golden-ratio
:status golden-ratio-mode
:on (golden-ratio-mode) (golden-ratio)
:off (golden-ratio-mode -1) (balance-windows)
:documentation "Resize the focused window using the golden ratio."
:evil-leader "tg")
:config
(progn
(setq golden-ratio-exclude-modes '("bs-mode"
"calc-mode"
"ediff-mode"
"dired-mode"
"gud-mode"
"gdb-locals-mode"
"gdb-registers-mode"
"gdb-breakpoints-mode"
"gdb-threads-mode"
"gdb-frames-mode"
"gdb-inferior-io-mode"
"gud-mode"
"gdb-inferior-io-mode"
"gdb-disassembly-mode"
"gdb-memory-mode"
"restclient-mode"
"speedbar-mode"
))
(add-to-list 'golden-ratio-exclude-buffer-regexp "^\\*[hH]elm.*")
(setq golden-ratio-extra-commands
(append golden-ratio-extra-commands
'(ace-window
ace-delete-window
ace-select-window
ace-swap-window
ace-maximize-window
avy-pop-mark
evil-avy-goto-word-or-subword-1
evil-avy-goto-line
windmove-left
windmove-right
windmove-up
windmove-down
evil-window-delete
evil-window-split
evil-window-vsplit
evil-window-left
evil-window-right
evil-window-up
evil-window-down
evil-window-bottom-right
evil-window-top-left
evil-window-mru
evil-window-next
evil-window-prev
evil-window-new
evil-window-vnew
evil-window-rotate-upwards
evil-window-rotate-downwards
evil-window-move-very-top
evil-window-move-far-left
evil-window-move-far-right
evil-window-move-very-bottom
select-window-0
select-window-1
select-window-2
select-window-3
select-window-4
select-window-5
select-window-6
select-window-7
select-window-8
select-window-9
buf-move-left
buf-move-right
buf-move-up
buf-move-down
ess-eval-buffer-and-go
ess-eval-function-and-go
ess-eval-line-and-go)))
;; Disable auto-resizing for some buffers
(defun spacemacs/no-golden-ratio-for-buffers (bufname)
"Disable golden-ratio if BUFNAME is the name of a visible buffer."
(and (get-buffer bufname) (get-buffer-window bufname 'visible)))
(defun spacemacs/no-golden-ratio-guide-key ()
"Disable golden-ratio for guide-key popwin buffer."
(or (spacemacs/no-golden-ratio-for-buffers " *guide-key*")
(spacemacs/no-golden-ratio-for-buffers " *popwin-dummy*")))
(add-to-list 'golden-ratio-inhibit-functions
'spacemacs/no-golden-ratio-guide-key)
(add-to-list 'golden-ratio-exclude-buffer-names " *NeoTree*")
(add-to-list 'golden-ratio-exclude-buffer-names "*LV*")
(add-to-list 'golden-ratio-exclude-buffer-names " *which-key*")
(spacemacs|diminish golden-ratio-mode "" " g"))))
(defun spacemacs-ui-visual/init-leuven-theme ()
(use-package leuven-theme
:defer t
:init (setq org-fontify-whole-heading-line t)))
(defun spacemacs-ui-visual/init-neotree ()
(use-package neotree
:defer t
:commands neo-global--window-exists-p
:init
(progn
(setq neo-window-width 32
neo-create-file-auto-open t
neo-banner-message nil
neo-show-updir-line nil
neo-mode-line-type 'neotree
neo-smart-open t
neo-dont-be-alone t
neo-persist-show nil
neo-show-hidden-files t
neo-auto-indent-point t
neo-modern-sidebar t
neo-vc-integration nil)
(defun spacemacs/neotree-expand-or-open ()
"Collapse a neotree node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(if (file-directory-p node)
(progn
(neo-buffer--set-expand node t)
(neo-buffer--refresh t)
(when neo-auto-indent-point
(next-line)
(neo-point-auto-indent)))
(call-interactively 'neotree-enter)))))
(defun spacemacs/neotree-collapse ()
"Collapse a neotree node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(when (file-directory-p node)
(neo-buffer--set-expand node nil)
(neo-buffer--refresh t))
(when neo-auto-indent-point
(neo-point-auto-indent)))))
(defun spacemacs/neotree-collapse-or-up ()
"Collapse an expanded directory node or go to the parent node."
(interactive)
(let ((node (neo-buffer--get-filename-current-line)))
(when node
(if (file-directory-p node)
(if (neo-buffer--expanded-node-p node)
(spacemacs/neotree-collapse)
(neotree-select-up-node))
(neotree-select-up-node)))))
(defun neotree-find-project-root ()
(interactive)
(if (neo-global--window-exists-p)
(neotree-hide)
(let ((origin-buffer-file-name (buffer-file-name)))
(neotree-find (projectile-project-root))
(neotree-find origin-buffer-file-name))))
(defun spacemacs//neotree-key-bindings ()
"Set the key bindings for a neotree buffer."
(evilified-state-evilify-map neotree-mode-map
:mode neotree-mode
:bindings
(kbd "TAB") 'neotree-stretch-toggle
(kbd "RET") 'neotree-enter
(kbd "|") 'neotree-enter-vertical-split
(kbd "-") 'neotree-enter-horizontal-split
(kbd "?") 'evil-search-backward
(kbd "c") 'neotree-create-node
(kbd "d") 'neotree-delete-node
(kbd "gr") 'neotree-refresh
(kbd "h") 'spacemacs/neotree-collapse-or-up
(kbd "H") 'neotree-select-previous-sibling-node
(kbd "J") 'neotree-select-down-node
(kbd "K") 'neotree-select-up-node
(kbd "l") 'spacemacs/neotree-expand-or-open
(kbd "L") 'neotree-select-next-sibling-node
(kbd "q") 'neotree-hide
(kbd "r") 'neotree-rename-node
(kbd "R") 'neotree-change-root
(kbd "s") 'neotree-hidden-file-toggle))
(spacemacs/set-leader-keys
"ft" 'neotree-toggle
"pt" 'neotree-find-project-root))
:config
(spacemacs//neotree-key-bindings)))
(defun spacemacs-ui-visual/init-smooth-scrolling ()
(use-package smooth-scrolling
:init
(progn
(setq smooth-scroll-margin 5)
(spacemacs|add-toggle smooth-scrolling
:status smooth-scrolling-mode
:on (progn
(smooth-scrolling-mode)
(enable-smooth-scroll-for-function previous-line)
(enable-smooth-scroll-for-function next-line)
(enable-smooth-scroll-for-function isearch-repeat))
:off (progn
(smooth-scrolling-mode -1)
(disable-smooth-scroll-for-function previous-line)
(disable-smooth-scroll-for-function next-line)
(disable-smooth-scroll-for-function isearch-repeat))
:documentation "Smooth scrolling."
:evil-leader "tv")
2016-03-03 10:44:00 +00:00
(when dotspacemacs-smooth-scrolling
(spacemacs/toggle-smooth-scrolling-on))
;; add hooks here only for emacs built-in packages that are not owned
;; by a layer.
(defun spacemacs//unset-scroll-margin ()
"Set scroll-margin to zero."
(setq-local scroll-margin 0))
(spacemacs/add-to-hooks 'spacemacs//unset-scroll-margin
'(messages-buffer-mode-hook)))))
(defun spacemacs-ui-visual/init-spaceline ()
(use-package spaceline-config
:init
(progn
(spacemacs|do-after-display-system-init
(setq-default powerline-default-separator
(if (display-graphic-p) 'wave 'utf-8)))
(defun spacemacs//set-powerline-for-startup-buffers ()
"Set the powerline for buffers created when Emacs starts."
(dolist (buffer '("*Messages*" "*spacemacs*" "*Compile-Log*"))
(when (and (get-buffer buffer)
(configuration-layer/package-usedp 'spaceline))
(spacemacs//restore-powerline buffer))))
(add-hook 'emacs-startup-hook
'spacemacs//set-powerline-for-startup-buffers))
:config
(progn
(defun spacemacs/customize-powerline-faces ()
"Alter powerline face to make them work with more themes."
(set-face-attribute 'powerline-inactive2 nil
:inherit 'font-lock-comment-face))
(spacemacs/customize-powerline-faces)
(dolist (spec '((minor-modes "tmm")
(major-mode "tmM")
(version-control "tmv")
(new-version "tmV")
(point-position "tmp")
(org-clock "tmc")))
(let* ((segment (car spec))
(status-var (intern (format "spaceline-%S-p" segment))))
(eval `(spacemacs|add-toggle ,(intern (format "mode-line-%S" segment))
:status ,status-var
:on (setq ,status-var t)
:off (setq ,status-var nil)
:documentation ,(format "Show %s in the mode-line."
(replace-regexp-in-string
"-" " " (format "%S" segment)))
:evil-leader ,(cadr spec)))))
(setq spaceline-org-clock-p nil)
(defun spacemacs//evil-state-face ()
Use evil in holy-mode Motivation While disabling Evil in holy-mode makes its implementation shorter and sounds elegant on the paper, in practice it puts a big burden on the configuration parts which need to know if Evil is enable or not. This is a bad separation of concerns and the bunch of fixes that we were forced to do in the past weeks shows this issue. Those fixes were about removing the knowledge of the activation of Evil by implementing new dispatching functions to be used by layers, this is cumbersome and makes Spacemacs layer configuration more subtle which is not good. There was additional bad consequences of the removal of Evil state like the impossibility to use Evil lisp state or iedit states, or we would have been forced to implement a temporary activation of Evil which is awkward. Instead I reintroduce Evil as the central piece of Spacemacs design thus Evil is now re-enabled in holy-mode. It provides the abstraction we need to isolate editing styles and be able to grow the Spacemacs configuration coverage sanely. Layers don't need to check whether the holy mode is active or not and they don't need to know if Evil is available (it is always available). We also don't need to write additional dispatching functions, this is the job of Evil, and I think it provides everything for this. Ideally configuration layer should be implemented with only Evil in mind and the holy-mode (and hybrid-mode) should magically make it work for Emacs style users, for instance we can freely use `evil-insert-state` anywhere in the code without any guard. Evil is now even more part of Spacemacs, we can really say that Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs needed this stable API to continue on the right track. While these changes should be rather transparent to the user, I'm sorry for this experimental period, I failed to see all the implications of such a change, I was just excited about the possibility to make Evil optional. The reality is that Spacemacs has to embrace it and keep its strong position on being Emacs+Evil at the core. Implementation - insert, motion and normal states are forced to emacs state using an advice on `evil-insert-state`, `evil-motion-state` and `evil-normal-state` respectively. These functions can be used freely in the layer configuration. - A new general hook `spacemacs-editing-style-hook` allow to hook any code that need to be configured based on the editing style. Functions hooked to this hook takes the current style as parameter, this basically generalize the hook used to setup hjkl navigation bindings. - ESC has been removed from the emacs state map. - Revert unneeded changes - Revert "evil: enter insert-state only from normal-state" commit bdd702dfbe302206bbc989c7a0832daba087a781. - Revert "avoid being evil in deft with emacs editing style" commit f3a16f49ed27cc8cf05f23f93b006d6e04235381. Additional changes All editing style packages have been moved to a layer called `spacemacs-editing-styles` Notes I did not have time to attack hybrid mode, I should be able to do it later.
2016-03-13 23:41:18 +00:00
(let ((state (if (eq 'operator evil-state) evil-previous-state evil-state)))
(intern (format "spacemacs-%S-face" state))))
(setq spaceline-highlight-face-func 'spacemacs//evil-state-face)
(let ((unicodep (dotspacemacs|symbol-value
dotspacemacs-mode-line-unicode-symbols)))
(setq spaceline-window-numbers-unicode unicodep)
(setq spaceline-workspace-numbers-unicode unicodep))
(defpowerline spacemacs-powerline-new-version
(propertize
spacemacs-version-check-lighter
'mouse-face 'mode-line-highlight
'help-echo (format "New version %s | Click with mouse-1 to update"
spacemacs-new-version)
'local-map (let ((map (make-sparse-keymap)))
(define-key map
[mode-line down-mouse-1]
(lambda (event)
(interactive "@e")
(if (yes-or-no-p
(format (concat "Do you want to update to the newest "
"version %s ?") spacemacs-new-version))
(progn
(spacemacs/switch-to-version spacemacs-new-version))
(message "Update aborted."))))
map)))
(spaceline-define-segment new-version
(spacemacs-powerline-new-version
(spacemacs/get-new-version-lighter-face
spacemacs-version spacemacs-new-version))
:when spacemacs-new-version)
(spaceline-spacemacs-theme '(new-version :when active))
(spaceline-helm-mode t)
(when (configuration-layer/package-usedp 'info+)
(spaceline-info-mode t))
(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)))
(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))))))))
(add-hook 'spaceline-pre-hook 'spacemacs//prepare-diminish))))
(defun spacemacs-ui-visual/init-vi-tilde-fringe ()
(spacemacs|do-after-display-system-init
(use-package vi-tilde-fringe
:init
(progn
(global-vi-tilde-fringe-mode)
(spacemacs|add-toggle vi-tilde-fringe
:status vi-tilde-fringe-mode
:on (global-vi-tilde-fringe-mode)
:off (global-vi-tilde-fringe-mode -1)
:documentation
"Globally display a ~ on empty lines in the fringe."
:evil-leader "T~")
;; don't enable it on spacemacs home buffer
(with-current-buffer "*spacemacs*"
(vi-tilde-fringe-mode -1))
;; after a major mode is loaded, check if the buffer is read only
;; if so, disable vi-tilde-fringe-mode
(add-hook 'after-change-major-mode-hook (lambda ()
(when buffer-read-only
(vi-tilde-fringe-mode -1)))))
:config
(spacemacs|hide-lighter vi-tilde-fringe-mode))))
(defun spacemacs-ui-visual/init-zoom-frm ()
(use-package zoom-frm
:commands (zoom-frm-unzoom
zoom-frm-out
zoom-frm-in)
:init
(progn
(spacemacs|define-transient-state zoom-frm
:title "Zoom Frame Transient State"
:doc "
[_+_/_=_] zoom frame in [_-_] zoom frame out [_0_] reset zoom [_q_] quit"
:bindings
("+" spacemacs/zoom-frm-in)
("=" spacemacs/zoom-frm-in)
("-" spacemacs/zoom-frm-out)
("0" spacemacs/zoom-frm-unzoom)
("q" nil :exit t))
(spacemacs/set-leader-keys "zf" 'spacemacs/zoom-frm-transient-state/body)
(defun spacemacs//zoom-frm-powerline-reset ()
(when (fboundp 'powerline-reset)
(setq-default powerline-height (spacemacs/compute-powerline-height))
(powerline-reset)))
(defun spacemacs//zoom-frm-do (arg)
"Perform a zoom action depending on ARG value."
(let ((zoom-action (cond ((eq arg 0) 'zoom-frm-unzoom)
((< arg 0) 'zoom-frm-out)
((> arg 0) 'zoom-frm-in)))
(fm (cdr (assoc 'fullscreen (frame-parameters))))
(fwp (* (frame-char-width) (frame-width)))
(fhp (* (frame-char-height) (frame-height))))
(when (equal fm 'maximized)
(toggle-frame-maximized))
(funcall zoom-action)
(set-frame-size nil fwp fhp t)
(when (equal fm 'maximized)
(toggle-frame-maximized))))
(defun spacemacs/zoom-frm-in ()
"zoom in frame, but keep the same pixel size"
(interactive)
(spacemacs//zoom-frm-do 1)
(spacemacs//zoom-frm-powerline-reset))
(defun spacemacs/zoom-frm-out ()
"zoom out frame, but keep the same pixel size"
(interactive)
(spacemacs//zoom-frm-do -1)
(spacemacs//zoom-frm-powerline-reset))
(defun spacemacs/zoom-frm-unzoom ()
"Unzoom current frame, keeping the same pixel size"
(interactive)
(spacemacs//zoom-frm-do 0)
(spacemacs//zoom-frm-powerline-reset))
;; Font size, either with ctrl + mouse wheel
(global-set-key (kbd "<C-wheel-up>") 'spacemacs/zoom-frm-in)
(global-set-key (kbd "<C-wheel-down>") 'spacemacs/zoom-frm-out))))