Skip to content

Instantly share code, notes, and snippets.

@thomasf
Created August 3, 2014 10:30
Show Gist options
  • Save thomasf/10204869160bdb039ff5 to your computer and use it in GitHub Desktop.
Save thomasf/10204869160bdb039ff5 to your computer and use it in GitHub Desktop.
cursor-style.el
(defvar my-normal-cursor-type 'bar)
(defun cursor-style-update-action ()
(when (bound-and-true-p cua-normal-cursor-color)
(let* ((current-cursor-color (cdr (assq 'cursor-color (frame-parameters))))
(cursor-style (cond
((bound-and-true-p region-bindings-mode) (cons "#d33682" '(bar . 8)))
((bound-and-true-p god-local-mode) (cons "#268bd2" 'box))
((bound-and-true-p buffer-read-only) (cons "#859900" '(hbar . 4)))
(t (cons cua-normal-cursor-color my-normal-cursor-type)))))
(unless (equal (car cursor-style) current-cursor-color)
(set-cursor-color (car cursor-style)))
(unless (equal (cdr cursor-style) cursor-type)
(setq cursor-type (cdr cursor-style))))))
(defun cursor-style-update ()
(run-with-idle-timer 0.2 nil 'cursor-style-update-action))
(hook-into-modes 'cursor-style-update
'(activate-mark-hook
deactivate-mark-hook
region-bindings-mode-hook
window-configuration-change-hook
minibuffer-setup-hook
minibuffer-exit-hook
god-mode-enabled-hook
god-mode-disabled-hook
god-local-mode-hook
read-only-mode-hook
after-change-major-mode-hook
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment