I have a snippet called struct
.
And I write text complex_struct
in a snippet field. yasnippet will expand
complex_struct
with the snippet struct
. I have to move backward one
character to avoid this behavior.
So I hope there is an indicator like make cursor change color to red, and style. Or change text face etc.
Here is the snippet code:
# -*- mode: snippet -*-
# name: struct
# key: struct
# --
struct ${1:name} {
$0
};
# -*- mode: snippet -*-
# name: complex_struct
# key: complex_struct
# --
complex struct ${1:name} {
$0
};
When I type text like the following:
complex_struct|
The point is at position (|
).
It will be expanded from snippet struct
instead of complex_struct
. I don't
want to change yasnippet expand detect characters list. Just want to show which
text is expandable (Like struct
in this case).
I have a demo code to change cursor style dynamically:
;; change cursor dynamically when prefix text is expandable.
(defun my-cursor-change-on-snippet ()
;; (yas-next-field-or-maybe-expand)
(if (or yas-triggers-in-field ; FIXME: improve condition
(yas-next-field-will-exit-p))
(progn
(set-cursor-color "red")
(setq cursor-type 'hollow))
(set-cursor-color "cyan")
(setq cursor-type '(hbar . 2))
)
)
(add-hook 'post-command-hook #'my-cursor-change-on-snippet)