Skip to content

Instantly share code, notes, and snippets.

@pcmantz
Created January 10, 2013 22:32
Show Gist options
  • Select an option

  • Save pcmantz/4506396 to your computer and use it in GitHub Desktop.

Select an option

Save pcmantz/4506396 to your computer and use it in GitHub Desktop.
(setq default-cursor-color "green")
(setq yasnippet-can-fire-cursor-color "purple" )
;; It will test whether it can expand, if yes, cursor color -> green.
(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--current-key))
(yas--current-key))))
(and templates-and-pos (first templates-and-pos))))
(defun yasnippet-change-cursor-color-when-can-fire (&optional field)
(interactive)
(set-cursor-color (if (yasnippet-can-fire-p)
yasnippet-can-fire-cursor-color
default-cursor-color)))
; As pointed out by Dmitri, this will make sure it will update color when needed.
(add-hook 'post-command-hook 'yasnippet-change-cursor-color-when-can-fire)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment