* fields like ${0: } still need a little more work....

This commit is contained in:
capitaomorte 2010-04-11 22:06:43 +00:00
parent f2aaf0eeb5
commit 411d868793

View File

@ -2770,10 +2770,17 @@ Otherwise throw exception."
(yas/field-text-for-display field)))) (yas/field-text-for-display field))))
(defun yas/text () (defun yas/text ()
"Return `yas/text' if that exists and is non-empty, else nil."
(if (and yas/text (if (and yas/text
(not (string= "" yas/text))) (not (string= "" yas/text)))
yas/text)) yas/text))
;; (defun yas/selected-text ()
;; "Return `yas/selected-text' if that exists and is non-empty, else nil."
;; (if (and yas/selected-text
;; (not (string= "" yas/selected-text)))
;; yas/selected-text))
(defun yas/get-field-once (number &optional transform-fn) (defun yas/get-field-once (number &optional transform-fn)
(unless yas/modified-p (unless yas/modified-p
(if transform-fn (if transform-fn
@ -2986,12 +2993,19 @@ Also create some protection overlays"
(setf (yas/snippet-active-field snippet) field) (setf (yas/snippet-active-field snippet) field)
(yas/place-overlays snippet field) (yas/place-overlays snippet field)
(overlay-put yas/active-field-overlay 'yas/field field) (overlay-put yas/active-field-overlay 'yas/field field)
(let ((number (yas/field-number field)))
(if (and number (zerop number))
(progn
(setf (yas/snippet-force-exit snippet) `(activate-mark ,(yas/field-start field) ,(yas/field-end field)))
(set-mark (yas/field-end field))
;;(x-set-selection 'PRIMARY (cons (yas/field-start field) (yas/field-end-field)))
(setq transient-mark-mode (cons 'only transient-mark-mode)))
;; primary field transform: first call to snippet transform ;; primary field transform: first call to snippet transform
(unless (yas/field-modified-p field) (unless (yas/field-modified-p field)
(if (yas/field-update-display field snippet) (if (yas/field-update-display field snippet)
(let ((inhibit-modification-hooks t)) (let ((inhibit-modification-hooks t))
(yas/update-mirrors snippet)) (yas/update-mirrors snippet))
(setf (yas/field-modified-p field) nil)))) (setf (yas/field-modified-p field) nil))))))
(defun yas/prev-field () (defun yas/prev-field ()
"Navigate to prev field. If there's none, exit the snippet." "Navigate to prev field. If there's none, exit the snippet."
@ -3268,11 +3282,9 @@ progress."
;; primary field transform: normal calls to expression or ;; primary field transform: normal calls to expression or
;; force an exit on next `post-command-hook' if the ;; force an exit on next `post-command-hook' if the
;; number is 0 ;; number is 0
(if (and number (zerop number))
(setf (yas/snippet-force-exit snippet) t)
(let ((saved-point (point))) (let ((saved-point (point)))
(yas/field-update-display field (car (yas/snippets-at-point))) (yas/field-update-display field (car (yas/snippets-at-point)))
(goto-char saved-point))) (goto-char saved-point))
(yas/update-mirrors (car (yas/snippets-at-point)))) (yas/update-mirrors (car (yas/snippets-at-point))))
(field (field
(when (and (not after?) (when (and (not after?)