diff --git a/init.el b/init.el index 4dac33a..8ee588d 100644 --- a/init.el +++ b/init.el @@ -1210,3 +1210,35 @@ (file-directory-p (helm-get-selection))) (helm-execute-persistent-action) (insert "/"))) + +(setq default-cursor-color (frame-parameter nil 'cursor-colbxuor)) +(setq yasnippet-can-fire-cursor-color "purple") + +;; It will test whether it can expand, if yes, cursor color -> purple. +(defun yasnippet-can-fire-p (&optional field) + (interactive) + (setq yas--condition-cache-timestamp (current-time)) + (let (templates-and-pos) + (unless (and yas-expand-only-for-last-commands + (not (member last-command yas-expand-only-for-last-commands))) + (setq templates-and-pos (if field + (save-restriction + (narrow-to-region (yas--field-start field) + (yas--field-end field)) + (yas--templates-for-key-at-point)) + (yas--templates-for-key-at-point)))) + (and templates-and-pos (first templates-and-pos)))) + +;; Taken from http://pages.sachachua.com/.emacs.d/Sacha.html +(defun sachachua/change-cursor-color-when-can-expand (&optional field) + (interactive) + (when (eq last-command 'self-insert-command) + (set-cursor-color (if (sachachua/can-expand) + yasnippet-can-fire-cursor-color + default-cursor-color)))) + +(defun sachachua/can-expand () + "Return true if right after an expandable thing." + (or (abbrev--before-point) (yasnippet-can-fire-p))) + +(add-hook 'post-command-hook 'sachachua/change-cursor-color-when-can-expand)