Took some time to find the function that did the checking whether or not it can expand, but was 'lucky' enough to find it eventually.
The key is that this function would normally expand, or otherwise, perform the fallback behavior. I cloned this function and set the cursor colors in those places instead.
And, surprisingly, it actually does not slow down at all.
;; 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))))
(set-cursor-color (if (and templates-and-pos (first templates-and-pos))
"green" "red"))))
; As pointed out by Dmitri, this will make sure it will update color when needed.
(add-hook 'post-command-hook 'yasnippet-can-fire-p)
Added this to my lisp collection (I was actually thinking that this would be useful as well).
Update: In latest version of yasnippet [from august 2014, from 0.8.1
], yas--current-key
function has been renamed into yas--templates-for-key-at-point
. cf Issue
name:
attributes are very helpful for yasnippet search autocompletion. – Sugar