Skip to content

Instantly share code, notes, and snippets.

@shitikanth
Last active December 11, 2017 03:21
Show Gist options
  • Save shitikanth/60e7d8dc8f826adf7be8717586abb533 to your computer and use it in GitHub Desktop.
Save shitikanth/60e7d8dc8f826adf7be8717586abb533 to your computer and use it in GitHub Desktop.
Set evil cursors consistent with base 16 themes automatically
(setq base16-evil-cursors
'(("normal" :base0B box)
("insert" :base0C (bar . 2))
("emacs" :base0D (bar . 2))
("hybrid" :base0D (bar . 2))
("replace" :base08 (hbar . 2))
("evilified" :base0A box)
("visual" :base09 (hbar . 2))
("motion" :base0E box)
("lisp" :base0E box)
("iedit" :base08 box)
("iedit-insert" :base08 (bar . 2))))
(defun base16-set-evil-cursor (state color shape)
(set (intern (format "evil-%s-state-cursor" state))
(list color shape)))
(defun base16-update-evil-cursors ()
(let ((current-theme (symbol-name (car custom-enabled-themes))))
(if (string-prefix-p "base16" current-theme)
(let* ((description (symbol-value (intern (concat current-theme "-colors"))))
(theme-colors (cl-loop for (name value) on description by #'cddr
collect (cons name value))))
(cl-loop for (state color style) in base16-evil-cursors
do
(base16-set-evil-cursor state (alist-get color theme-colors color) style)))
;; not base16 theme, restore default spacemacs cursors
(if (functionp (spacemacs/add-evil-cursor))
(cl-loop for (state color shape) in spacemacs-evil-cursors
do (spacemacs/add-evil-cursor state color shape))))
))
;; On spacemacs, there is no need to create a new hook. You can add
;; `base16-update-evil-cursors' to the `spacemacs-post-theme-change-hook'.
(defvar after-load-theme-hook nil
"Hook run after a color theme is loaded using `load-theme'.")
(defadvice load-theme (after run-after-load-theme-hook activate)
"Run `after-load-theme-hook'."
(message (format "Loading theme %s" (ad-get-arg 0)))
(run-hooks 'after-load-theme-hook))
(add-hook 'after-load-theme-hook #'base16-update-evil-cursors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment