Skip to content

Conversation

@ChongQing520
Copy link

may i add this hook?

@npostavs
Copy link
Collaborator

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?

@ChongQing520
Copy link
Author

ChongQing520 commented Dec 23, 2019

  1. What sort of things do you use this hook for?

    I only want a default value when user press the <tab>.

  2. What about when the user goes back one field,

    it can restore the previous text , or change to another value.

  3. how should hook elements handle that case?

    something he want or nothing.

@ChongQing520
Copy link
Author

(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
  )

@ChongQing520
Copy link
Author

(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)

@npostavs
Copy link
Collaborator

1. I only want a default value when user press the <tab>.

I don't understand, could you say more?

2\. What about when the user goes back one field,
    it can restore the previous text , or change to another value.

I don't want to change the current behaviour here.

3\. how should hook elements handle that case?
    something he want  or nothing.

I meant more, how would a hook function even know that the user is moving backwards?

@ChongQing520
Copy link
Author

in the function of open

fopen(char * fileName , char* mode)

i cannot remember which character can be used as the mode char.

so i can use the snippet

fopen(${1:char * filename},${2: r:read  w:write b:binary @"r"@})

the "r" is the default value.

@ChongQing520
Copy link
Author

What about when the user goes back one field.
how would a hook function even know that the user is moving backwards?

this hook will be called before leaving a yas-field.

move backward or forward is donnot matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants