emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 299efcb 40/40: packages/yasnippet: Merge external (v0.11.0


From: Noam Postavsky
Subject: [elpa] master 299efcb 40/40: packages/yasnippet: Merge external (v0.11.0)
Date: Wed, 26 Oct 2016 23:06:34 +0000 (UTC)

branch: master
commit 299efcbd8ea04f431d3b5f20ff96dee37d02255c
Merge: f06d730 e6b8651
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    packages/yasnippet: Merge external (v0.11.0)
---
 packages/yasnippet/.travis.yml                 |    7 +
 packages/yasnippet/CONTRIBUTING.md             |    2 +-
 packages/yasnippet/NEWS                        |   50 +-
 packages/yasnippet/README.mdown                |   14 +-
 packages/yasnippet/Rakefile                    |    6 +-
 packages/yasnippet/doc/index.org               |    2 +-
 packages/yasnippet/doc/nav-menu.html.inc       |    2 +-
 packages/yasnippet/doc/snippet-development.org |   23 +-
 packages/yasnippet/doc/snippet-expansion.org   |    6 +-
 packages/yasnippet/yasnippet-tests.el          |  238 +++++----
 packages/yasnippet/yasnippet.el                |  676 ++++++++++++------------
 11 files changed, 570 insertions(+), 456 deletions(-)

diff --git a/packages/yasnippet/.travis.yml b/packages/yasnippet/.travis.yml
index 72aa314..b43d358 100644
--- a/packages/yasnippet/.travis.yml
+++ b/packages/yasnippet/.travis.yml
@@ -16,6 +16,7 @@ install:
   - export PATH=/tmp/emacs/bin:${PATH}
   - if ! emacs -Q --batch --eval "(require 'cl-lib)" ; then
         curl -Lo cl-lib.el http://elpa.gnu.org/packages/cl-lib-0.5.el ;
+        export warnings="'(not cl-functions)" ;
     fi
   - if ! emacs -Q --batch --eval "(require 'ert)" ; then
         curl -LO 
https://raw.githubusercontent.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el
 &&
@@ -26,3 +27,9 @@ install:
 script:
   - rake compile
   - rake tests
+
+notifications:
+  email:
+    # Default is change, but that includes a new branch's 1st success.
+    on_success: never
+    on_failure: always # The default.
diff --git a/packages/yasnippet/CONTRIBUTING.md 
b/packages/yasnippet/CONTRIBUTING.md
index 7e2ce47..81c0a1f 100644
--- a/packages/yasnippet/CONTRIBUTING.md
+++ b/packages/yasnippet/CONTRIBUTING.md
@@ -26,4 +26,4 @@ there is no separate Changelog file.
 For trivial changes, a message consisting of just the changelog entry
 (the `* foo.el ...` part) is fine.
 
-[bugnote]: 
https://github.com/capitaomorte/yasnippet#important-note-regarding-bug-reporting
+[bugnote]: 
https://github.com/joaotavora/yasnippet#important-note-regarding-bug-reporting
diff --git a/packages/yasnippet/NEWS b/packages/yasnippet/NEWS
index 7f4dec6..6e6629d 100644
--- a/packages/yasnippet/NEWS
+++ b/packages/yasnippet/NEWS
@@ -4,6 +4,52 @@ Copyright (C) 2016 Free Software Foundation, Inc.
 See the end of the file for license conditions.
 
 
+
+* 0.11.0 (Oct 26, 2016)
+** Changes and New Features
+
+*** Modifying buffer in backquoted expressions is deprecated!
+Backquoted expressions should only return a string that will be
+inserted.  Snippets which modify the buffer as a side-effect will now
+trigger a warning.
+
+*** The verbosity levels for messages have been adjusted.
+While the default verbosity level was increased by 1 (it was only
+lower before due to a bug), several messages now only print at the
+level 4, so the overall effect should be less messages by default.
+
+*** Saving and loading snippets has been streamlined.  Saving the
+snippet to a file will now automatically load it.  Additionally, the
+buffer will be renamed from "*new snippet*" to whatever the snippet is
+named.  See also Github #718, #733, and #734.
+
+*** `yas-escape-text' no longer signals an error when given nil.
+
+*** `yas-describe-tables' is split into simpler commands.
+**** `yas-describe-tables' takes a prefix arg to show non-active tables.
+**** New command `yas-describe-tables-by-namehash' shows table by namehash.
+
+*** Use the region contents as the snippet body of new snippets.
+
+*** The dependency on `cl' is removed.
+Yasnippet now only requires `cl-lib'.
+
+** Fixed Bugs
+
+*** Fix field navigation (tabbing) in the backwards direction.
+See Github #722
+
+*** Add support for deprecated yas/ symbols in `yas-define-menu'.
+It was left out by accident.  This support is conditional on
+`yas-alias-to-yas/prefix-p', just like other obsolete yas/ bindings.
+
+*** Fix overriding of snippet by a new snippet with same uuid.
+See Github #714.
+
+*** Fix handling of snippets with 2 mirros on the same line.
+See Github #712.
+
+
 * 0.10.0 (June 11th, 2016)
 
 ** Changes and New Features
@@ -114,7 +160,7 @@ good enough.  See issue #497.
 
 *** Documentation rewritten in org-mode and updated.
 A tremendous effort by Noam Postavsky.  Hopefully easier to maintain
-and navigate.  Available at <http://capitaomorte.github.io/yasnippet>.
+and navigate.  Available at <http://joaotavora.github.io/yasnippet>.
 
 *** Snippets are now maintained in their own repo.
 Snippets live in Andrea Crotti's
@@ -122,7 +168,7 @@ Snippets live in Andrea Crotti's
 for more details.
 
 *** Textmate snippet importer moved to separate `yasmate' repo.
-URL is <https://github.com/capitaomorte/yasmate>.  See README.md for
+URL is <https://github.com/joaotavora/yasmate>.  See README.md for
 more details.
 
 *** `yas-snippet-dirs' now allows symbols as aliases to directories.
diff --git a/packages/yasnippet/README.mdown b/packages/yasnippet/README.mdown
index a3062ea..f4e0594 100644
--- a/packages/yasnippet/README.mdown
+++ b/packages/yasnippet/README.mdown
@@ -20,7 +20,7 @@ YASnippet. Watch [a demo on YouTube][youtube-demo].
 Clone this repository somewhere
 
     $ cd ~/.emacs.d/plugins
-    $ git clone --recursive https://github.com/capitaomorte/yasnippet
+    $ git clone --recursive https://github.com/joaotavora/yasnippet
 
 Add the following in your `.emacs` file:
 
@@ -117,14 +117,14 @@ a way to reproduce the problem exactly like it happened 
to you.
 To do this, we need to rule out interference from external factors
 like other Emacs extensions or your own customisations.
 
-Here's an example report that "sandboxes" an Emacs session just for 
+Here's an example report that "sandboxes" an Emacs session just for
 reproducing a bug.
 
 ```
 $ emacs --version
 Emacs 24.3
 $ cd /tmp/
-$ git clone https://github.com/capitaomorte/yasnippet.git yasnippet-bug
+$ git clone https://github.com/joaotavora/yasnippet.git yasnippet-bug
 $ cd yasnippet-bug
 $ git log -1 --oneline
 6053db0 Closes #527: Unbreak case where yas-fallback-behaviour is a list
@@ -138,11 +138,11 @@ OR
 When loading yasnippet I see "Error: failed to frobnicate"!
 ```
 
-Using `emacs -Q` or temporarily moving your `.emacs` init file to the side 
+Using `emacs -Q` or temporarily moving your `.emacs` init file to the side
 is another way to achieve good reproducibility.
 
 Here's a
-[another example](https://github.com/capitaomorte/yasnippet/issues/318)
+[another example](https://github.com/joaotavora/yasnippet/issues/318)
 of a bug report. It has everything needed for a successful analysis
 and speedy resolution.
 
@@ -162,10 +162,10 @@ request).
 Finally, thank you very much for using YASnippet!
 
 [docs]: http://joaotavora.github.io/yasnippet/
-[issues]: https://github.com/capitaomorte/yasnippet/issues
+[issues]: https://github.com/joaotavora/yasnippet/issues
 [googlecode tracker]: http://code.google.com/p/yasnippet/issues/list
 [forum]: http://groups.google.com/group/smart-snippet
 [melpa]: http://melpa.milkbox.net/
-[yasmate]: http://github.com/capitaomorte/yasmate
+[yasmate]: http://github.com/joaotavora/yasmate
 [textmate-to-yas.el]: https://github.com/mattfidler/textmate-to-yas.el
 [yasnippet-snippets]: http://github.com/AndreaCrotti/yasnippet-snippets
diff --git a/packages/yasnippet/Rakefile b/packages/yasnippet/Rakefile
index f88237b..48a2086 100644
--- a/packages/yasnippet/Rakefile
+++ b/packages/yasnippet/Rakefile
@@ -98,8 +98,12 @@ end
 desc "Compile yasnippet.el into yasnippet.elc"
 
 rule '.elc' => '.el' do |t|
+  set_warnings = ""
+  if ENV['warnings']
+    set_warnings = " --eval \"(setq byte-compile-warnings 
#{ENV['warnings']})\""
+  end
   sh "#{$EMACS} --batch -L . --eval \"(setq byte-compile-error-on-warn t)\"" +
-     " -f batch-byte-compile #{t.source}"
+     "#{set_warnings} -f batch-byte-compile #{t.source}"
 end
 task :compile => FileList["yasnippet.el"].ext('elc')
 
diff --git a/packages/yasnippet/doc/index.org b/packages/yasnippet/doc/index.org
index f99b3f7..c5e0be3 100644
--- a/packages/yasnippet/doc/index.org
+++ b/packages/yasnippet/doc/index.org
@@ -3,7 +3,7 @@
 
 The YASnippet documentation has been split into separate parts:
 
-0. 
[[https://github.com/capitaomorte/yasnippet/blob/master/README.mdown][README]]
+0. [[https://github.com/joaotavora/yasnippet/blob/master/README.mdown][README]]
 
    Contains an introduction, installation instructions and other important
    notes.
diff --git a/packages/yasnippet/doc/nav-menu.html.inc 
b/packages/yasnippet/doc/nav-menu.html.inc
index b31ec94..2a3f0a1 100644
--- a/packages/yasnippet/doc/nav-menu.html.inc
+++ b/packages/yasnippet/doc/nav-menu.html.inc
@@ -1,7 +1,7 @@
 <nav>
   <ul class="center">
     <li> <a href="index.html">Overview</a>
-    <li> <a 
href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown";>
+    <li> <a 
href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown";>
         Intro and Tutorial</a>
     <li class="center">Snippet
       <ul>
diff --git a/packages/yasnippet/doc/snippet-development.org 
b/packages/yasnippet/doc/snippet-development.org
index 4fd293d..ffe648c 100644
--- a/packages/yasnippet/doc/snippet-development.org
+++ b/packages/yasnippet/doc/snippet-development.org
@@ -209,7 +209,7 @@ back-quotes (=`=). The lisp forms are evaluated when the 
snippet is
 being expanded. The evaluation is done in the same buffer as the
 snippet being expanded.
 
-Here's an example for c-mode` to calculate the header file guard
+Here's an example for c-mode to calculate the header file guard
 dynamically:
 
 #+BEGIN_SRC snippet
@@ -235,6 +235,27 @@ to "wrap" the selected region inside your recently 
inserted snippet.
 Alternatively, you can also customize the variable
 [[sym:yas-wrap-around-region][=yas-wrap-around-region=]] to =t= which will do 
this automatically.
 
+*** Note: backquote expressions should not modify the buffer
+
+Please note that the lisp forms in backquotes should *not* modify the
+buffer, doing so will trigger a warning.  For example, instead of
+doing
+
+#+BEGIN_SRC snippet
+  Timestamp: `(insert (current-time-string))`
+#+END_SRC
+
+do this:
+#+BEGIN_SRC snippet
+  Timestamp: `(current-time-string)`
+#+END_SRC
+
+The warning may be suppressed with the following code in your init file:
+#+BEGIN_SRC emacs-lisp
+  (add-to-list 'warning-suppress-types '(yasnippet backquote-change))
+#+END_SRC
+
+
 ** Tab stop fields
 
 Tab stops are fields that you can navigate back and forth by =TAB= and
diff --git a/packages/yasnippet/doc/snippet-expansion.org 
b/packages/yasnippet/doc/snippet-expansion.org
index f57df95..4bd133b 100644
--- a/packages/yasnippet/doc/snippet-expansion.org
+++ b/packages/yasnippet/doc/snippet-expansion.org
@@ -193,11 +193,11 @@ block or a string (e.g. in =python-mode=).
 
 If you use the =# condition := directive (see
 [[./snippet-development.org][Writing Snippets]]) you could just specify
-the condition for =if= to be =(not (python-in-string/comment))=. But how
+the condition for =if= to be =(not (python-syntax-comment-or-string-p))=. But 
how
 about =while=, =for=, etc. ? Writing the same condition for all the
 snippets is just boring. So has a buffer local variable
 [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]. You can set 
this variable to
-=(not (python-in-string/comment))= in =python-mode-hook=.
+=(not (python-syntax-comment-or-string-p))= in =python-mode-hook=.
 
 Then, what if you really want some particular snippet to expand even
 inside a comment? Set 
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] like this
@@ -206,7 +206,7 @@ inside a comment? Set 
[[sym:yas-buffer-local-condition][=yas-buffer-local-condit
   (add-hook 'python-mode-hook
             (lambda ()
               (setq yas-buffer-local-condition
-                    '(if (python-in-string/comment)
+                    '(if (python-syntax-comment-or-string-p)
                          '(require-snippet-condition . force-in-comment)
                        t))))
 #+END_SRC
diff --git a/packages/yasnippet/yasnippet-tests.el 
b/packages/yasnippet/yasnippet-tests.el
index 47b6e1f..6b7a91a 100644
--- a/packages/yasnippet/yasnippet-tests.el
+++ b/packages/yasnippet/yasnippet-tests.el
@@ -27,7 +27,7 @@
 (require 'yasnippet)
 (require 'ert)
 (require 'ert-x)
-(require 'cl)
+(require 'cl-lib)
 
 
 ;;; Snippet mechanics
@@ -38,14 +38,17 @@
 (ert-deftest field-navigation ()
   (with-temp-buffer
     (yas-minor-mode 1)
-    (yas-expand-snippet "${1:brother} from another ${2:mother}")
+    (yas-expand-snippet "${1:brother} from ${2:another} ${3:mother}")
     (should (string= (yas--buffer-contents)
                      "brother from another mother"))
-
     (should (looking-at "brother"))
     (ert-simulate-command '(yas-next-field-or-maybe-expand))
+    (should (looking-at "another"))
+    (ert-simulate-command '(yas-next-field-or-maybe-expand))
     (should (looking-at "mother"))
     (ert-simulate-command '(yas-prev-field))
+    (should (looking-at "another"))
+    (ert-simulate-command '(yas-prev-field))
     (should (looking-at "brother"))))
 
 (ert-deftest simple-mirror ()
@@ -227,13 +230,32 @@ end" (buffer-string)))
 No indent$>
 end" (buffer-string)))))
 
+(ert-deftest single-line-multi-mirror-indentation ()
+  "Make sure not to indent with multiple mirrors per line."
+  ;; See also Github issue #712.
+  (with-temp-buffer
+    (text-mode)
+    (yas-minor-mode 1)
+    (yas-expand-snippet "${1:XXXXX} --------
+$1   ---------------- $1 ----
+$1   ------------------------")
+    (should (string= (yas--buffer-contents) "XXXXX --------
+XXXXX   ---------------- XXXXX ----
+XXXXX   ------------------------"))))
+
+(ert-deftest indent-mirrors-on-update ()
+  "Check that mirrors are always kept indented."
+  (with-temp-buffer
+    (ruby-mode)
+    (yas-minor-mode 1)
+    (yas-expand-snippet "def $1\n$1\nend")
+    (yas-mock-insert "xxx")
+    ;; Assuming 2 space indent.
+    (should (string= "def xxx\n  xxx\nend" (buffer-string)))))
 
-(ert-deftest navigate-a-snippet-with-multiline-mirrors-issue-665 ()
-  "In issue 665, a multi-line mirror is attempted.
 
-Indentation doesn't (yet) happen on these mirrors, but let this
-test guard against any misnavigations that might be introduced by
-an incorrect implementation of mirror auto-indentation"
+(ert-deftest snippet-with-multiline-mirrors-issue-665 ()
+  "In issue 665, a multi-line mirror is attempted."
   (with-temp-buffer
     (ruby-mode)
     (yas-minor-mode 1)
@@ -246,8 +268,9 @@ mapconcat #'(lambda (arg)
     (ert-simulate-command '(yas-next-field))
     (let ((expected (mapconcat #'identity
                                '("@bla = bla"
-                                 "[[:blank:address@hidden = ble"
-                                 "[[:blank:address@hidden = bli")
+                                 ;; assume ruby is always indented to 2 spaces
+                                 "  @ble = ble"
+                                 "  @bli = bli")
                                "\n")))
       (should (looking-at expected))
       (yas-mock-insert "blo")
@@ -503,48 +526,16 @@ TODO: correct this bug!"
 
 ;;; Loading
 ;;;
-(defun yas--call-with-temporary-redefinitions (function
-                                               &rest 
function-names-and-overriding-functions)
-  (let* ((overrides (remove-if-not #'(lambda (fdef)
-                                       (fboundp (first fdef)))
-                                   function-names-and-overriding-functions))
-         (definition-names (mapcar #'first overrides))
-         (overriding-functions (mapcar #'second overrides))
-         (saved-functions (mapcar #'symbol-function definition-names)))
-    ;; saving all definitions before overriding anything ensures FDEFINITION
-    ;; errors don't cause accidental permanent redefinitions.
-    ;;
-    (cl-labels ((set-fdefinitions (names functions)
-                                  (loop for name in names
-                                        for fn in functions
-                                        do (fset name fn))))
-      (set-fdefinitions definition-names overriding-functions)
-      (unwind-protect (funcall function)
-       (set-fdefinitions definition-names saved-functions)))))
-
-(defmacro yas--with-temporary-redefinitions (fdefinitions &rest body)
-  ;; "Temporarily (but globally) redefine each function in FDEFINITIONS.
-  ;; E.g.: (yas--with-temporary-redefinitions ((foo (x) ...)
-  ;;                                           (bar (x) ...))
-  ;;         ;; code that eventually calls foo, bar of (setf foo)
-  ;;         ...)"
-  ;; FIXME: This is hideous!  Better use defadvice (or at least letf).
-  `(yas--call-with-temporary-redefinitions
-    (lambda () ,@body)
-    ,@(mapcar #'(lambda (thingy)
-                  `(list ',(first thingy)
-                         (lambda ,@(rest thingy))))
-              fdefinitions)))
 
 (defmacro yas-with-overriden-buffer-list (&rest body)
   (let ((saved-sym (make-symbol "yas--buffer-list")))
     `(let ((,saved-sym (symbol-function 'buffer-list)))
-       (yas--with-temporary-redefinitions
-           ((buffer-list ()
-                         (remove-if #'(lambda (buf)
-                                        (with-current-buffer buf
-                                          (eq major-mode 
'lisp-interaction-mode)))
-                                    (funcall ,saved-sym))))
+       (cl-letf (((symbol-function 'buffer-list)
+                  (lambda ()
+                    (cl-remove-if (lambda (buf)
+                                    (with-current-buffer buf
+                                      (eq major-mode 'lisp-interaction-mode)))
+                                  (funcall ,saved-sym)))))
          ,@body))))
 
 
@@ -587,20 +578,71 @@ TODO: correct this bug!"
   (yas-with-some-interesting-snippet-dirs
    (yas-reload-all)
    (yas-recompile-all)
-   (yas--with-temporary-redefinitions ((yas--load-directory-2
-                                        (&rest _dummies)
-                                        (ert-fail "yas--load-directory-2 
shouldn't be called when snippets have been compiled")))
+   (cl-letf (((symbol-function 'yas--load-directory-2)
+              (lambda (&rest _dummies)
+                (ert-fail "yas--load-directory-2 shouldn't be called when 
snippets have been compiled"))))
      (yas-reload-all)
      (yas--basic-jit-loading-1))))
 
+(ert-deftest snippet-load-uuid ()
+  "Test snippets with same uuid override old ones."
+  (yas-saving-variables
+   (yas-define-snippets
+    'text-mode
+    '(("1" "one" "one" nil nil nil nil "C-c 1" "uuid-1")
+      ("2" "two" "two" nil nil nil nil nil "uuid-2")))
+   (with-temp-buffer
+     (text-mode)
+     (yas-minor-mode +1)
+     (should (equal (yas-lookup-snippet "one") "one"))
+     (should (eq (key-binding "\C-c1") 'yas-expand-from-keymap))
+     (yas-define-snippets
+      'text-mode '(("_1" "one!" "won" nil nil nil nil nil "uuid-1")))
+     (should (null (yas-lookup-snippet "one" nil 'noerror)))
+     (should (null (key-binding "\C-c1")))
+     (should (equal (yas-lookup-snippet "won") "one!")))))
+
+(ert-deftest snippet-save ()
+  "Make sure snippets can be saved correctly."
+  (yas-saving-variables
+   (yas-with-snippet-dirs
+    '((".emacs.d/snippets"
+       ("text-mode")))
+    (cl-letf (((symbol-function 'y-or-n-p) (lambda (&rest _) t))
+              ((symbol-function 'read-file-name)
+               (lambda (_prompt &optional _dir _default _mustmatch initial 
_predicate)
+                 (expand-file-name initial)))
+              ((symbol-function 'completing-read)
+               (lambda (_prompt collection &rest _)
+                 (or (car collection) ""))))
+      (with-temp-buffer
+        (text-mode)
+        (yas-minor-mode +1)
+        (save-current-buffer
+          (yas-new-snippet t)
+          (with-current-buffer "*new snippet*"
+            (snippet-mode)
+            (insert "# name: foo\n# key: bar\n# --\nsnippet foo")
+            (call-interactively 'yas-load-snippet-buffer-and-close)))
+        (save-current-buffer
+          (yas-new-snippet t)
+          (with-current-buffer "*new snippet*"
+            (snippet-mode)
+            (insert "# name: bar\n# key: bar\n# --\nsnippet bar")
+            (call-interactively 'yas-load-snippet-buffer-and-close)))
+        (should (file-readable-p
+                 (expand-file-name "foo" (car yas-snippet-dirs))))
+        (should (file-readable-p
+                 (expand-file-name "bar" (car yas-snippet-dirs)))))))))
+
 (ert-deftest visiting-compiled-snippets ()
   "Test snippet visiting for compiled snippets."
   (yas-with-some-interesting-snippet-dirs
    (yas-recompile-all)
    (yas-reload-all 'no-jit) ; must be loaded for `yas-lookup-snippet' to work.
-   (yas--with-temporary-redefinitions ((find-file-noselect
-                                        (filename &rest _)
-                                        (throw 'yas-snippet-file filename)))
+   (cl-letf (((symbol-function 'find-file-noselect)
+              (lambda (filename &rest _)
+                (throw 'yas-snippet-file filename))))
      (should (string-suffix-p
               "cc-mode/def"
               (catch 'yas-snippet-file
@@ -766,12 +808,12 @@ TODO: correct this bug!"
      (let ((menu (cdr (gethash 'fancy-mode yas--menu-table))))
        (should (eql 4 (length menu)))
        (dolist (item '("a-guy" "a-beggar"))
-         (should (find item menu :key #'third :test #'string=)))
-       (should-not (find "an-outcast" menu :key #'third :test #'string=))
+         (should (cl-find item menu :key #'cl-third :test #'string=)))
+       (should-not (cl-find "an-outcast" menu :key #'cl-third :test #'string=))
        (dolist (submenu '("sirs" "ladies"))
          (should (keymapp
-                  (fourth
-                   (find submenu menu :key #'third :test #'string=)))))
+                  (cl-fourth
+                   (cl-find submenu menu :key #'cl-third :test #'string=)))))
        ))))
 
 (ert-deftest test-group-menus ()
@@ -784,19 +826,19 @@ TODO: correct this bug!"
      (let ((menu (cdr (gethash 'c-mode yas--menu-table))))
        (should (eql 3 (length menu)))
        (dolist (item '("printf" "foo-group-a" "foo-group-b"))
-         (should (find item menu :key #'third :test #'string=)))
+         (should (cl-find item menu :key #'cl-third :test #'string=)))
        (dolist (submenu '("foo-group-a" "foo-group-b"))
          (should (keymapp
-                  (fourth
-                   (find submenu menu :key #'third :test #'string=))))))
+                  (cl-fourth
+                   (cl-find submenu menu :key #'cl-third :test #'string=))))))
      ;; now group directives
      ;;
      (let ((menu (cdr (gethash 'lisp-interaction-mode yas--menu-table))))
        (should (eql 1 (length menu)))
-       (should (find "barbar" menu :key #'third :test #'string=))
+       (should (cl-find "barbar" menu :key #'cl-third :test #'string=))
        (should (keymapp
-                (fourth
-                 (find "barbar" menu :key #'third :test #'string=))))))))
+                (cl-fourth
+                 (cl-find "barbar" menu :key #'cl-third :test #'string=))))))))
 
 (ert-deftest test-group-menus-twisted ()
   "Same as similarly named test, but be mean.
@@ -808,20 +850,20 @@ TODO: be meaner"
      ;; behaviour
      (with-temp-buffer
        (insert "# group: foo-group-c\n# --\nstrecmp($1)")
-       (write-region nil nil (concat (first (yas-snippet-dirs))
+       (write-region nil nil (concat (car (yas-snippet-dirs))
                                      "/c-mode/foo-group-b/strcmp")))
      (yas-reload-all 'no-jit)
      (let ((menu (cdr (gethash 'c-mode yas--menu-table))))
        (should (eql 4 (length menu)))
        (dolist (item '("printf" "foo-group-a" "foo-group-b" "foo-group-c"))
-         (should (find item menu :key #'third :test #'string=)))
+         (should (cl-find item menu :key #'cl-third :test #'string=)))
        (dolist (submenu '("foo-group-a" "foo-group-b" "foo-group-c"))
          (should (keymapp
-                  (fourth
-                   (find submenu menu :key #'third :test #'string=))))))
+                  (cl-fourth
+                   (cl-find submenu menu :key #'cl-third :test #'string=))))))
      ;; delete the .yas-make-groups file and watch behaviour
      ;;
-     (delete-file (concat (first (yas-snippet-dirs))
+     (delete-file (concat (car (yas-snippet-dirs))
                           "/c-mode/.yas-make-groups"))
      (yas-reload-all 'no-jit)
      (let ((menu (cdr (gethash 'c-mode yas--menu-table))))
@@ -829,19 +871,19 @@ TODO: be meaner"
      ;; Change a group directive and reload
      ;;
      (let ((menu (cdr (gethash 'lisp-interaction-mode yas--menu-table))))
-       (should (find "barbar" menu :key #'third :test #'string=)))
+       (should (cl-find "barbar" menu :key #'cl-third :test #'string=)))
 
      (with-temp-buffer
        (insert "# group: foofoo\n# --\n(ert-deftest ${1:name} () $0)")
-       (write-region nil nil (concat (first (yas-snippet-dirs))
+       (write-region nil nil (concat (car (yas-snippet-dirs))
                                      "/lisp-interaction-mode/ert-deftest")))
      (yas-reload-all 'no-jit)
      (let ((menu (cdr (gethash 'lisp-interaction-mode yas--menu-table))))
        (should (eql 1 (length menu)))
-       (should (find "foofoo" menu :key #'third :test #'string=))
+       (should (cl-find "foofoo" menu :key #'cl-third :test #'string=))
        (should (keymapp
-                (fourth
-                 (find "foofoo" menu :key #'third :test #'string=))))))))
+                (cl-fourth
+                 (cl-find "foofoo" menu :key #'cl-third :test #'string=))))))))
 
 
 ;;; The infamous and problematic tab keybinding
@@ -859,23 +901,21 @@ TODO: be meaner"
     (should (eq (key-binding [backtab]) 'yas-prev-field))))
 
 (ert-deftest test-rebindings ()
-  (unwind-protect
-      (progn
-        (define-key yas-minor-mode-map [tab] nil)
-        (define-key yas-minor-mode-map (kbd "TAB") nil)
-        (define-key yas-minor-mode-map (kbd "SPC") 'yas-expand)
-        (with-temp-buffer
-          (yas-minor-mode 1)
-          (should (not (eq (key-binding (yas--read-keybinding "TAB")) 
'yas-expand)))
-          (should (eq (key-binding (yas--read-keybinding "SPC")) 'yas-expand))
-          (yas-reload-all)
-          (should (not (eq (key-binding (yas--read-keybinding "TAB")) 
'yas-expand)))
-          (should (eq (key-binding (yas--read-keybinding "SPC")) 
'yas-expand))))
-    ;; FIXME: actually should restore to whatever saved values where there.
-    ;;
-    (define-key yas-minor-mode-map [tab] 'yas-expand)
-    (define-key yas-minor-mode-map (kbd "TAB") 'yas-expand)
-    (define-key yas-minor-mode-map (kbd "SPC") nil)))
+  (let* ((yas-minor-mode-map (copy-keymap yas-minor-mode-map))
+         (minor-mode-map-alist
+          (cons `(yas-minor-mode . ,yas-minor-mode-map)
+                (cl-remove 'yas-minor-mode minor-mode-map-alist
+                           :test #'eq :key #'car))))
+    (define-key yas-minor-mode-map [tab] nil)
+    (define-key yas-minor-mode-map (kbd "TAB") nil)
+    (define-key yas-minor-mode-map (kbd "SPC") 'yas-expand)
+    (with-temp-buffer
+      (yas-minor-mode 1)
+      (should-not (eq (key-binding (kbd "TAB")) 'yas-expand))
+      (should (eq (key-binding (kbd "SPC")) 'yas-expand))
+      (yas-reload-all)
+      (should-not (eq (key-binding (kbd "TAB")) 'yas-expand))
+      (should (eq (key-binding (kbd "SPC")) 'yas-expand)))))
 
 (ert-deftest test-yas-in-org ()
   (with-temp-buffer
@@ -973,13 +1013,13 @@ add the snippets associated with the given mode."
          (saved-values (mapcar #'symbol-value vars)))
     (unwind-protect
         (funcall fn)
-      (loop for var in vars
-            for saved in saved-values
-            do (set var saved)))))
+      (cl-loop for var in vars
+               for saved in saved-values
+               do (set var saved)))))
 
 (defun yas-call-with-snippet-dirs (dirs fn)
   (let* ((default-directory (make-temp-file "yasnippet-fixture" t))
-         (yas-snippet-dirs (mapcar #'car dirs)))
+         (yas-snippet-dirs (mapcar (lambda (d) (expand-file-name (car d))) 
dirs)))
     (with-temp-message ""
       (unwind-protect
           (progn
@@ -1016,16 +1056,8 @@ attention to case differences."
 (put 'yas-with-overriden-buffer-list         'edebug-form-spec t)
 (put 'yas-with-some-interesting-snippet-dirs 'edebug-form-spec t)
 
-
-(put 'yas--with-temporary-redefinitions 'lisp-indent-function 1)
-(put 'yas--with-temporary-redefinitions 'edebug-form-spec '((&rest (defun*)) 
cl-declarations body))
-
-
-
-
 (provide 'yasnippet-tests)
 ;; Local Variables:
 ;; indent-tabs-mode: nil
-;; byte-compile-warnings: (not cl-functions)
 ;; End:
 ;;; yasnippet-tests.el ends here
diff --git a/packages/yasnippet/yasnippet.el b/packages/yasnippet/yasnippet.el
index 9c741a6..a6977d1 100644
--- a/packages/yasnippet/yasnippet.el
+++ b/packages/yasnippet/yasnippet.el
@@ -5,10 +5,10 @@
 ;;          João Távora <address@hidden>,
 ;;          Noam Postavsky <address@hidden>
 ;; Maintainer: Noam Postavsky <address@hidden>
-;; Version: 0.10.0
-;; X-URL: http://github.com/capitaomorte/yasnippet
+;; Version: 0.11.0
+;; X-URL: http://github.com/joaotavora/yasnippet
 ;; Keywords: convenience, emulation
-;; URL: http://github.com/capitaomorte/yasnippet
+;; URL: http://github.com/joaotavora/yasnippet
 ;; Package-Requires: ((cl-lib "0.5"))
 ;; EmacsWiki: YaSnippetMode
 
@@ -127,11 +127,10 @@
 ;;   `custom-set-variables' is executed in your .emacs file.
 ;;
 ;;   For more information and detailed usage, refer to the project page:
-;;      http://github.com/capitaomorte/yasnippet
+;;      http://github.com/joaotavora/yasnippet
 
 ;;; Code:
 
-(require 'cl)
 (require 'cl-lib)
 (require 'easymenu)
 (require 'help-mode)
@@ -178,8 +177,6 @@ created with `yas-new-snippet'. "
   :type '(choice (directory :tag "Single directory")
                  (repeat :tag "List of directories"
                          (choice (directory) (variable))))
-  :group 'yasnippet
-  :require 'yasnippet
   :set #'(lambda (symbol new)
            (let ((old (and (boundp symbol)
                            (symbol-value symbol))))
@@ -207,11 +204,10 @@ created with `yas-new-snippet'. "
 # name: $1
 # key: ${2:${1:$(yas--key-from-desc yas-text)}}
 # --
-$0"
+$0`(yas-escape-text yas-selected-text)`"
   "Default snippet to use when creating a new snippet.
 If nil, don't use any snippet."
-  :type 'string
-  :group 'yasnippet)
+  :type 'string)
 
 (defcustom yas-prompt-functions '(yas-dropdown-prompt
                                   yas-completing-prompt
@@ -240,8 +236,7 @@ nil.
 signal `quit' with
 
   (signal \\='quit \"user quit!\")."
-  :type '(repeat function)
-  :group 'yasnippet)
+  :type '(repeat function))
 
 (defcustom yas-indent-line 'auto
   "Controls indenting applied to a recent snippet expansion.
@@ -257,28 +252,24 @@ after expansion (the manual per-line \"$>\" indentation 
still
 applies)."
   :type '(choice (const :tag "Nothing"  nothing)
                  (const :tag "Fixed"    fixed)
-                 (const :tag "Auto"     auto))
-  :group 'yasnippet)
+                 (const :tag "Auto"     auto)))
 
 (defcustom yas-also-auto-indent-first-line nil
   "Non-nil means also auto indent first line according to mode.
 
 Naturally this is only valid when `yas-indent-line' is `auto'"
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-snippet-revival t
   "Non-nil means re-activate snippet fields after undo/redo."
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-triggers-in-field nil
   "If non-nil, allow stacked expansions (snippets inside snippets).
 
 Otherwise `yas-next-field-or-maybe-expand' just moves on to the
 next field"
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-fallback-behavior 'call-other-command
   "How to act when `yas-expand' does *not* expand a snippet.
@@ -294,8 +285,7 @@ next field"
   COMMAND. If ARGS is non-nil, call COMMAND non-interactively
   with ARGS as arguments."
   :type '(choice (const :tag "Call previous command"  call-other-command)
-                 (const :tag "Do nothing"             return-nil))
-  :group 'yasnippet)
+                 (const :tag "Do nothing"             return-nil)))
 
 (defcustom yas-choose-keys-first nil
   "If non-nil, prompt for snippet key first, then for template.
@@ -303,8 +293,7 @@ next field"
 Otherwise prompts for all possible snippet names.
 
 This affects `yas-insert-snippet' and `yas-visit-snippet-file'."
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-choose-tables-first nil
   "If non-nil, and multiple eligible snippet tables, prompts user for tables 
first.
@@ -313,8 +302,7 @@ Otherwise, user chooses between the merging together of all
 eligible tables.
 
 This affects `yas-insert-snippet', `yas-visit-snippet-file'"
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-use-menu 'abbreviate
   "Display a YASnippet menu in the menu bar.
@@ -332,16 +320,14 @@ menu and the modes set in `yas--extra-modes' are listed.
 Any other non-nil value, every submenu is listed."
   :type '(choice (const :tag "Full"  full)
                  (const :tag "Abbreviate" abbreviate)
-                 (const :tag "No menu" nil))
-  :group 'yasnippet)
+                 (const :tag "No menu" nil)))
 
 (defcustom yas-trigger-symbol (or (and (eq window-system 'mac)
                                        (ignore-errors
                                          (char-to-string ?\x21E5))) ;; little 
->| sign
                                   " =>")
   "The text that will be used in menu to represent the trigger."
-  :type 'string
-  :group 'yasnippet)
+  :type 'string)
 
 (defcustom yas-wrap-around-region nil
   "What to insert for snippet's $0 field.
@@ -353,22 +339,19 @@ per-snippet basis.  A value of `cua' is considered 
equivalent to
   :type '(choice (character :tag "Insert from register")
                  (const t :tag "Insert region contents")
                  (const nil :tag "Don't insert anything")
-                 (const cua)) ; backwards compat
-  :group 'yasnippet)
+                 (const cua))) ; backwards compat
 
 (defcustom yas-good-grace t
   "If non-nil, don't raise errors in inline elisp evaluation.
 
 An error string \"[yas] error\" is returned instead."
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-visit-from-menu nil
   "If non-nil visit snippets's files from menu, instead of expanding them.
 
 This can only work when snippets are loaded from files."
-  :type 'boolean
-  :group 'yasnippet)
+  :type 'boolean)
 
 (defcustom yas-expand-only-for-last-commands nil
   "List of `last-command' values to restrict tab-triggering to, or nil.
@@ -381,8 +364,7 @@ Optionally, set this to something like 
(self-insert-command) if
 you to wish restrict expansion to only happen when the last
 letter of the snippet tab trigger was typed immediately before
 the trigger key itself."
-  :type '(repeat function)
-  :group 'yasnippet)
+  :type '(repeat function))
 
 (defcustom yas-alias-to-yas/prefix-p t
   "If non-nil make aliases for the old style yas/ prefixed symbols.
@@ -394,13 +376,11 @@ It must be set to nil before loading yasnippet to take 
effect."
 ;;
 (defface yas-field-highlight-face
   '((t (:inherit 'region)))
-  "The face used to highlight the currently active field of a snippet"
-  :group 'yasnippet)
+  "The face used to highlight the currently active field of a snippet")
 
 (defface yas--field-debug-face
   '()
-  "The face used for debugging some overlays normally hidden"
-  :group 'yasnippet)
+  "The face used for debugging some overlays normally hidden")
 
 
 ;;; User-visible variables
@@ -522,7 +502,7 @@ conditions.
  (add-hook \\='python-mode-hook
            (lambda ()
               (setq yas-buffer-local-condition
-                    \\='(if (python-in-string/comment)
+                    \\='(if (python-syntax-comment-or-string-p)
                          \\='(require-snippet-condition . force-in-comment)
                        t))))
 
@@ -534,7 +514,7 @@ snippet itself contains a condition that returns the symbol
 
 ;;; Internal variables
 
-(defconst yas--version "0.10.0")
+(defconst yas--version "0.11.0")
 
 (defvar yas--menu-table (make-hash-table)
   "A hash table of MAJOR-MODE symbols to menu keymaps.")
@@ -637,33 +617,33 @@ snippet itself contains a condition that returns the 
symbol
      )
     ("Prompting method"
      ["System X-widget" (setq yas-prompt-functions
-                              (cons 'yas-x-prompt
-                                    (remove 'yas-x-prompt
+                              (cons #'yas-x-prompt
+                                    (remove #'yas-x-prompt
                                             yas-prompt-functions)))
       :help "Use your windowing system's (gtk, mac, windows, etc...) default 
menu"
       :active t :style radio   :selected (eq (car yas-prompt-functions)
-                                             'yas-x-prompt)]
+                                             #'yas-x-prompt)]
      ["Dropdown-list" (setq yas-prompt-functions
-                            (cons 'yas-dropdown-prompt
-                                  (remove 'yas-dropdown-prompt
+                            (cons #'yas-dropdown-prompt
+                                  (remove #'yas-dropdown-prompt
                                           yas-prompt-functions)))
       :help "Use a special dropdown list"
       :active t :style radio   :selected (eq (car yas-prompt-functions)
-                                             'yas-dropdown-prompt)]
+                                             #'yas-dropdown-prompt)]
      ["Ido" (setq yas-prompt-functions
-                  (cons 'yas-ido-prompt
-                        (remove 'yas-ido-prompt
+                  (cons #'yas-ido-prompt
+                        (remove #'yas-ido-prompt
                                 yas-prompt-functions)))
       :help "Use an ido-style minibuffer prompt"
       :active t :style radio   :selected (eq (car yas-prompt-functions)
-                                             'yas-ido-prompt)]
+                                             #'yas-ido-prompt)]
      ["Completing read" (setq yas-prompt-functions
-                              (cons 'yas-completing-prompt
-                                    (remove 'yas-completing-prompt
+                              (cons #'yas-completing-prompt
+                                    (remove #'yas-completing-prompt
                                             yas-prompt-functions)))
       :help "Use a normal minibuffer prompt"
       :active t :style radio   :selected (eq (car yas-prompt-functions)
-                                             'yas-completing-prompt)]
+                                             #'yas-completing-prompt)]
      )
     ("Misc"
      ["Wrap region in exit marker"
@@ -776,10 +756,7 @@ Negative prefix argument turns off the mode.
 
 Key bindings:
 \\{yas-minor-mode-map}"
-  nil
-  ;; The indicator for the mode line.
-  " yas"
-  :group 'yasnippet
+  :lighter " yas" ;; The indicator for the mode line.
   (cond ((and yas-minor-mode (featurep 'yasnippet))
          ;; Install the direct keymaps in `emulation-mode-map-alists'
          ;; (we use `add-hook' even though it's not technically a hook,
@@ -872,9 +849,7 @@ Honour `yas-dont-activate-functions', which see."
     (yas-minor-mode 1)))
 
 ;;;###autoload
-(define-globalized-minor-mode yas-global-mode yas-minor-mode yas-minor-mode-on
-  :group 'yasnippet
-  :require 'yasnippet)
+(define-globalized-minor-mode yas-global-mode yas-minor-mode yas-minor-mode-on)
 
 (defun yas--global-mode-reload-with-jit-maybe ()
   "Run `yas-reload-all' when `yas-global-mode' is on."
@@ -913,9 +888,9 @@ Honour `yas-dont-activate-functions', which see."
       "Menu used when snippet-mode is active."
       (cons "Snippet"
             (mapcar #'(lambda (ent)
-                        (when (third ent)
-                          (define-key map (third ent) (second ent)))
-                        (vector (first ent) (second ent) t))
+                        (when (nth 2 ent)
+                          (define-key map (nth 2 ent) (nth 1 ent)))
+                        (vector (nth 0 ent) (nth 1 ent) t))
                     '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-l")
                       ("Load and quit window" 
yas-load-snippet-buffer-and-close "\C-c\C-c")
                       ("Try out this snippet" yas-tryout-snippet 
"\C-c\C-t")))))
@@ -929,7 +904,8 @@ Honour `yas-dont-activate-functions', which see."
   (setq font-lock-defaults '(yas--font-lock-keywords))
   (set (make-local-variable 'require-final-newline) nil)
   (set (make-local-variable 'comment-start) "#")
-  (set (make-local-variable 'comment-start-skip) "#+[\t ]*"))
+  (set (make-local-variable 'comment-start-skip) "#+[\t ]*")
+  (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t))
 
 
 
@@ -976,7 +952,7 @@ Honour `yas-dont-activate-functions', which see."
   table
   )
 
-(defstruct (yas--table (:constructor yas--make-snippet-table (name)))
+(cl-defstruct (yas--table (:constructor yas--make-snippet-table (name)))
   "A table to store snippets for a particular mode.
 
 Has the following fields:
@@ -1083,7 +1059,7 @@ Has the following fields:
         (maphash #'(lambda (k v)
                      (let ((template (gethash name v)))
                        (when (and template
-                                  (eq uuid (yas--template-uuid template)))
+                                  (equal uuid (yas--template-uuid template)))
                          (remhash name v)
                          (when (zerop (hash-table-count v))
                            (push k empty-keys)))))
@@ -1151,9 +1127,9 @@ Return TEMPLATE."
     (unless (eq (cdr menu-binding-pair) :none)
       ;; the menu item name
       ;;
-      (setf (cadar menu-binding-pair) (yas--template-name template))
+      (setf (cl-cadar menu-binding-pair) (yas--template-name template))
       ;; the :keys information (also visible to the user)
-      (setf (getf (cdr (car menu-binding-pair)) :keys)
+      (setf (cl-getf (cdr (car menu-binding-pair)) :keys)
             (or (and keybinding (key-description keybinding))
                 (and key (concat key yas-trigger-symbol))))))
   (unless (yas--template-menu-managed-by-yas-define-menu template)
@@ -1164,7 +1140,7 @@ Return TEMPLATE."
           (group (yas--template-group template)))
       ;; Remove from menu keymap
       ;;
-      (assert menu-keymap)
+      (cl-assert menu-keymap)
       (yas--delete-from-keymap menu-keymap (yas--template-uuid template))
 
       ;; Add necessary subgroups as necessary.
@@ -1227,10 +1203,10 @@ This function implements the rules described in
   (let ((requirement (yas--require-template-specific-condition-p)))
     (if (eq requirement 'always)
         templates
-      (remove-if-not #'(lambda (pair)
-                         (yas--template-can-expand-p
-                          (yas--template-condition (cdr pair)) requirement))
-                     templates))))
+      (cl-remove-if-not (lambda (pair)
+                          (yas--template-can-expand-p
+                           (yas--template-condition (cdr pair)) requirement))
+                        templates))))
 
 (defun yas--require-template-specific-condition-p ()
   "Decide if this buffer requests/requires snippet-specific
@@ -1299,9 +1275,9 @@ Returns (TEMPLATES START END). This function respects
           (save-excursion
             (goto-char original)
             (setq templates
-                  (mapcan #'(lambda (table)
-                              (yas--fetch table possible-key))
-                          (yas--get-snippet-tables))))))
+                  (cl-mapcan (lambda (table)
+                               (yas--fetch table possible-key))
+                             (yas--get-snippet-tables))))))
       (when templates
         (list templates (point) original)))))
 
@@ -1555,31 +1531,31 @@ Optional PROMPT sets the prompt to use."
           (sort templates #'(lambda (t1 t2)
                               (< (length (yas--template-name t1))
                                  (length (yas--template-name t2))))))
-    (some #'(lambda (fn)
-              (funcall fn (or prompt "Choose a snippet: ")
-                       templates
-                       #'yas--template-name))
-          yas-prompt-functions)))
+    (cl-some (lambda (fn)
+               (funcall fn (or prompt "Choose a snippet: ")
+                        templates
+                        #'yas--template-name))
+             yas-prompt-functions)))
 
 (defun yas--prompt-for-keys (keys &optional prompt)
   "Interactively choose a template key from the list KEYS.
 
 Optional PROMPT sets the prompt to use."
   (when keys
-    (some #'(lambda (fn)
-              (funcall fn (or prompt "Choose a snippet key: ") keys))
-          yas-prompt-functions)))
+    (cl-some (lambda (fn)
+               (funcall fn (or prompt "Choose a snippet key: ") keys))
+             yas-prompt-functions)))
 
 (defun yas--prompt-for-table (tables &optional prompt)
   "Interactively choose a table from the list TABLES.
 
 Optional PROMPT sets the prompt to use."
   (when tables
-    (some #'(lambda (fn)
-              (funcall fn (or prompt "Choose a snippet table: ")
-                       tables
-                       #'yas--table-name))
-          yas-prompt-functions)))
+    (cl-some (lambda (fn)
+               (funcall fn (or prompt "Choose a snippet table: ")
+                        tables
+                        #'yas--table-name))
+             yas-prompt-functions)))
 
 (defun yas-x-prompt (prompt choices &optional display-fn)
   "Display choices in a x-window prompt."
@@ -1596,9 +1572,10 @@ Optional PROMPT sets the prompt to use."
                   (selected-window)))
         t)
       `(,prompt ("title"
-                 ,@(mapcar* (lambda (c d) `(,(concat "   " d) . ,c))
-                            choices
-                            (if display-fn (mapcar display-fn choices) 
choices)))))
+                 ,@(cl-mapcar (lambda (c d) `(,(concat "   " d) . ,c))
+                              choices
+                              (if display-fn (mapcar display-fn choices)
+                                choices)))))
      (keyboard-quit))))
 
 (defun yas-maybe-ido-prompt (prompt choices &optional display-fn)
@@ -1625,11 +1602,11 @@ Optional PROMPT sets the prompt to use."
                           nil 'require-match nil nil)))
     (if (eq choices formatted-choices)
         chosen
-      (nth (or (position chosen formatted-choices :test #'string=) 0)
+      (nth (or (cl-position chosen formatted-choices :test #'string=) 0)
            choices))))
 
 (defun yas-no-prompt (_prompt choices &optional _display-fn)
-  (first choices))
+  (cl-first choices))
 
 
 ;;; Defining snippets
@@ -1719,7 +1696,7 @@ the current buffers contents."
 
 (defun yas--define-parents (mode parents)
   "Add PARENTS to the list of MODE's parents."
-  (puthash mode (remove-duplicates
+  (puthash mode (cl-remove-duplicates
                  (append parents
                          (gethash mode yas--parents)))
            yas--parents))
@@ -1835,7 +1812,7 @@ prompt the user to select one."
                    (yas--message 4 "Loaded %s" directory)
                  (yas--message 4 "Prepared just-in-time loading for %s" 
directory)))
               (t
-               (push (yas--message 0 "Check your `yas-snippet-dirs': %s is not 
a directory" directory) errors)))))
+               (push (yas--message 1 "Check your `yas-snippet-dirs': %s is not 
a directory" directory) errors)))))
     errors))
 
 (defun yas-reload-all (&optional no-jit interactive)
@@ -1851,9 +1828,10 @@ prefix argument."
   (catch 'abort
     (let ((errors)
           (snippet-editing-buffers
-           (remove-if-not #'(lambda (buffer)
-                              (with-current-buffer buffer 
yas--editing-template))
-                          (buffer-list))))
+           (cl-remove-if-not (lambda (buffer)
+                               (with-current-buffer buffer
+                                 yas--editing-template))
+                             (buffer-list))))
       ;; Warn if there are buffers visiting snippets, since reloading will 
break
       ;; any on-line editing of those buffers.
       ;;
@@ -1914,18 +1892,11 @@ prefix argument."
         (funcall fun))
       (remhash mode yas--scheduled-jit-loads))))
 
-;; (when (<= emacs-major-version 22)
-;;   (add-hook 'after-change-major-mode-hook 'yas--load-pending-jits))
-
-(defun yas--quote-string (string)
-  "Escape and quote STRING.
-foo\"bar\\! -> \"foo\\\"bar\\\\!\""
-  (concat "\""
-          (replace-regexp-in-string "[\\\"]"
-                                    "\\\\\\&"
-                                    string
-                                    t)
-          "\""))
+(defun yas-escape-text (text)
+  "Escape TEXT for snippet."
+  (when text
+    (replace-regexp-in-string "[\\$]" "\\\\\\&" text)))
+
 
 ;;; Snippet compilation function
 
@@ -2017,10 +1988,9 @@ static in the menu."
 
 (defun yas--show-menu-p (mode)
   (cond ((eq yas-use-menu 'abbreviate)
-         (find mode
-               (mapcar #'(lambda (table)
-                           (yas--table-mode table))
-                       (yas--get-snippet-tables))))
+         (cl-find mode
+                  (mapcar #'yas--table-mode
+                          (yas--get-snippet-tables))))
         (yas-use-menu t)))
 
 (defun yas--delete-from-keymap (keymap uuid)
@@ -2034,19 +2004,19 @@ static in the menu."
   ;;
   (mapc #'(lambda (item)
             (when (and (listp (cdr item))
-                       (keymapp (third (cdr item))))
-              (yas--delete-from-keymap (third (cdr item)) uuid)))
-        (rest keymap))
+                       (keymapp (nth 2 (cdr item))))
+              (yas--delete-from-keymap (nth 2 (cdr item)) uuid)))
+        (cdr keymap))
   ;; Set the uuid entry to nil
   ;;
   (define-key keymap (vector (make-symbol uuid)) nil)
   ;; Destructively modify keymap
   ;;
-  (setcdr keymap (delete-if #'(lambda (item)
-                                (or (null (cdr item))
-                                    (and (keymapp (third (cdr item)))
-                                         (null (cdr (third (cdr item)))))))
-                            (rest keymap))))
+  (setcdr keymap (cl-delete-if (lambda (item)
+                                 (or (null (cdr item))
+                                     (and (keymapp (nth 2 (cdr item)))
+                                          (null (cdr (nth 2 (cdr item)))))))
+                               (cdr keymap))))
 
 (defun yas-define-menu (mode menu &optional omit-items)
   "Define a snippet menu for MODE according to MENU, omitting OMIT-ITEMS.
@@ -2081,31 +2051,37 @@ omitted from MODE's menu, even if they're manually 
loaded."
 
 (defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional 
group-list)
   "Helper for `yas-define-menu'."
-  (dolist (e (reverse menu))
-    (cond ((eq (first e) 'yas-item)
-           (let ((template (or (gethash (second e) uuidhash)
-                               (puthash (second e)
-                                        (yas--make-template
-                                         :table table
-                                         :perm-group group-list
-                                         :uuid (second e))
-                                        uuidhash))))
-             (define-key menu-keymap (vector (gensym))
-               (car (yas--template-menu-binding-pair-get-create template 
:stay)))))
-          ((eq (first e) 'yas-submenu)
-           (let ((subkeymap (make-sparse-keymap)))
-             (define-key menu-keymap (vector (gensym))
-               `(menu-item ,(second e) ,subkeymap))
-             (yas--define-menu-1 table
-                                subkeymap
-                                (third e)
-                                uuidhash
-                                (append group-list (list (second e))))))
-          ((eq (first e) 'yas-separator)
-           (define-key menu-keymap (vector (gensym))
-             '(menu-item "----")))
-          (t
-           (yas--message 1 "Don't know anything about menu entry %s" (first 
e))))))
+  (cl-loop
+   for (type name submenu) in (reverse menu)
+   if (or (eq type 'yas-item)
+          (and yas-alias-to-yas/prefix-p
+               (eq type 'yas/item)))
+   do (let ((template (or (gethash name uuidhash)
+                          (puthash name
+                                   (yas--make-template
+                                    :table table
+                                    :perm-group group-list
+                                    :uuid name)
+                                   uuidhash))))
+        (define-key menu-keymap (vector (cl-gensym))
+          (car (yas--template-menu-binding-pair-get-create template :stay))))
+   else if (or (eq type 'yas-submenu)
+               (and yas-alias-to-yas/prefix-p
+                    (eq type 'yas/submenu)))
+   do (let ((subkeymap (make-sparse-keymap)))
+        (define-key menu-keymap (vector (cl-gensym))
+          `(menu-item ,name ,subkeymap))
+        (yas--define-menu-1 table
+                            subkeymap
+                            submenu
+                            uuidhash
+                            (append group-list (list name))))
+   else if (or (eq type 'yas-separator)
+               (and yas-alias-to-yas/prefix-p
+                    (eq type 'yas/separator)))
+   do (define-key menu-keymap (vector (cl-gensym))
+        '(menu-item "----"))
+   else do (yas--message 1 "Don't know anything about menu entry %s" type)))
 
 (defun yas--define (mode key template &optional name condition group)
   "Define a snippet.  Expanding KEY into TEMPLATE.
@@ -2194,12 +2170,13 @@ object satisfying `yas--field-p' to restrict the 
expansion to."
 If expansion fails, execute the previous binding for this key"
   (interactive)
   (setq yas--condition-cache-timestamp (current-time))
-  (let* ((vec (subseq (this-command-keys-vector) (if current-prefix-arg
-                                                     (length 
(this-command-keys))
-                                                   0)))
-         (templates (mapcan #'(lambda (table)
-                                (yas--fetch table vec))
-                            (yas--get-snippet-tables))))
+  (let* ((vec (cl-subseq (this-command-keys-vector)
+                         (if current-prefix-arg
+                             (length (this-command-keys))
+                           0)))
+         (templates (cl-mapcan (lambda (table)
+                                 (yas--fetch table vec))
+                               (yas--get-snippet-tables))))
     (if templates
         (yas--expand-or-prompt-for-template templates)
       (let ((yas-fallback-behavior 'call-other-command))
@@ -2211,7 +2188,7 @@ If expansion fails, execute the previous binding for this 
key"
 Prompt the user if TEMPLATES has more than one element, else
 expand immediately.  Common gateway for
 `yas-expand-from-trigger-key' and `yas-expand-from-keymap'."
-  (let ((yas--current-template (or (and (rest templates) ;; more than one
+  (let ((yas--current-template (or (and (cl-rest templates) ;; more than one
                                         (yas--prompt-for-template (mapcar 
#'cdr templates)))
                                    (cdar templates))))
     (when yas--current-template
@@ -2249,7 +2226,7 @@ Common gateway for `yas-expand-from-trigger-key' and
                 (yas-minor-mode nil)
                 (beyond-yasnippet (yas--keybinding-beyond-yasnippet)))
            (yas--message 4 "Falling back to %s"  beyond-yasnippet)
-           (assert (or (null beyond-yasnippet) (commandp beyond-yasnippet)))
+           (cl-assert (or (null beyond-yasnippet) (commandp beyond-yasnippet)))
            (setq this-command beyond-yasnippet)
            (when beyond-yasnippet
              (call-interactively beyond-yasnippet))))
@@ -2314,13 +2291,13 @@ Honours `yas-choose-tables-first', 
`yas-choose-keys-first' and
   (mapcar #'cdr
           (if yas-choose-keys-first
               (let ((key (yas--prompt-for-keys
-                          (mapcan #'yas--table-all-keys tables))))
+                          (cl-mapcan #'yas--table-all-keys tables))))
                 (when key
-                  (mapcan #'(lambda (table)
-                              (yas--fetch table key))
-                          tables)))
-            (remove-duplicates (mapcan #'yas--table-templates tables)
-                               :test #'equal))))
+                  (cl-mapcan (lambda (table)
+                               (yas--fetch table key))
+                             tables)))
+            (cl-remove-duplicates (cl-mapcan #'yas--table-templates tables)
+                                  :test #'equal))))
 
 (defun yas--lookup-snippet-1 (name mode)
   "Get the snippet called NAME in MODE's tables."
@@ -2357,7 +2334,7 @@ by condition."
                                          yas-buffer-local-condition))
          (templates (yas--all-templates (yas--get-snippet-tables)))
          (yas--current-template (and templates
-                                    (or (and (rest templates) ;; more than one 
template for same key
+                                    (or (and (cl-rest templates) ;; more than 
one template for same key
                                              (yas--prompt-for-template 
templates))
                                         (car templates))))
          (where (if (region-active-p)
@@ -2415,15 +2392,15 @@ visited file in `snippet-mode'."
                          (pp-to-string (yas--template-content template))
                        (yas--template-content template))))
            (snippet-mode)
-           (set (make-local-variable 'yas--editing-template) template)))))
+           (set (make-local-variable 'yas--editing-template) template)
+           (set (make-local-variable 'default-directory)
+                (car (cdr (car (yas--guess-snippet-directories 
(yas--template-table template))))))))))
 
 (defun yas--guess-snippet-directories-1 (table)
   "Guess possible snippet subdirectories for TABLE."
-  (cons (yas--table-name table)
-        (mapcan #'(lambda (parent)
-                    (yas--guess-snippet-directories-1
-                     parent))
-                (yas--table-parents table))))
+  (cons (file-name-as-directory (yas--table-name table))
+        (cl-mapcan #'yas--guess-snippet-directories-1
+                   (yas--table-parents table))))
 
 (defun yas--guess-snippet-directories (&optional table)
   "Try to guess suitable directories based on the current active
@@ -2452,8 +2429,9 @@ where snippets of table might exist."
 
 (defun yas--make-directory-maybe (table-and-dirs &optional main-table-string)
   "Return a dir inside TABLE-AND-DIRS, prompts for creation if none exists."
-  (or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr 
table-and-dirs))
-      (let ((candidate (first (cdr table-and-dirs))))
+  (or (cl-some (lambda (dir) (when (file-directory-p dir) dir))
+               (cdr table-and-dirs))
+      (let ((candidate (cl-first (cdr table-and-dirs))))
         (unless (file-writable-p (file-name-directory candidate))
           (error (yas--format "%s is not writable." candidate)))
         (if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" 
does not exist! Create? "
@@ -2476,16 +2454,22 @@ where snippets of table might exist."
 Expands a snippet-writing snippet, unless the optional prefix arg
 NO-TEMPLATE is non-nil."
   (interactive "P")
-  (let ((guessed-directories (yas--guess-snippet-directories)))
+  (let ((guessed-directories (yas--guess-snippet-directories))
+        (yas-selected-text (or yas-selected-text
+                               (and (region-active-p)
+                                    (buffer-substring-no-properties
+                                     (region-beginning) (region-end))))))
 
     (switch-to-buffer "*new snippet*")
     (erase-buffer)
     (kill-all-local-variables)
     (snippet-mode)
     (yas-minor-mode 1)
-    (set (make-local-variable 'yas--guessed-modes) (mapcar #'(lambda (d)
-                                                              (yas--table-mode 
(car d)))
-                                                          guessed-directories))
+    (set (make-local-variable 'yas--guessed-modes)
+         (mapcar (lambda (d) (yas--table-mode (car d)))
+                 guessed-directories))
+    (set (make-local-variable 'default-directory)
+         (car (cdr (car guessed-directories))))
     (if (and (not no-template) yas-new-snippet-default)
         (yas-expand-snippet yas-new-snippet-default))))
 
@@ -2498,12 +2482,13 @@ representing one or more of the mode's parents.
 Note that MODE-SYM need not be the symbol of a real major mode,
 neither do the elements of PARENTS."
   (let* ((file-dir (and file
-                        (directory-file-name (or (some #'(lambda (special)
-                                                           
(locate-dominating-file file special))
-                                                       '(".yas-setup.el"
-                                                         ".yas-make-groups"
-                                                         ".yas-parents"))
-                                                 (directory-file-name 
(file-name-directory file))))))
+                        (directory-file-name
+                         (or (cl-some (lambda (special)
+                                        (locate-dominating-file file special))
+                                      '(".yas-setup.el"
+                                        ".yas-make-groups"
+                                        ".yas-parents"))
+                             (directory-file-name (file-name-directory 
file))))))
          (parents-file-name (concat file-dir "/.yas-parents"))
          (major-mode-name (and file-dir
                                (file-name-nondirectory file-dir)))
@@ -2539,20 +2524,21 @@ neither do the elements of PARENTS."
     (intern
      (funcall prompt (format "Choose or enter a table (yas guesses %s): "
                              (if yas--guessed-modes
-                                 (first yas--guessed-modes)
+                                 (cl-first yas--guessed-modes)
                                "nothing"))
               (mapcar #'symbol-name yas--guessed-modes)
               nil
               nil
               nil
               nil
-              (if (first yas--guessed-modes)
-                  (symbol-name (first yas--guessed-modes)))))))
+              (if (cl-first yas--guessed-modes)
+                  (symbol-name (cl-first yas--guessed-modes)))))))
 
 (defun yas-load-snippet-buffer (table &optional interactive)
   "Parse and load current buffer's snippet definition into TABLE.
 TABLE is a symbol name passed to `yas--table-get-create'.  When
-called interactively, prompt for the table name."
+called interactively, prompt for the table name.
+Return the `yas--template' object created"
   (interactive (list (yas--read-table) t))
   (cond
    ;;  We have `yas--editing-template', this buffer's content comes from a
@@ -2574,7 +2560,23 @@ called interactively, prompt for the table name."
   (when interactive
     (yas--message 3 "Snippet \"%s\" loaded for %s."
                   (yas--template-name yas--editing-template)
-                  (yas--table-name (yas--template-table 
yas--editing-template)))))
+                  (yas--table-name (yas--template-table 
yas--editing-template))))
+  yas--editing-template)
+
+(defun yas-maybe-load-snippet-buffer ()
+  "Added to `after-save-hook' in `snippet-mode'."
+  (let* ((mode (intern (file-name-sans-extension
+                        (file-name-nondirectory
+                         (directory-file-name default-directory)))))
+         (current-snippet
+          (apply #'yas--define-snippets-2 (yas--table-get-create mode)
+                 (yas--parse-template buffer-file-name)))
+         (uuid (yas--template-uuid current-snippet)))
+    (unless (equal current-snippet
+                   (if uuid (yas--get-template-by-uuid mode uuid)
+                     (yas--lookup-snippet-1
+                      (yas--template-name current-snippet) mode)))
+      (yas-load-snippet-buffer mode t))))
 
 (defun yas-load-snippet-buffer-and-close (table &optional kill)
   "Load and save the snippet, then `quit-window' if saved.
@@ -2587,31 +2589,20 @@ The prefix argument KILL is passed to `quit-window'.
 Don't use this from a Lisp program, call `yas-load-snippet-buffer'
 and `kill-buffer' instead."
   (interactive (list (yas--read-table) current-prefix-arg))
-  (yas-load-snippet-buffer table t)
-  (let ((file (yas--template-get-file yas--editing-template)))
-    (when (and (or
-                ;; Only offer to save this if it looks like a library or new
-                ;; snippet (loaded from elisp, from a dir in `yas-snippet-dirs'
-                ;; which is not the first, or from an unwritable file)
-                ;;
-                (not file)
-                (not (file-writable-p file))
-                (and (cdr-safe yas-snippet-dirs)
-                     (not (string-prefix-p (expand-file-name (car 
yas-snippet-dirs)) file))))
-               (y-or-n-p (yas--format "Looks like a library or new snippet. 
Save to new file? ")))
-      (let* ((option (first (yas--guess-snippet-directories 
(yas--template-table yas--editing-template))))
-             (chosen (and option
-                          (yas--make-directory-maybe option))))
-        (when chosen
-          (let ((default-file-name (or (and file (file-name-nondirectory file))
-                                       (yas--template-name 
yas--editing-template))))
-            (write-file (expand-file-name
-                         (read-file-name (format "File name to create in %s? " 
chosen)
-                                         chosen default-file-name)
-                         chosen))
-            (setf (yas--template-load-file yas--editing-template) 
buffer-file-name))))))
-  (when buffer-file-name
-    (save-buffer)
+  (let ((template (yas-load-snippet-buffer table t)))
+    (when (and (buffer-modified-p)
+               (y-or-n-p
+                (format "[yas] Loaded for %s. Also save snippet buffer?"
+                        (yas--table-name (yas--template-table template)))))
+      (let ((default-directory (car (cdr (car (yas--guess-snippet-directories
+                                               (yas--template-table 
template))))))
+            (default-file-name (yas--template-name template)))
+        (unless (or buffer-file-name (not default-file-name))
+          (setq buffer-file-name
+                (read-file-name "File to save snippet in: "
+                                nil nil nil default-file-name))
+          (rename-buffer (file-name-nondirectory buffer-file-name) t))
+        (save-buffer)))
     (quit-window kill)))
 
 (defun yas-tryout-snippet (&optional debug)
@@ -2622,7 +2613,7 @@ and `kill-buffer' instead."
          (test-mode (or (and (car major-mode-and-parent)
                              (fboundp (car major-mode-and-parent))
                              (car major-mode-and-parent))
-                        (first yas--guessed-modes)
+                        (cl-first yas--guessed-modes)
                         (intern (read-from-minibuffer (yas--format "Please 
input a mode: ")))))
          (yas--current-template
           (and parsed
@@ -2645,73 +2636,66 @@ and `kill-buffer' instead."
                                  (point-max)
                                  (yas--template-expand-env 
yas--current-template))
              (when (and debug
-                        (require 'yasnippet-debug nil t))
-               (add-hook 'post-command-hook 'yas-debug-snippet-vars nil t))))
+                        (require 'yasnippet-debug nil t)
+                        (fboundp 'yas-debug-snippet-vars))
+               (add-hook 'post-command-hook #'yas-debug-snippet-vars nil t))))
           (t
            (yas--message 1 "Cannot test snippet for unknown major mode")))))
 
 (defun yas-active-keys ()
   "Return all active trigger keys for current buffer and point."
-  (remove-duplicates
-   (remove-if-not #'stringp (mapcan #'yas--table-all-keys 
(yas--get-snippet-tables)))
+  (cl-remove-duplicates
+   (cl-remove-if-not #'stringp (cl-mapcan #'yas--table-all-keys
+                                          (yas--get-snippet-tables)))
    :test #'string=))
 
 (defun yas--template-fine-group (template)
   (car (last (or (yas--template-group template)
                  (yas--template-perm-group template)))))
 
-(defun yas-describe-tables (&optional choose)
+(defun yas-describe-table-by-namehash ()
+  "Display snippet tables by NAMEHASH."
+  (interactive)
+  (with-current-buffer (get-buffer-create "*YASnippet Tables by NAMEHASH*")
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (insert "YASnippet tables by NAMEHASH: \n")
+      (maphash
+       (lambda (_mode table)
+         (insert (format "\nSnippet table `%s':\n\n" (yas--table-name table)))
+         (maphash
+          (lambda (key _v)
+            (insert (format "   key %s maps snippets: %s\n" key
+                            (let ((names))
+                              (maphash #'(lambda (k _v)
+                                           (push k names))
+                                       (gethash key (yas--table-hash table)))
+                              names))))
+          (yas--table-hash table)))
+       yas--tables))
+    (view-mode +1)
+    (goto-char 1)
+    (display-buffer (current-buffer))))
+
+(defun yas-describe-tables (&optional with-nonactive)
   "Display snippets for each table."
   (interactive "P")
-  (let* ((by-name-hash (and choose
-                            (y-or-n-p "Show by namehash? ")))
-         (buffer (get-buffer-create "*YASnippet tables*"))
-         (active-tables (yas--get-snippet-tables))
-         (remain-tables (let ((all))
-                          (maphash #'(lambda (_k v)
-                                       (unless (find v active-tables)
-                                         (push v all)))
-                                   yas--tables)
-                          all))
-         (table-lists (list active-tables remain-tables))
-         (original-buffer (current-buffer))
-         (continue t)
-         (yas--condition-cache-timestamp (current-time)))
-    (with-current-buffer buffer
-      (setq buffer-read-only nil)
-      (erase-buffer)
-      (cond ((not by-name-hash)
-             (insert "YASnippet tables:\n")
-             (while (and table-lists
-                         continue)
-               (dolist (table (car table-lists))
-                 (yas--describe-pretty-table table original-buffer))
-               (setq table-lists (cdr table-lists))
-               (when table-lists
-                 (yas--create-snippet-xrefs)
-                 (display-buffer buffer)
-                 (setq continue (and choose (y-or-n-p "Show also non-active 
tables? ")))))
-             (yas--create-snippet-xrefs)
-             (help-mode)
-             (goto-char 1))
-            (t
-             (insert "\n\nYASnippet tables by NAMEHASH: \n")
-             (dolist (table (append active-tables remain-tables))
-               (insert (format "\nSnippet table `%s':\n\n" (yas--table-name 
table)))
-               (let ((keys))
-                 (maphash #'(lambda (k _v)
-                              (push k keys))
-                          (yas--table-hash table))
-                 (dolist (key keys)
-                   (insert (format "   key %s maps snippets: %s\n" key
-                                   (let ((names))
-                                     (maphash #'(lambda (k _v)
-                                                  (push k names))
-                                              (gethash key (yas--table-hash 
table)))
-                                     names))))))))
-      (goto-char 1)
-      (setq buffer-read-only t))
-    (display-buffer buffer)))
+  (let ((original-buffer (current-buffer))
+        (tables (yas--get-snippet-tables)))
+   (with-current-buffer (get-buffer-create "*YASnippet Tables*")
+     (let ((inhibit-read-only t))
+       (when with-nonactive
+         (maphash #'(lambda (_k v)
+                      (cl-pushnew v tables))
+                  yas--tables))
+       (erase-buffer)
+       (insert "YASnippet tables:\n")
+       (dolist (table tables)
+         (yas--describe-pretty-table table original-buffer))
+       (yas--create-snippet-xrefs))
+     (help-mode)
+     (goto-char 1)
+     (display-buffer (current-buffer)))))
 
 (defun yas--describe-pretty-table (table &optional original-buffer)
   (insert (format "\nSnippet table `%s'"
@@ -2827,16 +2811,16 @@ The last element of POSSIBILITIES may be a list of 
strings."
       (when (listp last-elem)
         (setcar last-link (car last-elem))
         (setcdr last-link (cdr last-elem))))
-    (some #'(lambda (fn)
-              (funcall fn "Choose: " possibilities))
-          yas-prompt-functions)))
+    (cl-some (lambda (fn)
+               (funcall fn "Choose: " possibilities))
+             yas-prompt-functions)))
 
 (defun yas-key-to-value (alist)
   (unless (or yas-moving-away-p
               yas-modified-p)
     (let ((key (read-key-sequence "")))
       (when (stringp key)
-        (or (cdr (find key alist :key #'car :test #'string=))
+        (or (cdr (cl-find key alist :key #'car :test #'string=))
             key)))))
 
 (defun yas-throw (text)
@@ -2847,7 +2831,8 @@ The last element of POSSIBILITIES may be a list of 
strings."
   "Verify that the current field value is in POSSIBILITIES.
 
 Otherwise throw exception."
-  (when (and yas-moving-away-p (notany #'(lambda (pos) (string= pos yas-text)) 
possibilities))
+  (when (and yas-moving-away-p
+             (cl-notany (lambda (pos) (string= pos yas-text)) possibilities))
     (yas-throw (yas--format "Field only allows %s" possibilities))))
 
 (defun yas-field-value (number)
@@ -2914,7 +2899,7 @@ Use this in primary and mirror transformations to tget."
 (put 'yas--active-field-overlay 'permanent-local t)
 (put 'yas--field-protection-overlays 'permanent-local t)
 
-(defstruct (yas--snippet (:constructor yas--make-snippet ()))
+(cl-defstruct (yas--snippet (:constructor yas--make-snippet ()))
   "A snippet.
 
 ..."
@@ -2928,7 +2913,7 @@ Use this in primary and mirror transformations to tget."
   previous-active-field
   force-exit)
 
-(defstruct (yas--field (:constructor yas--make-field (number start end 
parent-field)))
+(cl-defstruct (yas--field (:constructor yas--make-field (number start end 
parent-field)))
   "A field.
 
 NUMBER is the field number.
@@ -2948,7 +2933,7 @@ NEXT is another `yas--field' or `yas--mirror' or 
`yas--exit'.
   next)
 
 
-(defstruct (yas--mirror (:constructor yas--make-mirror (start end transform)))
+(cl-defstruct (yas--mirror (:constructor yas--make-mirror (start end 
transform)))
   "A mirror.
 
 START and END are mostly buffer markers, but see \"apropos markers-to-points\".
@@ -2962,7 +2947,7 @@ DEPTH is a count of how many nested mirrors can affect 
this mirror"
   next
   depth)
 
-(defstruct (yas--exit (:constructor yas--make-exit (marker)))
+(cl-defstruct (yas--exit (:constructor yas--make-exit (marker)))
   marker
   next)
 
@@ -2999,9 +2984,9 @@ With optional string TEXT do it in that string."
       (replace-match to t t text))))
 
 (defun yas--snippet-find-field (snippet number)
-  (find-if #'(lambda (field)
-               (eq number (yas--field-number field)))
-           (yas--snippet-fields snippet)))
+  (cl-find-if (lambda (field)
+                (eq number (yas--field-number field)))
+              (yas--snippet-fields snippet)))
 
 (defun yas--snippet-sort-fields (snippet)
   "Sort the fields of SNIPPET in navigation order."
@@ -3091,8 +3076,7 @@ Otherwise delegate to `yas-next-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))))))
+    (nth (abs n) (memq active (if (>= n 0) live-fields (reverse 
live-fields))))))
 
 (defun yas-next-field (&optional arg)
   "Navigate to the ARGth next field.
@@ -3155,7 +3139,7 @@ Also create some protection overlays"
 
 (defun yas-exit-snippet (snippet)
   "Goto exit-marker of SNIPPET."
-  (interactive (list (first (yas--snippets-at-point))))
+  (interactive (list (cl-first (yas--snippets-at-point))))
   (when snippet
     (setf (yas--snippet-force-exit snippet) t)
     (goto-char (if (yas--snippet-exit snippet)
@@ -3222,7 +3206,7 @@ This renders the snippet as ordinary text."
       ;; again from `yas--take-care-of-redo'....
       (setf (yas--snippet-fields snippet) nil)))
 
-  (yas--message 3 "Snippet %s exited." (yas--snippet-id snippet)))
+  (yas--message 4 "Snippet %s exited." (yas--snippet-id snippet)))
 
 (defun yas--safely-run-hooks (hook-var)
   (condition-case error
@@ -3428,14 +3412,15 @@ field start.  This hook does nothing if an undo is in 
progress."
     (let* ((inhibit-modification-hooks t)
            (field (overlay-get overlay 'yas--field))
            (snippet (overlay-get yas--active-field-overlay 'yas--snippet)))
-      (when (yas--skip-and-clear-field-p field beg end length)
-        ;; We delete text starting from the END of insertion.
-        (yas--skip-and-clear field end))
-      (setf (yas--field-modified-p field) t)
-      (yas--advance-end-maybe field (overlay-end overlay))
-      (save-excursion
-        (yas--field-update-display field))
-      (yas--update-mirrors snippet))))
+      (save-match-data
+        (when (yas--skip-and-clear-field-p field beg end length)
+          ;; We delete text starting from the END of insertion.
+          (yas--skip-and-clear field end))
+        (setf (yas--field-modified-p field) t)
+        (yas--advance-end-maybe field (overlay-end overlay))
+        (save-excursion
+          (yas--field-update-display field))
+        (yas--update-mirrors snippet)))))
 
 ;;; Apropos protection overlays:
 ;;
@@ -3466,9 +3451,10 @@ Move the overlays, or create them if they do not exit."
     ;; go on to normal overlay creation/moving
     ;;
     (cond ((and yas--field-protection-overlays
-                (every #'overlay-buffer yas--field-protection-overlays))
-           (move-overlay (first yas--field-protection-overlays) (1- start) 
start)
-           (move-overlay (second yas--field-protection-overlays) end (1+ end)))
+                (cl-every #'overlay-buffer yas--field-protection-overlays))
+           (move-overlay (nth 0 yas--field-protection-overlays)
+                         (1- start) start)
+           (move-overlay (nth 1 yas--field-protection-overlays) end (1+ end)))
           (t
            (setq yas--field-protection-overlays
                  (list (make-overlay (1- start) start nil t nil)
@@ -3770,7 +3756,7 @@ has to be called before the $-constructs are deleted."
       (setq soup
             (sort soup compare-fom-begs))
       (when soup
-        (reduce link-foms soup)))))
+        (cl-reduce link-foms soup)))))
 
 (defun yas--calculate-mirrors-in-fields (snippet mirror)
   "Attempt to assign a parent field of SNIPPET to the mirror MIRROR.
@@ -4021,20 +4007,37 @@ With optional string TEXT do it in string instead of 
the buffer."
 (defun yas--save-backquotes ()
   "Save all the \"\\=`(lisp-expression)\\=`\"-style expressions
 with their evaluated value into `yas--backquote-markers-and-strings'."
-  (while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
-    (let ((current-string (match-string-no-properties 1)) transformed)
-      (save-restriction (widen)
-                        (delete-region (match-beginning 0) (match-end 0)))
-      (setq transformed (yas--eval-lisp (yas--read-lisp (yas--restore-escapes 
current-string '(?`)))))
-      (goto-char (match-beginning 0))
-      (when transformed
-        (let ((marker (make-marker)))
-          (save-restriction
-            (widen)
-            (insert "Y") ;; quite horrendous, I love it :)
-            (set-marker marker (point))
-            (insert "Y"))
-          (push (cons marker transformed) 
yas--backquote-markers-and-strings))))))
+  (let* ((yas--snippet-buffer (current-buffer))
+         (yas--change-detected nil)
+         (detect-change (lambda (_beg _end)
+                          (when (eq (current-buffer) yas--snippet-buffer)
+                            (setq yas--change-detected t)))))
+    (while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
+      (let ((current-string (match-string-no-properties 1)) transformed)
+        (save-restriction (widen)
+                          (delete-region (match-beginning 0) (match-end 0)))
+        (let ((before-change-functions
+               (cons detect-change before-change-functions)))
+          (setq transformed (yas--eval-lisp (yas--read-lisp
+                                             (yas--restore-escapes
+                                              current-string '(?`))))))
+        (goto-char (match-beginning 0))
+        (when transformed
+          (let ((marker (make-marker))
+                (before-change-functions (cdr before-change-functions)))
+            (save-restriction
+              (widen)
+              (insert "Y") ;; quite horrendous, I love it :)
+              (set-marker marker (point))
+              (insert "Y"))
+            (push (cons marker transformed) 
yas--backquote-markers-and-strings)))))
+    (when yas--change-detected
+      (lwarn '(yasnippet backquote-change) :warning
+             "`%s' modified buffer in a backquote expression.
+  To hide this warning, add (yasnippet backquote-change) to 
`warning-suppress-types'."
+             (if yas--current-template
+                 (yas--template-name yas--current-template)
+               "Snippet")))))
 
 (defun yas--restore-backquotes ()
   "Replace markers in `yas--backquote-markers-and-strings' with their values."
@@ -4211,19 +4214,15 @@ When multiple expressions are found, only the last one 
counts."
                                (yas--field-mirrors parent))))
     (or (yas--mirror-depth mirror)
         (setf (yas--mirror-depth mirror)
-              (cond ((memq mirror traversed)
-                     0)
+              (cond ((memq mirror traversed) 0)
                     ((and parent parents-mirrors)
-                     (1+ (reduce #'max
-                                 (mapcar #'(lambda (m)
-                                             (yas--calculate-mirror-depth m
-                                                                          
(cons mirror
-                                                                               
 traversed)))
-                                         parents-mirrors))))
-                    (parent
-                     1)
-                    (t
-                     0))))))
+                     (1+ (cl-reduce
+                          #'max parents-mirrors
+                          :key (lambda (m)
+                                 (yas--calculate-mirror-depth
+                                  m (cons mirror traversed))))))
+                    (parent 1)
+                    (t 0))))))
 
 (defun yas--update-mirrors (snippet)
   "Update all the mirrors of SNIPPET."
@@ -4238,7 +4237,11 @@ When multiple expressions are found, only the last one 
counts."
                 (cl-mapcan #'(lambda (field)
                                (mapcar #'(lambda (mirror)
                                            (cons field mirror))
-                                       (yas--field-mirrors field)))
+                                       (cl-sort
+                                        (cl-copy-list
+                                         (yas--field-mirrors field))
+                                        #'<
+                                        :key #'yas--mirror-start)))
                            (yas--snippet-fields snippet))
                 ;; then sort this list so that entries with mirrors with parent
                 ;; fields appear before. This was important for fixing #290, 
and
@@ -4319,12 +4322,14 @@ When multiple expressions are found, only the last one 
counts."
          ;; restored correctly, this condition handles that
          ;;
          (let* ((snippet (car (yas--snippets-at-point)))
-                (target-field (and snippet
-                                   (find-if-not #'(lambda (field)
-                                                    
(yas--field-probably-deleted-p snippet field))
-                                                (remove nil
-                                                        (cons 
(yas--snippet-active-field snippet)
-                                                              
(yas--snippet-fields snippet)))))))
+                (target-field
+                 (and snippet
+                      (cl-find-if-not
+                       (lambda (field)
+                         (yas--field-probably-deleted-p snippet field))
+                       (remq nil
+                             (cons (yas--snippet-active-field snippet)
+                                   (yas--snippet-fields snippet)))))))
            (when target-field
              (yas--move-to-field snippet target-field))))
         ((not (yas--undo-in-progress))
@@ -4366,9 +4371,9 @@ object satisfying `yas--field-p' to restrict the 
expansion to.")))
   (concat "Expand/run snippets from keymaps, possibly falling back to original 
binding.\n"
           (when (and context (eq this-command 'describe-key))
             (let* ((vec (this-single-command-keys))
-                   (templates (mapcan #'(lambda (table)
-                                          (yas--fetch table vec))
-                                      (yas--get-snippet-tables)))
+                   (templates (cl-mapcan (lambda (table)
+                                           (yas--fetch table vec))
+                                         (yas--get-snippet-tables)))
                    (yas--direct-keymaps nil)
                    (fallback (key-binding vec)))
               (concat "In this case, "
@@ -4417,8 +4422,8 @@ object satisfying `yas--field-p' to restrict the 
expansion to.")))
   "Log level for `yas--message' 4 means trace most anything, 0 means nothing.")
 
 (defun yas--message (level message &rest args)
-  "When LEVEL is above `yas-verbosity-level', log MESSAGE and ARGS."
-  (when (> yas-verbosity level)
+  "When LEVEL is at or below `yas-verbosity-level', log MESSAGE and ARGS."
+  (when (>= yas-verbosity level)
     (message "%s" (apply #'yas--format message args))))
 
 (defun yas--warning (format-control &rest format-args)
@@ -4637,6 +4642,5 @@ can more or less safely rely upon them.")
 ;; Local Variables:
 ;; coding: utf-8
 ;; indent-tabs-mode: nil
-;; byte-compile-warnings: (not cl-functions)
 ;; End:
 ;;; yasnippet.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]