Getting rid of low-level assumptions in yasnippet

The main thrust is to get rid of the use of the `cl-struct-slots'
property which doesn't exist in Emacs-25 any more.

* yasnippet.el: Update copyright
(yas--template): Change constructor name from
`yas--make-blank-template' to `yas--make-template'
(yas--populate-template): Remove.
(yas--define-snippets-1): Use `yas--make-template'
(yas--define-snippets-1): Use `setf's
(yas-define-menu, yas--define-menu-1, yas-tryout-snippet): Use
`yas--make-template'
This commit is contained in:
Stefan Monnier 2015-03-20 10:34:33 +00:00 committed by João Távora
parent fc5052b863
commit d19ef74634

View File

@ -1,6 +1,6 @@
;;; yasnippet.el --- Yet another snippet extension for Emacs. ;;; 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 <pluskid@gmail.com>, João Távora <joaotavora@gmail.com> ;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com>
;; Maintainer: João Távora <joaotavora@gmail.com> ;; Maintainer: João Távora <joaotavora@gmail.com>
;; Version: 0.8.1 ;; Version: 0.8.1
@ -912,7 +912,7 @@ Honour `yas-dont-activate', which see."
;;; Internal structs for template management ;;; 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." "A template for a snippet."
key key
content content
@ -928,16 +928,6 @@ Honour `yas-dont-activate', which see."
table 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))) (defstruct (yas--table (:constructor yas--make-snippet-table (name)))
"A table to store snippets for a particular mode. "A table to store snippets for a particular mode.
@ -1620,20 +1610,19 @@ Optional PROMPT sets the prompt to use."
(uuid (or (ninth snippet) (uuid (or (ninth snippet)
name)) name))
(template (or (gethash uuid (yas--table-uuidhash snippet-table)) (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 ;; X) populate the template object
;; ;;
(yas--populate-template template (setf (yas--template-key template) key)
:table snippet-table (setf (yas--template-content template) (second snippet))
:key key (setf (yas--template-name template) (or name key))
:content (second snippet) (setf (yas--template-group template) group)
:name (or name key) (setf (yas--template-condition template) condition)
:group group (setf (yas--template-expand-env template) (sixth snippet))
:condition condition (setf (yas--template-file template) (seventh snippet))
:expand-env (sixth snippet) (setf (yas--template-keybinding template) keybinding)
:file (seventh snippet)
:keybinding keybinding
:uuid uuid)
;; X) Update this template in the appropriate table. This step ;; X) Update this template in the appropriate table. This step
;; also will take care of adding the key indicators in the ;; also will take care of adding the key indicators in the
;; templates menu entry, if any ;; templates menu entry, if any
@ -2071,11 +2060,10 @@ omitted from MODE's menu, even if they're manually loaded."
hash) hash)
(dolist (uuid omit-items) (dolist (uuid omit-items)
(let ((template (or (gethash uuid hash) (let ((template (or (gethash uuid hash)
(yas--populate-template (puthash uuid (puthash uuid
(yas--make-blank-template) (yas--make-template :table table
hash) :uuid uuid)
:table table hash))))
:uuid uuid))))
(setf (yas--template-menu-binding-pair template) (cons nil :none)))))) (setf (yas--template-menu-binding-pair template) (cons nil :none))))))
(defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list) (defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list)
@ -2083,12 +2071,12 @@ omitted from MODE's menu, even if they're manually loaded."
(dolist (e (reverse menu)) (dolist (e (reverse menu))
(cond ((eq (first e) 'yas-item) (cond ((eq (first e) 'yas-item)
(let ((template (or (gethash (second e) uuidhash) (let ((template (or (gethash (second e) uuidhash)
(yas--populate-template (puthash (second e) (puthash (second e)
(yas--make-blank-template) (yas--make-template
uuidhash) :table table
:table table :perm-group group-list
:perm-group group-list :uuid (second e))
:uuid (second e))))) uuidhash))))
(define-key menu-keymap (vector (gensym)) (define-key menu-keymap (vector (gensym))
(car (yas--template-menu-binding-pair-get-create template :stay))))) (car (yas--template-menu-binding-pair-get-create template :stay)))))
((eq (first e) 'yas-submenu) ((eq (first e) 'yas-submenu)
@ -2607,12 +2595,11 @@ and `kill-buffer' instead."
(yas--current-template (yas--current-template
(and parsed (and parsed
(fboundp test-mode) (fboundp test-mode)
(yas--populate-template (yas--make-blank-template) (yas--make-template :table nil ;; no tables for ephemeral snippets
:table nil ;; no tables for ephemeral snippets :key (first parsed)
:key (first parsed) :content (second parsed)
:content (second parsed) :name (third parsed)
:name (third parsed) :expand-env (sixth parsed)))))
:expand-env (sixth parsed)))))
(cond (yas--current-template (cond (yas--current-template
(let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template)))) (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template))))
(kill-buffer (get-buffer-create buffer-name)) (kill-buffer (get-buffer-create buffer-name))