summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2018-06-15 10:31:13 +0200
committerSimeon Simeonov2018-06-15 10:31:13 +0200
commit3ae91e4233bf442f08eb2dbef72d95798b3870bf (patch)
treeb09cc7adc9a7890c4a61ad9495d7e9ccf56099f5
parent19907ef276869e1a7b29f4af9678c95d21a42dad (diff)
Upgrade yasnippet
-rw-r--r--.emacs.d/lisp/yasnippet.el52
1 files changed, 39 insertions, 13 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index d478073..d06165f 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -2987,6 +2987,18 @@ The last element of POSSIBILITIES may be a list of strings."
2987 (funcall fn "Choose: " possibilities)) 2987 (funcall fn "Choose: " possibilities))
2988 yas-prompt-functions))) 2988 yas-prompt-functions)))
2989 2989
2990(defun yas--auto-next ()
2991 "Helper for `yas-auto-next'."
2992 (remove-hook 'post-command-hook #'yas--auto-next t)
2993 (yas-next-field))
2994
2995(defmacro yas-auto-next (&rest body)
2996 "Automatically advance to next field after eval'ing BODY."
2997 (declare (indent 0) (debug t))
2998 `(unless yas-moving-away-p
2999 (prog1 ,@body
3000 (add-hook 'post-command-hook #'yas--auto-next nil t))))
3001
2990(defun yas-key-to-value (alist) 3002(defun yas-key-to-value (alist)
2991 (unless (or yas-moving-away-p 3003 (unless (or yas-moving-away-p
2992 yas-modified-p) 3004 yas-modified-p)
@@ -3058,6 +3070,10 @@ other fields."
3058(defvar yas--active-field-overlay nil 3070(defvar yas--active-field-overlay nil
3059 "Overlays the currently active field.") 3071 "Overlays the currently active field.")
3060 3072
3073(defvar yas--active-snippets nil
3074 "List of currently active snippets")
3075(make-variable-buffer-local 'yas--active-snippets)
3076
3061(defvar yas--field-protection-overlays nil 3077(defvar yas--field-protection-overlays nil
3062 "Two overlays protect the current active field.") 3078 "Two overlays protect the current active field.")
3063 3079
@@ -3261,12 +3277,19 @@ equivalent to a range covering the whole buffer."
3261 (setq beg (point-min) end (point-max))) 3277 (setq beg (point-min) end (point-max)))
3262 ((not end) 3278 ((not end)
3263 (setq end (1+ beg)))) 3279 (setq end (1+ beg))))
3264 (cl-sort 3280 (if (and (eq beg (point-min))
3265 (delete-dups ;; Snippets have multiple overlays. 3281 (eq end (point-max)))
3266 (delq nil 3282 yas--active-snippets
3267 (mapcar (lambda (ov) (overlay-get ov 'yas--snippet)) 3283 ;; Note: don't use `mapcar' here, since it would allocate in
3268 (overlays-in beg end)))) 3284 ;; proportion to the amount of overlays, even though the list of
3269 #'>= :key #'yas--snippet-id)) 3285 ;; active snippets should be very small.
3286 (let ((snippets nil))
3287 (dolist (ov (overlays-in beg end))
3288 (let ((snippet (overlay-get ov 'yas--snippet)))
3289 ;; Snippets have multiple overlays, so check for dups.
3290 (when (and snippet (not (memq snippet snippets)))
3291 (push snippet snippets))))
3292 (cl-sort snippets #'>= :key #'yas--snippet-id))))
3270 3293
3271(define-obsolete-function-alias 'yas--snippets-at-point 3294(define-obsolete-function-alias 'yas--snippets-at-point
3272 'yas-active-snippets "0.12") 3295 'yas-active-snippets "0.12")
@@ -3426,6 +3449,9 @@ This renders the snippet as ordinary text."
3426 ;; 3449 ;;
3427 (yas--markers-to-points snippet) 3450 (yas--markers-to-points snippet)
3428 3451
3452 ;; It's no longer an active snippet.
3453 (cl-callf2 delq snippet yas--active-snippets)
3454
3429 ;; Take care of snippet revival on undo. 3455 ;; Take care of snippet revival on undo.
3430 (if (and yas-snippet-revival (listp buffer-undo-list)) 3456 (if (and yas-snippet-revival (listp buffer-undo-list))
3431 (push `(apply yas--snippet-revive ,yas-snippet-beg ,yas-snippet-end ,snippet) 3457 (push `(apply yas--snippet-revive ,yas-snippet-beg ,yas-snippet-end ,snippet)
@@ -3519,13 +3545,12 @@ HOOK should be a symbol, a hook variable, as in `run-hooks'."
3519 "Check if point exited the currently active field of the snippet. 3545 "Check if point exited the currently active field of the snippet.
3520 3546
3521If so cleans up the whole snippet up." 3547If so cleans up the whole snippet up."
3522 (let* ((snippets (yas-active-snippets 'all)) 3548 (let* ((snippet-exit-transform nil)
3523 (snippets-left snippets) 3549 (exited-snippets-p nil)
3524 (snippet-exit-transform)
3525 ;; Record the custom snippet `yas-after-exit-snippet-hook' 3550 ;; Record the custom snippet `yas-after-exit-snippet-hook'
3526 ;; set in the expand-env field. 3551 ;; set in the expand-env field.
3527 (snippet-exit-hook yas-after-exit-snippet-hook)) 3552 (snippet-exit-hook yas-after-exit-snippet-hook))
3528 (dolist (snippet snippets) 3553 (dolist (snippet yas--active-snippets)
3529 (let ((active-field (yas--snippet-active-field snippet))) 3554 (let ((active-field (yas--snippet-active-field snippet)))
3530 (yas--letenv (yas--snippet-expand-env snippet) 3555 (yas--letenv (yas--snippet-expand-env snippet)
3531 ;; Note: the `force-exit' field could be a transform in case of 3556 ;; Note: the `force-exit' field could be a transform in case of
@@ -3533,10 +3558,10 @@ If so cleans up the whole snippet up."
3533 (setq snippet-exit-transform (yas--snippet-force-exit snippet)) 3558 (setq snippet-exit-transform (yas--snippet-force-exit snippet))
3534 (cond ((or snippet-exit-transform 3559 (cond ((or snippet-exit-transform
3535 (not (and active-field (yas--field-contains-point-p active-field)))) 3560 (not (and active-field (yas--field-contains-point-p active-field))))
3536 (setq snippets-left (delete snippet snippets-left))
3537 (setf (yas--snippet-force-exit snippet) nil) 3561 (setf (yas--snippet-force-exit snippet) nil)
3538 (setq snippet-exit-hook yas-after-exit-snippet-hook) 3562 (setq snippet-exit-hook yas-after-exit-snippet-hook)
3539 (yas--commit-snippet snippet)) 3563 (yas--commit-snippet snippet)
3564 (setq exited-snippets-p t))
3540 ((and active-field 3565 ((and active-field
3541 (or (not yas--active-field-overlay) 3566 (or (not yas--active-field-overlay)
3542 (not (overlay-buffer yas--active-field-overlay)))) 3567 (not (overlay-buffer yas--active-field-overlay))))
@@ -3550,7 +3575,7 @@ If so cleans up the whole snippet up."
3550 (yas--update-mirrors snippet))) 3575 (yas--update-mirrors snippet)))
3551 (t 3576 (t
3552 nil))))) 3577 nil)))))
3553 (unless (or (null snippets) snippets-left) 3578 (unless (or yas--active-snippets (not exited-snippets-p))
3554 (when snippet-exit-transform 3579 (when snippet-exit-transform
3555 (yas--eval-for-effect snippet-exit-transform)) 3580 (yas--eval-for-effect snippet-exit-transform))
3556 (let ((yas-after-exit-snippet-hook snippet-exit-hook)) 3581 (let ((yas-after-exit-snippet-hook snippet-exit-hook))
@@ -4043,6 +4068,7 @@ Returns the newly created snippet."
4043 ;; Move to end 4068 ;; Move to end
4044 (goto-char (point-max)) 4069 (goto-char (point-max))
4045 4070
4071 (push snippet yas--active-snippets)
4046 snippet)))) 4072 snippet))))
4047 4073
4048 4074