[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master cc14db3 11/36: Refactor yas-next-field a bit
From: |
Noam Postavsky |
Subject: |
[elpa] master cc14db3 11/36: Refactor yas-next-field a bit |
Date: |
Sat, 11 Jun 2016 19:21:10 +0000 (UTC) |
branch: master
commit cc14db399cbc8faa8aeb40e7982efb79c40acc4a
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Refactor yas-next-field a bit
* yasnippet.el (yas--find-next-field): New function to find target field.
(yas-next-field): Use it.
---
yasnippet.el | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index 93b21f5..a4e9b37 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3063,38 +3063,36 @@ Otherwise delegate to `yas-next-field'."
(yas-next-field))))
(yas-next-field)))
+(defun yas--find-next-field (n snippet active)
+ "Return the Nth field after the ACTIVE one in SNIPPET."
+ (let ((live-fields (cl-remove-if
+ (lambda (field)
+ (and (not (eq field active))
+ (yas--field-probably-deleted-p snippet field)))
+ (yas--snippet-fields snippet))))
+ (if (>= n 0) (nth n (memq active live-fields))
+ (car (last (memq active (reverse live-fields)) (- n))))))
+
(defun yas-next-field (&optional arg)
"Navigate to the ARGth next field.
If there's none, exit the snippet."
(interactive)
- (let* ((arg (or arg
- 1))
- (snippet (first (yas--snippets-at-point)))
+ (unless arg (setq arg 1))
+ (let* ((snippet (car (yas--snippets-at-point)))
(active-field (overlay-get yas--active-field-overlay 'yas--field))
- (live-fields (remove-if #'(lambda (field)
- (and (not (eq field active-field))
- (yas--field-probably-deleted-p
snippet field)))
- (yas--snippet-fields snippet)))
- (active-field-pos (position active-field live-fields))
- (target-pos (and active-field-pos (+ arg active-field-pos)))
- (target-field (and target-pos (nth target-pos live-fields))))
- ;; First check if we're moving out of a field with a transform
- ;;
- (when (and active-field
- (yas--field-transform active-field))
+ (target-field (yas--find-next-field arg snippet active-field)))
+ ;; First check if we're moving out of a field with a transform.
+ (when (and active-field (yas--field-transform active-field))
(let* ((yas-moving-away-p t)
(yas-text (yas--field-text-for-display active-field))
(yas-modified-p (yas--field-modified-p active-field)))
;; primary field transform: exit call to field-transform
(yas--eval-lisp (yas--field-transform active-field))))
;; Now actually move...
- (cond ((and target-pos (>= target-pos (length live-fields)))
- (yas-exit-snippet snippet))
- (target-field
- (yas--move-to-field snippet target-field))
- (t
- nil))))
+ (if target-field
+ (yas--move-to-field snippet target-field)
+ (yas-exit-snippet snippet))))
(defun yas--place-overlays (snippet field)
"Correctly place overlays for SNIPPET's FIELD."
- [elpa] master updated (ee4cf1e -> 438f5db), Noam Postavsky, 2016/06/11
- [elpa] master 3e67b1b 02/36: yasnippet.el (snippet-mode): Add autoload cookie., Noam Postavsky, 2016/06/11
- [elpa] master c0032e6 08/36: chmod -x doc/yas-doc-helper.el, Noam Postavsky, 2016/06/11
- [elpa] master 14f830a 13/36: Test expansion in an empty buffer, Noam Postavsky, 2016/06/11
- [elpa] master a87ec54 12/36: yasnippet.el (yas-next-field-will-exit-p): New function., Noam Postavsky, 2016/06/11
- [elpa] master 7799aa9 09/36: Document .yas-setup.el, Noam Postavsky, 2016/06/11
- [elpa] master 4f2aa15 05/36: Only kill snippets for text length change, Noam Postavsky, 2016/06/11
- [elpa] master 8771082 03/36: Don't add useless kill ring entries, Noam Postavsky, 2016/06/11
- [elpa] master cc14db3 11/36: Refactor yas-next-field a bit,
Noam Postavsky <=
- [elpa] master db4cd31 20/36: Delete active region for trigger key expansion, Noam Postavsky, 2016/06/11
- [elpa] master e37ce9e 18/36: Disable region wrapping for trigger key expansion, Noam Postavsky, 2016/06/11
- [elpa] master 6180cc4 28/36: Fix field transform application in yas-next-field, Noam Postavsky, 2016/06/11
- [elpa] master 146b161 25/36: Don't indent empty lines in snippet expansion, Noam Postavsky, 2016/06/11
- [elpa] master e9406f5 26/36: Document $> and fix escaping, Noam Postavsky, 2016/06/11
- [elpa] master 6f97316 27/36: Fix outdated and misformatted docs, Noam Postavsky, 2016/06/11
- [elpa] master bd30a30 04/36: yas-dont-activate is a hook, Noam Postavsky, 2016/06/11
- [elpa] master c1b2cb7 17/36: Improve documentation for new register option, Noam Postavsky, 2016/06/11
- [elpa] master 4c6064c 01/36: Avoid potential problems with user's hooks, Noam Postavsky, 2016/06/11
- [elpa] master 5d44a9f 19/36: Revert "Disable region wrapping for trigger key expansion", Noam Postavsky, 2016/06/11