From eeeaae3a34ca050c9ea30aa3950dc91db70b9b1a Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 28 Apr 2015 15:22:10 +0200 Subject: Upgrade yasnippet to 0.8.1 --- .emacs.d/lisp/yasnippet.el | 103 ++++++++++++++++++--------------------------- 1 file 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 @@ ;;; yasnippet.el --- Yet another snippet extension for Emacs. -;; Copyright (C) 2008-2013 Free Software Foundation, Inc. +;; Copyright (C) 2008-2013, 2015 Free Software Foundation, Inc. ;; Authors: pluskid , João Távora ;; Maintainer: João Távora ;; Version: 0.8.1 @@ -41,7 +41,7 @@ ;; stored. Can also be a list of directories. In that case, ;; when used for bulk (re)loading of snippets (at startup or ;; via `yas-reload-all'), directories appearing earlier in -;; the list shadow other dir's snippets. Also, the first +;; the list override other dir's snippets. Also, the first ;; directory is taken as the default for storing the user's ;; new snippets. ;; @@ -165,7 +165,7 @@ Each element, a string or a symbol whose value is a string, designates a top-level directory where per-mode snippet directories can be found. -Elements appearing earlier in the list shadow later elements' +Elements appearing earlier in the list override later elements' snippets. The first directory is taken as the default for storing snippet's @@ -526,10 +526,6 @@ snippet itself contains a condition that returns the symbol (defvar yas--menu-table (make-hash-table) "A hash table of MAJOR-MODE symbols to menu keymaps.") -(defvar yas--known-modes - '(ruby-mode rst-mode markdown-mode) - "A list of mode which is well known but not part of Emacs.") - (defvar yas--escaped-characters '(?\\ ?` ?\" ?' ?$ ?} ?{ ?\( ?\)) "List of characters which *might* need to be escaped.") @@ -916,7 +912,7 @@ Honour `yas-dont-activate', which see." ;;; Internal structs for template management -(defstruct (yas--template (:constructor yas--make-blank-template)) +(defstruct (yas--template (:constructor yas--make-template)) "A template for a snippet." key content @@ -932,16 +928,6 @@ Honour `yas-dont-activate', which see." table ) -(defun yas--populate-template (template &rest args) - "Helper function to populate TEMPLATE with properties." - (while args - (aset template - (position (intern (substring (symbol-name (car args)) 1)) - (mapcar #'car (get 'yas--template 'cl-struct-slots))) - (second args)) - (setq args (cddr args))) - template) - (defstruct (yas--table (:constructor yas--make-snippet-table (name))) "A table to store snippets for a particular mode. @@ -1283,16 +1269,6 @@ Returns (TEMPLATES START END). This function respects ;;; Internal functions and macros: -(defun yas--real-mode? (mode) - "Try to find out if MODE is a real mode. - -The MODE bound to a function (like `c-mode') is considered real -mode. Other well known mode like `ruby-mode' which is not part of -Emacs might not bound to a function until it is loaded. So -yasnippet keeps a list of modes like this to help the judgment." - (or (fboundp mode) - (find mode yas--known-modes))) - (defun yas--handle-error (err) "Handle error depending on value of `yas-good-grace'." (let ((msg (yas--format "elisp error: %s" (error-message-string err)))) @@ -1634,20 +1610,19 @@ Optional PROMPT sets the prompt to use." (uuid (or (ninth snippet) name)) (template (or (gethash uuid (yas--table-uuidhash snippet-table)) - (yas--make-blank-template)))) + (yas--make-template :uuid uuid + :table snippet-table)))) ;; X) populate the template object ;; - (yas--populate-template template - :table snippet-table - :key key - :content (second snippet) - :name (or name key) - :group group - :condition condition - :expand-env (sixth snippet) - :file (seventh snippet) - :keybinding keybinding - :uuid uuid) + (setf (yas--template-key template) key) + (setf (yas--template-content template) (second snippet)) + (setf (yas--template-name template) (or name key)) + (setf (yas--template-group template) group) + (setf (yas--template-condition template) condition) + (setf (yas--template-expand-env template) (sixth snippet)) + (setf (yas--template-file template) (seventh snippet)) + (setf (yas--template-keybinding template) keybinding) + ;; X) Update this template in the appropriate table. This step ;; also will take care of adding the key indicators in the ;; templates menu entry, if any @@ -1727,10 +1702,10 @@ the current buffers contents." (defun yas--load-yas-setup-file (file) (if (not yas--creating-compiled-snippets) ;; Normal case. - (load file 'noerror) + (load file 'noerror (<= yas-verbosity 2)) (let ((elfile (concat file ".el"))) (when (file-exists-p elfile) - (insert ";;; .yas-setup.el support file if any:\n;;;\n") + (insert ";;; contents of the .yas-setup.el support file:\n;;;\n") (insert-file-contents elfile) (goto-char (point-max)))))) @@ -2085,11 +2060,10 @@ omitted from MODE's menu, even if they're manually loaded." hash) (dolist (uuid omit-items) (let ((template (or (gethash uuid hash) - (yas--populate-template (puthash uuid - (yas--make-blank-template) - hash) - :table table - :uuid uuid)))) + (puthash uuid + (yas--make-template :table table + :uuid uuid) + hash)))) (setf (yas--template-menu-binding-pair template) (cons nil :none)))))) (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." (dolist (e (reverse menu)) (cond ((eq (first e) 'yas-item) (let ((template (or (gethash (second e) uuidhash) - (yas--populate-template (puthash (second e) - (yas--make-blank-template) - uuidhash) - :table table - :perm-group group-list - :uuid (second e))))) + (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) @@ -2621,12 +2595,11 @@ and `kill-buffer' instead." (yas--current-template (and parsed (fboundp test-mode) - (yas--populate-template (yas--make-blank-template) - :table nil ;; no tables for ephemeral snippets - :key (first parsed) - :content (second parsed) - :name (third parsed) - :expand-env (sixth parsed))))) + (yas--make-template :table nil ;; no tables for ephemeral snippets + :key (first parsed) + :content (second parsed) + :name (third parsed) + :expand-env (sixth parsed))))) (cond (yas--current-template (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template)))) (kill-buffer (get-buffer-create buffer-name)) @@ -3043,7 +3016,8 @@ through the field's start point" ;; the field numbered 0, just before the exit marker, should ;; never be skipped ;; - (not (zerop (yas--field-number field))))) + (not (and (yas--field-number field) + (zerop (yas--field-number field)))))) (defun yas--snippets-at-point (&optional all-snippets) "Return a sorted list of snippets at point. @@ -3514,8 +3488,12 @@ The error should be ignored in `debug-ignored-errors'" "Expand snippet CONTENT at current point. Text between START and END will be deleted before inserting -template. EXPAND-ENV is are let-style variable to value bindings +template. EXPAND-ENV is a list of (SYM VALUE) let-style dynamic bindings considered when expanding the snippet." + (cl-assert (and yas-minor-mode + (memq 'yas--post-command-handler post-command-hook)) + nil + "[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'") (run-hooks 'yas-before-expand-snippet-hook) ;; @@ -4314,7 +4292,7 @@ When multiple expressions are found, only the last one counts." (or (and fallback (format "call command `%s'." (pp-to-string fallback))) - "do nothing (`yas-expand' doesn't shadow\nanything)."))) + "do nothing (`yas-expand' doesn't override\nanything)."))) ((eq yas-fallback-behavior 'return-nil) "do nothing.") (t "defer to `yas-fallback-behavior' (which see).")))) @@ -4456,6 +4434,7 @@ and return the directory. Return nil if not found." (defun yas-initialize () "For backward compatibility, enable `yas-minor-mode' globally." + (declare (obsolete "Use (yas-global-mode 1) instead." "0.8")) (yas-global-mode 1)) (defvar yas--backported-syms '(;; `defcustom's -- cgit v1.3