Modified yas/compile-bundle to make the bundle ELPA compatible

This commit is contained in:
Zhang Chiyuan 2009-02-10 05:29:05 +00:00
parent 69bd61b9b2
commit 29d3991eb7

View File

@ -1,10 +1,13 @@
;;; yasnippet.el --- Yet another snippet extension for Emacs. ;;; yasnippet.el --- Yet another snippet extension for Emacs.
;; Copyright 2008 pluskid ;; Copyright 2008 pluskid
;;
;; Author: pluskid <pluskid@gmail.com> ;; Author: pluskid <pluskid@gmail.com>
;; Created: 02 Mar 2008
;; Version: 0.5.9 ;; Version: 0.5.9
;; X-URL: http://code.google.com/p/yasnippet/ ;; Keywords: snippet, textmate
;; URL: http://code.google.com/p/yasnippet/
;; EmacsWiki: YaSnippetMode
;; This file is free software; you can redistribute it and/or modify ;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by ;; it under the terms of the GNU General Public License as published by
@ -35,6 +38,8 @@
;; For more information and detailed usage, refer to the project page: ;; For more information and detailed usage, refer to the project page:
;; http://code.google.com/p/yasnippet/ ;; http://code.google.com/p/yasnippet/
;;; Code:
(eval-when-compile (require 'cl)) (eval-when-compile (require 'cl))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1035,6 +1040,17 @@ foo\"bar\\! -> \"foo\\\"bar\\\\!\""
t) t)
"\"")) "\""))
(defun yas/compile-bundle-for-elpa
(&optional yasnippet yasnippet-bundle snippet-roots code)
"Compile bundle for ELPA, add autoloads so that ELPA can
generate code to load and activate YASnippet."
(yas/compile-bundle
yasnippet yasnippet-bundle snippet-roots
(concat (or code "")
"\n(yas/initialize-bundle)"
"\n;;;###autoload" ; break through so that won't
"(require 'yasnippet-bundle)"))) ; be treated as magic comment
(defun yas/compile-bundle (defun yas/compile-bundle
(&optional yasnippet yasnippet-bundle snippet-roots code) (&optional yasnippet yasnippet-bundle snippet-roots code)
"Compile snippets in SNIPPET-ROOTS to a single bundle file. "Compile snippets in SNIPPET-ROOTS to a single bundle file.
@ -1055,19 +1071,23 @@ all the parameters:
(when (null snippet-roots) (when (null snippet-roots)
(setq snippet-roots '("snippets"))) (setq snippet-roots '("snippets")))
(when (null code) (when (null code)
(setq code "(yas/initialize)")) (setq code "(yas/initialize-bundle)"))
(let ((dirs (or (and (listp snippet-roots) snippet-roots) (let ((dirs (or (and (listp snippet-roots) snippet-roots)
(list snippet-roots))) (list snippet-roots)))
(bundle-buffer nil)) (bundle-buffer nil))
(with-temp-buffer (with-temp-buffer
(setq bundle-buffer (current-buffer)) (setq bundle-buffer (current-buffer))
(insert ";;; yasnippet-bundle.el --- "
"Yet another snippet extension (Auto compiled bundle)\n")
(insert-file-contents yasnippet) (insert-file-contents yasnippet)
(goto-char (point-max)) (goto-char (point-max))
(insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n") (insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(insert ";;;; Auto-generated code ;;;;\n") (insert ";;;; Auto-generated code ;;;;\n")
(insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n") (insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(insert code "\n") (insert "(defun yas/initialize-bundle ()\n"
" \"Initialize YASnippet and load snippets in the bundle.\""
" (yas/initialize)\n")
(flet ((yas/define-snippets (flet ((yas/define-snippets
(mode snippets &optional parent) (mode snippets &optional parent)
(with-current-buffer bundle-buffer (with-current-buffer bundle-buffer
@ -1100,11 +1120,16 @@ all the parameters:
(dolist (dir dirs) (dolist (dir dirs)
(dolist (subdir (yas/directory-files dir nil)) (dolist (subdir (yas/directory-files dir nil))
(yas/load-directory-1 subdir nil)))) (yas/load-directory-1 subdir nil))))
(insert ")\n\n" code "\n")
(insert "(provide '" (insert "(provide '"
(file-name-nondirectory (file-name-nondirectory
(file-name-sans-extension (file-name-sans-extension
yasnippet-bundle)) yasnippet-bundle))
")\n") ")\n")
(insert ";;; "
(file-name-nondirectory yasnippet-bundle)
" ends here\n")
(setq buffer-file-name yasnippet-bundle) (setq buffer-file-name yasnippet-bundle)
(save-buffer)))) (save-buffer))))
@ -1883,3 +1908,5 @@ Use multiple times to bind different COMMANDs to the same KEY."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; dropdown-list.el ends here ;;; dropdown-list.el ends here
;;; yasnippet.el ends here