summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2015-04-28 15:22:10 +0200
committerSimeon Simeonov2015-04-28 15:22:10 +0200
commiteeeaae3a34ca050c9ea30aa3950dc91db70b9b1a (patch)
tree0758aced8efbf64efa34a8de295c22bc8b2bc224
parent5f664d715dacfd3f81a057e17da3465a6838b85f (diff)
Upgrade yasnippet to 0.8.1
-rw-r--r--.emacs.d/lisp/yasnippet.el103
1 files changed, 41 insertions, 62 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index bbfca9c..305bb95 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -1,6 +1,6 @@
1;;; yasnippet.el --- Yet another snippet extension for Emacs. 1;;; yasnippet.el --- Yet another snippet extension for Emacs.
2 2
3;; Copyright (C) 2008-2013 Free Software Foundation, Inc. 3;; Copyright (C) 2008-2013, 2015 Free Software Foundation, Inc.
4;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com> 4;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com>
5;; Maintainer: João Távora <joaotavora@gmail.com> 5;; Maintainer: João Távora <joaotavora@gmail.com>
6;; Version: 0.8.1 6;; Version: 0.8.1
@@ -41,7 +41,7 @@
41;; stored. Can also be a list of directories. In that case, 41;; stored. Can also be a list of directories. In that case,
42;; when used for bulk (re)loading of snippets (at startup or 42;; when used for bulk (re)loading of snippets (at startup or
43;; via `yas-reload-all'), directories appearing earlier in 43;; via `yas-reload-all'), directories appearing earlier in
44;; the list shadow other dir's snippets. Also, the first 44;; the list override other dir's snippets. Also, the first
45;; directory is taken as the default for storing the user's 45;; directory is taken as the default for storing the user's
46;; new snippets. 46;; new snippets.
47;; 47;;
@@ -165,7 +165,7 @@ Each element, a string or a symbol whose value is a string,
165designates a top-level directory where per-mode snippet 165designates a top-level directory where per-mode snippet
166directories can be found. 166directories can be found.
167 167
168Elements appearing earlier in the list shadow later elements' 168Elements appearing earlier in the list override later elements'
169snippets. 169snippets.
170 170
171The first directory is taken as the default for storing snippet's 171The first directory is taken as the default for storing snippet's
@@ -526,10 +526,6 @@ snippet itself contains a condition that returns the symbol
526(defvar yas--menu-table (make-hash-table) 526(defvar yas--menu-table (make-hash-table)
527 "A hash table of MAJOR-MODE symbols to menu keymaps.") 527 "A hash table of MAJOR-MODE symbols to menu keymaps.")
528 528
529(defvar yas--known-modes
530 '(ruby-mode rst-mode markdown-mode)
531 "A list of mode which is well known but not part of Emacs.")
532
533(defvar yas--escaped-characters 529(defvar yas--escaped-characters
534 '(?\\ ?` ?\" ?' ?$ ?} ?{ ?\( ?\)) 530 '(?\\ ?` ?\" ?' ?$ ?} ?{ ?\( ?\))
535 "List of characters which *might* need to be escaped.") 531 "List of characters which *might* need to be escaped.")
@@ -916,7 +912,7 @@ Honour `yas-dont-activate', which see."
916 912
917;;; Internal structs for template management 913;;; Internal structs for template management
918 914
919(defstruct (yas--template (:constructor yas--make-blank-template)) 915(defstruct (yas--template (:constructor yas--make-template))
920 "A template for a snippet." 916 "A template for a snippet."
921 key 917 key
922 content 918 content
@@ -932,16 +928,6 @@ Honour `yas-dont-activate', which see."
932 table 928 table
933 ) 929 )
934 930
935(defun yas--populate-template (template &rest args)
936 "Helper function to populate TEMPLATE with properties."
937 (while args
938 (aset template
939 (position (intern (substring (symbol-name (car args)) 1))
940 (mapcar #'car (get 'yas--template 'cl-struct-slots)))
941 (second args))
942 (setq args (cddr args)))
943 template)
944
945(defstruct (yas--table (:constructor yas--make-snippet-table (name))) 931(defstruct (yas--table (:constructor yas--make-snippet-table (name)))
946 "A table to store snippets for a particular mode. 932 "A table to store snippets for a particular mode.
947 933
@@ -1283,16 +1269,6 @@ Returns (TEMPLATES START END). This function respects
1283 1269
1284;;; Internal functions and macros: 1270;;; Internal functions and macros:
1285 1271
1286(defun yas--real-mode? (mode)
1287 "Try to find out if MODE is a real mode.
1288
1289The MODE bound to a function (like `c-mode') is considered real
1290mode. Other well known mode like `ruby-mode' which is not part of
1291Emacs might not bound to a function until it is loaded. So
1292yasnippet keeps a list of modes like this to help the judgment."
1293 (or (fboundp mode)
1294 (find mode yas--known-modes)))
1295
1296(defun yas--handle-error (err) 1272(defun yas--handle-error (err)
1297 "Handle error depending on value of `yas-good-grace'." 1273 "Handle error depending on value of `yas-good-grace'."
1298 (let ((msg (yas--format "elisp error: %s" (error-message-string err)))) 1274 (let ((msg (yas--format "elisp error: %s" (error-message-string err))))
@@ -1634,20 +1610,19 @@ Optional PROMPT sets the prompt to use."
1634 (uuid (or (ninth snippet) 1610 (uuid (or (ninth snippet)
1635 name)) 1611 name))
1636 (template (or (gethash uuid (yas--table-uuidhash snippet-table)) 1612 (template (or (gethash uuid (yas--table-uuidhash snippet-table))
1637 (yas--make-blank-template)))) 1613 (yas--make-template :uuid uuid
1614 :table snippet-table))))
1638 ;; X) populate the template object 1615 ;; X) populate the template object
1639 ;; 1616 ;;
1640 (yas--populate-template template 1617 (setf (yas--template-key template) key)
1641 :table snippet-table 1618 (setf (yas--template-content template) (second snippet))
1642 :key key 1619 (setf (yas--template-name template) (or name key))
1643 :content (second snippet) 1620 (setf (yas--template-group template) group)
1644 :name (or name key) 1621 (setf (yas--template-condition template) condition)
1645 :group group 1622 (setf (yas--template-expand-env template) (sixth snippet))
1646 :condition condition 1623 (setf (yas--template-file template) (seventh snippet))
1647 :expand-env (sixth snippet) 1624 (setf (yas--template-keybinding template) keybinding)
1648 :file (seventh snippet) 1625
1649 :keybinding keybinding
1650 :uuid uuid)
1651 ;; X) Update this template in the appropriate table. This step 1626 ;; X) Update this template in the appropriate table. This step
1652 ;; also will take care of adding the key indicators in the 1627 ;; also will take care of adding the key indicators in the
1653 ;; templates menu entry, if any 1628 ;; templates menu entry, if any
@@ -1727,10 +1702,10 @@ the current buffers contents."
1727(defun yas--load-yas-setup-file (file) 1702(defun yas--load-yas-setup-file (file)
1728 (if (not yas--creating-compiled-snippets) 1703 (if (not yas--creating-compiled-snippets)
1729 ;; Normal case. 1704 ;; Normal case.
1730 (load file 'noerror) 1705 (load file 'noerror (<= yas-verbosity 2))
1731 (let ((elfile (concat file ".el"))) 1706 (let ((elfile (concat file ".el")))
1732 (when (file-exists-p elfile) 1707 (when (file-exists-p elfile)
1733 (insert ";;; .yas-setup.el support file if any:\n;;;\n") 1708 (insert ";;; contents of the .yas-setup.el support file:\n;;;\n")
1734 (insert-file-contents elfile) 1709 (insert-file-contents elfile)
1735 (goto-char (point-max)))))) 1710 (goto-char (point-max))))))
1736 1711
@@ -2085,11 +2060,10 @@ omitted from MODE's menu, even if they're manually loaded."
2085 hash) 2060 hash)
2086 (dolist (uuid omit-items) 2061 (dolist (uuid omit-items)
2087 (let ((template (or (gethash uuid hash) 2062 (let ((template (or (gethash uuid hash)
2088 (yas--populate-template (puthash uuid 2063 (puthash uuid
2089 (yas--make-blank-template) 2064 (yas--make-template :table table
2090 hash) 2065 :uuid uuid)
2091 :table table 2066 hash))))
2092 :uuid uuid))))
2093 (setf (yas--template-menu-binding-pair template) (cons nil :none)))))) 2067 (setf (yas--template-menu-binding-pair template) (cons nil :none))))))
2094 2068
2095(defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list) 2069(defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list)
@@ -2097,12 +2071,12 @@ omitted from MODE's menu, even if they're manually loaded."
2097 (dolist (e (reverse menu)) 2071 (dolist (e (reverse menu))
2098 (cond ((eq (first e) 'yas-item) 2072 (cond ((eq (first e) 'yas-item)
2099 (let ((template (or (gethash (second e) uuidhash) 2073 (let ((template (or (gethash (second e) uuidhash)
2100 (yas--populate-template (puthash (second e) 2074 (puthash (second e)
2101 (yas--make-blank-template) 2075 (yas--make-template
2102 uuidhash) 2076 :table table
2103 :table table 2077 :perm-group group-list
2104 :perm-group group-list 2078 :uuid (second e))
2105 :uuid (second e))))) 2079 uuidhash))))
2106 (define-key menu-keymap (vector (gensym)) 2080 (define-key menu-keymap (vector (gensym))
2107 (car (yas--template-menu-binding-pair-get-create template :stay))))) 2081 (car (yas--template-menu-binding-pair-get-create template :stay)))))
2108 ((eq (first e) 'yas-submenu) 2082 ((eq (first e) 'yas-submenu)
@@ -2621,12 +2595,11 @@ and `kill-buffer' instead."
2621 (yas--current-template 2595 (yas--current-template
2622 (and parsed 2596 (and parsed
2623 (fboundp test-mode) 2597 (fboundp test-mode)
2624 (yas--populate-template (yas--make-blank-template) 2598 (yas--make-template :table nil ;; no tables for ephemeral snippets
2625 :table nil ;; no tables for ephemeral snippets 2599 :key (first parsed)
2626 :key (first parsed) 2600 :content (second parsed)
2627 :content (second parsed) 2601 :name (third parsed)
2628 :name (third parsed) 2602 :expand-env (sixth parsed)))))
2629 :expand-env (sixth parsed)))))
2630 (cond (yas--current-template 2603 (cond (yas--current-template
2631 (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template)))) 2604 (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template))))
2632 (kill-buffer (get-buffer-create buffer-name)) 2605 (kill-buffer (get-buffer-create buffer-name))
@@ -3043,7 +3016,8 @@ through the field's start point"
3043 ;; the field numbered 0, just before the exit marker, should 3016 ;; the field numbered 0, just before the exit marker, should
3044 ;; never be skipped 3017 ;; never be skipped
3045 ;; 3018 ;;
3046 (not (zerop (yas--field-number field))))) 3019 (not (and (yas--field-number field)
3020 (zerop (yas--field-number field))))))
3047 3021
3048(defun yas--snippets-at-point (&optional all-snippets) 3022(defun yas--snippets-at-point (&optional all-snippets)
3049 "Return a sorted list of snippets at point. 3023 "Return a sorted list of snippets at point.
@@ -3514,8 +3488,12 @@ The error should be ignored in `debug-ignored-errors'"
3514 "Expand snippet CONTENT at current point. 3488 "Expand snippet CONTENT at current point.
3515 3489
3516Text between START and END will be deleted before inserting 3490Text between START and END will be deleted before inserting
3517template. EXPAND-ENV is are let-style variable to value bindings 3491template. EXPAND-ENV is a list of (SYM VALUE) let-style dynamic bindings
3518considered when expanding the snippet." 3492considered when expanding the snippet."
3493 (cl-assert (and yas-minor-mode
3494 (memq 'yas--post-command-handler post-command-hook))
3495 nil
3496 "[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'")
3519 (run-hooks 'yas-before-expand-snippet-hook) 3497 (run-hooks 'yas-before-expand-snippet-hook)
3520 3498
3521 ;; 3499 ;;
@@ -4314,7 +4292,7 @@ When multiple expressions are found, only the last one counts."
4314 (or (and fallback 4292 (or (and fallback
4315 (format "call command `%s'." 4293 (format "call command `%s'."
4316 (pp-to-string fallback))) 4294 (pp-to-string fallback)))
4317 "do nothing (`yas-expand' doesn't shadow\nanything)."))) 4295 "do nothing (`yas-expand' doesn't override\nanything).")))
4318 ((eq yas-fallback-behavior 'return-nil) 4296 ((eq yas-fallback-behavior 'return-nil)
4319 "do nothing.") 4297 "do nothing.")
4320 (t "defer to `yas-fallback-behavior' (which see).")))) 4298 (t "defer to `yas-fallback-behavior' (which see)."))))
@@ -4456,6 +4434,7 @@ and return the directory. Return nil if not found."
4456 4434
4457(defun yas-initialize () 4435(defun yas-initialize ()
4458 "For backward compatibility, enable `yas-minor-mode' globally." 4436 "For backward compatibility, enable `yas-minor-mode' globally."
4437 (declare (obsolete "Use (yas-global-mode 1) instead." "0.8"))
4459 (yas-global-mode 1)) 4438 (yas-global-mode 1))
4460 4439
4461(defvar yas--backported-syms '(;; `defcustom's 4440(defvar yas--backported-syms '(;; `defcustom's