exit-snippet mostly implemented.

This commit is contained in:
Zhang Chiyuan 2008-03-03 16:11:55 +00:00
parent aa7b6f0a91
commit eee6a51740

View File

@ -249,14 +249,20 @@ will be deleted before inserting template."
;; Step 5: Create fields ;; Step 5: Create fields
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward yas/field-regexp nil t) (while (re-search-forward yas/field-regexp nil t)
(let ((number (match-string-no-properties 1)))
(if (and number
(string= "0" number))
(progn
(replace-match "")
(yas/snippet-exit-marker-set
snippet
(copy-marker (point) t)))
(yas/snippet-add-field (yas/snippet-add-field
snippet snippet
(yas/snippet-field-new (yas/snippet-field-new
(make-overlay (match-beginning 0) (match-end 0)) (make-overlay (match-beginning 0) (match-end 0))
(if (match-string-no-properties 1) (and number (string-to-number number))
(string-to-number (match-string-no-properties 1)) (match-string-no-properties 2))))))
nil)
(match-string-no-properties 2))))
;; Step 6: Sort and link each field group ;; Step 6: Sort and link each field group
(yas/snippet-field-groups-set (yas/snippet-field-groups-set
@ -295,14 +301,17 @@ will be deleted before inserting template."
(length (- end start))) (length (- end start)))
(goto-char start) (goto-char start)
(insert value) (insert value)
(delete-char length)))))) (delete-char length)))))
;; Step : restore all escape characters ;; Step 9: restore all escape characters
(yas/replace-all yas/escape-dollar "$") (yas/replace-all yas/escape-dollar "$")
(yas/replace-all yas/escape-backquote "`") (yas/replace-all yas/escape-backquote "`")
(yas/replace-all yas/escape-backslash "\\") (yas/replace-all yas/escape-backslash "\\")
(goto-char (point-max))) ;; Step 10: move to end and make sure exit-marker exist
(goto-char (point-max))
(unless (yas/snippet-exit-marker snippet)
(yas/snippet-exit-marker-set snippet (copy-marker (point) t)))))
(delete-char length))) (delete-char length)))
@ -368,6 +377,7 @@ otherwise, nil returned."
(defun yas/exit-snippet (snippet) (defun yas/exit-snippet (snippet)
"Goto exit-marker of SNIPPET and delete the snippet." "Goto exit-marker of SNIPPET and delete the snippet."
(interactive) (interactive)
(goto-char (yas/snippet-exit-marker snippet))
) )
(provide 'yasnippet) (provide 'yasnippet)