summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2020-05-11 08:58:52 +0200
committerSimeon Simeonov2020-05-11 08:58:52 +0200
commit0e3b7027a9f5f1c57ff13af96cba042a5a16142d (patch)
tree32bcb49d185413d47dc90279a140c1efe11fa14b
parentb4ae205398b94266d012c5cffc64bc1450c3d541 (diff)
Update yasnippet
-rw-r--r--.emacs.d/lisp/yasnippet.el76
1 files changed, 48 insertions, 28 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index bfd904e..ac25669 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -5,7 +5,7 @@
5;; João Távora <joaotavora@gmail.com>, 5;; João Távora <joaotavora@gmail.com>,
6;; Noam Postavsky <npostavs@gmail.com> 6;; Noam Postavsky <npostavs@gmail.com>
7;; Maintainer: Noam Postavsky <npostavs@gmail.com> 7;; Maintainer: Noam Postavsky <npostavs@gmail.com>
8;; Version: 0.13.0 8;; Version: 0.14.0
9;; X-URL: http://github.com/joaotavora/yasnippet 9;; X-URL: http://github.com/joaotavora/yasnippet
10;; Keywords: convenience, emulation 10;; Keywords: convenience, emulation
11;; URL: http://github.com/joaotavora/yasnippet 11;; URL: http://github.com/joaotavora/yasnippet
@@ -160,7 +160,7 @@
160 160
161(defconst yas-installed-snippets-dir (expand-file-name "snippets" yas--loaddir)) 161(defconst yas-installed-snippets-dir (expand-file-name "snippets" yas--loaddir))
162(make-obsolete-variable 'yas-installed-snippets-dir "\ 162(make-obsolete-variable 'yas-installed-snippets-dir "\
163Yasnippet no longer comes with installed snippets" "0.13") 163Yasnippet no longer comes with installed snippets" "0.14")
164 164
165(defconst yas--default-user-snippets-dir 165(defconst yas--default-user-snippets-dir
166 (expand-file-name "snippets" user-emacs-directory)) 166 (expand-file-name "snippets" user-emacs-directory))
@@ -579,7 +579,7 @@ can be useful."
579 579
580;;; Internal variables 580;;; Internal variables
581 581
582(defconst yas--version "0.13.0") 582(defconst yas--version "0.14.0")
583 583
584(defvar yas--menu-table (make-hash-table) 584(defvar yas--menu-table (make-hash-table)
585 "A hash table of MAJOR-MODE symbols to menu keymaps.") 585 "A hash table of MAJOR-MODE symbols to menu keymaps.")
@@ -3501,7 +3501,8 @@ This renders the snippet as ordinary text."
3501 ;; 3501 ;;
3502 (let ((previous-field (yas--snippet-previous-active-field snippet))) 3502 (let ((previous-field (yas--snippet-previous-active-field snippet)))
3503 (when (and yas-snippet-end previous-field) 3503 (when (and yas-snippet-end previous-field)
3504 (yas--advance-end-maybe previous-field yas-snippet-end))) 3504 (yas--advance-end-maybe-previous-fields
3505 previous-field yas-snippet-end (cdr yas--active-snippets))))
3505 3506
3506 ;; Convert all markers to points, 3507 ;; Convert all markers to points,
3507 ;; 3508 ;;
@@ -3849,14 +3850,9 @@ field start. This hook does nothing if an undo is in progress."
3849 (setf (yas--field-modified-p field) t) 3850 (setf (yas--field-modified-p field) t)
3850 ;; Adjust any pending active fields in case of stacked 3851 ;; Adjust any pending active fields in case of stacked
3851 ;; expansion. 3852 ;; expansion.
3852 (let ((pfield field) 3853 (yas--advance-end-maybe-previous-fields
3853 (psnippets (yas--gather-active-snippets 3854 field (overlay-end overlay)
3854 overlay beg end t))) 3855 (yas--gather-active-snippets overlay beg end t))
3855 (while (and pfield psnippets)
3856 (let ((psnippet (pop psnippets)))
3857 (cl-assert (memq pfield (yas--snippet-fields psnippet)))
3858 (yas--advance-end-maybe pfield (overlay-end overlay))
3859 (setq pfield (yas--snippet-previous-active-field psnippet)))))
3860 ;; Update fields now, but delay auto indentation until 3856 ;; Update fields now, but delay auto indentation until
3861 ;; post-command. We don't want to run indentation on 3857 ;; post-command. We don't want to run indentation on
3862 ;; the intermediate state where field text might be 3858 ;; the intermediate state where field text might be
@@ -4110,7 +4106,9 @@ for normal snippets, and a list for command snippets)."
4110 (overlay-get yas--active-field-overlay 'yas--field)))) 4106 (overlay-get yas--active-field-overlay 'yas--field))))
4111 (when existing-field 4107 (when existing-field
4112 (setf (yas--snippet-previous-active-field snippet) existing-field) 4108 (setf (yas--snippet-previous-active-field snippet) existing-field)
4113 (yas--advance-end-maybe existing-field (overlay-end yas--active-field-overlay)))) 4109 (yas--advance-end-maybe-previous-fields
4110 existing-field (overlay-end yas--active-field-overlay)
4111 (cdr yas--active-snippets))))
4114 4112
4115 ;; Exit the snippet immediately if no fields. 4113 ;; Exit the snippet immediately if no fields.
4116 (unless (yas--snippet-fields snippet) 4114 (unless (yas--snippet-fields snippet)
@@ -4170,21 +4168,27 @@ Returns the newly created snippet."
4170 (yas--letenv expand-env 4168 (yas--letenv expand-env
4171 ;; Put a single undo action for the expanded snippet's 4169 ;; Put a single undo action for the expanded snippet's
4172 ;; content. 4170 ;; content.
4173 (let ((buffer-undo-list t) 4171 (let ((buffer-undo-list t))
4174 (inhibit-modification-hooks t))
4175 ;; Some versions of cc-mode fail when inserting snippet
4176 ;; content in a narrowed buffer, so make sure to insert
4177 ;; before narrowing. Furthermore, call before and after
4178 ;; change functions manually, otherwise cc-mode's cache can
4179 ;; get messed up.
4180 (goto-char begin) 4172 (goto-char begin)
4181 (run-hook-with-args 'before-change-functions begin begin) 4173 ;; Call before and after change functions manually,
4182 (insert content) 4174 ;; otherwise cc-mode's cache can get messed up. Don't use
4183 (setq end (+ end (length content))) 4175 ;; `inhibit-modification-hooks' for that, that blocks
4184 (narrow-to-region begin end) 4176 ;; overlay and text property hooks as well! FIXME: Maybe
4185 (goto-char (point-min)) 4177 ;; use `combine-change-calls'? (Requires Emacs 27+ though.)
4186 (yas--snippet-parse-create snippet) 4178 (run-hook-with-args 'before-change-functions begin end)
4187 (run-hook-with-args 'after-change-functions (point-min) (point-max) 0)) 4179 (let ((before-change-functions nil)
4180 (after-change-functions nil))
4181 ;; Some versions of cc-mode (might be the one with Emacs
4182 ;; 24.3 only) fail when inserting snippet content in a
4183 ;; narrowed buffer, so make sure to insert before
4184 ;; narrowing.
4185 (insert content)
4186 (narrow-to-region begin (point))
4187 (goto-char (point-min))
4188 (yas--snippet-parse-create snippet))
4189 (run-hook-with-args 'after-change-functions
4190 (point-min) (point-max)
4191 (- (point-max) (point-min))))
4188 (when (listp buffer-undo-list) 4192 (when (listp buffer-undo-list)
4189 (push (cons (point-min) (point-max)) 4193 (push (cons (point-min) (point-max))
4190 buffer-undo-list)) 4194 buffer-undo-list))
@@ -4336,6 +4340,13 @@ exit-marker have identical start and end markers."
4336 ((yas--exit-p fom) 4340 ((yas--exit-p fom)
4337 (yas--advance-start-maybe (yas--fom-next fom) newend)))) 4341 (yas--advance-start-maybe (yas--fom-next fom) newend))))
4338 4342
4343(defun yas--advance-end-maybe-previous-fields (field end snippets)
4344 "Call `yas--advance-end-maybe' on FIELD, and previous fields on SNIPPETS."
4345 (dolist (snippet snippets)
4346 (cl-assert (memq field (yas--snippet-fields snippet)))
4347 (yas--advance-end-maybe field end)
4348 (setq field (yas--snippet-previous-active-field snippet))))
4349
4339(defun yas--advance-start-maybe (fom newstart) 4350(defun yas--advance-start-maybe (fom newstart)
4340 "Maybe advance FOM's start to NEWSTART if it needs it. 4351 "Maybe advance FOM's start to NEWSTART if it needs it.
4341 4352
@@ -4714,6 +4725,13 @@ SAVED-QUOTES is the in format returned by `yas--save-backquotes'."
4714 yas--indent-markers)) 4725 yas--indent-markers))
4715 (setq yas--indent-markers (nreverse yas--indent-markers))) 4726 (setq yas--indent-markers (nreverse yas--indent-markers)))
4716 4727
4728(defun yas--scan-for-field-end ()
4729 (while (progn (re-search-forward "\\${\\|}")
4730 (when (eq (char-before) ?\{)
4731 ;; Nested field.
4732 (yas--scan-for-field-end))))
4733 (point))
4734
4717(defun yas--field-parse-create (snippet &optional parent-field) 4735(defun yas--field-parse-create (snippet &optional parent-field)
4718 "Parse most field expressions in SNIPPET, except for the simple one \"$n\". 4736 "Parse most field expressions in SNIPPET, except for the simple one \"$n\".
4719 4737
@@ -4730,7 +4748,9 @@ When multiple expressions are found, only the last one counts."
4730 ;; 4748 ;;
4731 (save-excursion 4749 (save-excursion
4732 (while (re-search-forward yas--field-regexp nil t) 4750 (while (re-search-forward yas--field-regexp nil t)
4733 (let* ((brace-scan (yas--scan-sexps (1+ (match-beginning 0)) 1)) 4751 (let* ((brace-scan (save-match-data
4752 (goto-char (match-beginning 2))
4753 (yas--scan-for-field-end)))
4734 ;; if the `brace-scan' didn't reach a brace, we have a 4754 ;; if the `brace-scan' didn't reach a brace, we have a
4735 ;; snippet with invalid escaping, probably a closing 4755 ;; snippet with invalid escaping, probably a closing
4736 ;; brace escaped with two backslashes (github#979). But 4756 ;; brace escaped with two backslashes (github#979). But