-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add hook of yas-next-field-hook #1027
base: master
Are you sure you want to change the base?
Conversation
…ield-hook run-hook-with-args yas-next-field-hook
What sort of things do you use this hook for? What about when the user goes back one field, how should hook elements handle that case? |
|
(cl-defstruct (yas--field (:constructor yas--make-field (number start end parent-field)))
"A field.
NUMBER is the field number.
START and END are mostly buffer markers, but see \"apropos markers-to-points\".
PARENT-FIELD is a `yas--field' this field is nested under, or nil.
MIRRORS is a list of `yas--mirror's
TRANSFORM is a lisp form.
MODIFIED-P is a boolean set to true once user inputs text.
NEXT is another `yas--field' or `yas--mirror' or `yas--exit'.
"
number
start end
parent-field
(mirrors '())
(transform nil)
(modified-p nil)
next
default ;; my added
content
raw
) |
(defun chong-yas-next (active-field snippet)
(when (and (not (yas--field-modified-p active-field))
(yas--field-default active-field)
)
(save-excursion
(let* ((start (yas--field-start active-field))
(end (yas--field-end active-field))
(default (yas--field-default active-field))
(len (- end start))
)
(goto-char start)
(cond
((stringp default)
(insert (yas--restore-escapes default)))
((listp default)
(insert (yas--eval-for-string default))
))))))
(add-hook 'yas-next-field-hook 'chong-yas-next) |
I don't understand, could you say more?
I don't want to change the current behaviour here.
I meant more, how would a hook function even know that the user is moving backwards? |
in the function of open
i cannot remember which character can be used as the mode char. so i can use the snippet
the "r" is the default value. |
this hook will be called before leaving a yas-field. move backward or forward is donnot matter. |
may i add this hook?