yasnippet-bundle.el gone.

fast snippet loading now via .yas-compiled-snippet.el files, uses yas/compile-snippets
This commit is contained in:
João Távora 2012-02-26 20:42:56 +00:00
parent f651c41da0
commit 483364c8e5
2 changed files with 73 additions and 159 deletions

View File

@ -9,17 +9,6 @@ end
find_version find_version
FileUtils.mkdir_p('pkg') FileUtils.mkdir_p('pkg')
desc "generate bundle file for classic snippets."
task :bundle do
sh 'emacs --batch -l yasnippet.el --eval "(yas/compile-bundle)"'
sh "tar czf pkg/yasnippet-bundle-#{$version}.el.tgz yasnippet-bundle.el"
end
desc "generate bundle file for textmate snippets."
task :textmate_bundle => [:convert] do
sh 'emacs --batch -l yasnippet.el --eval "(yas/compile-textmate-bundle)"'
sh "tar czf pkg/yasnippet-textmate-bundle-#{$version}.el.tgz yasnippet-textmate-bundle.el"
end
desc "convert some textmate bundles to yasnippets" desc "convert some textmate bundles to yasnippets"
task :convert_bundles do task :convert_bundles do

View File

@ -32,7 +32,7 @@
;; ;;
;; (add-to-list 'load-path ;; (add-to-list 'load-path
;; "~/.emacs.d/plugins/yasnippet") ;; "~/.emacs.d/plugins/yasnippet")
;; (require 'yasnippet) ;; not yasnippet-bundle ;; (require 'yasnippet)
;; (yas/global-mode 1) ;; (yas/global-mode 1)
;; ;;
;; ;;
@ -1601,19 +1601,15 @@ TEMPLATES is a list of `yas/template'."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Loading snippets from files ;; Loading snippets from files
;; ;;
(defun yas/load-directory-1 (directory &optional mode-sym parents) (defun yas/load-directory-1 (directory &optional mode-sym parents no-compiled-snippets)
"Recursively load snippet templates from DIRECTORY." "Recursively load snippet templates from DIRECTORY."
(unless (file-exists-p (concat directory "/" ".yas-skip"))
;; Load .yas-setup.el files wherever we find them ;; Load .yas-setup.el files wherever we find them
;; ;;
(let ((file (concat directory "/" ".yas-setup"))) (load ".yas-setup" 'noerror)
(when (or (file-readable-p (concat file ".el")) (if (and (not no-compiled-snippets)
(file-readable-p (concat file ".elc"))) (load ".yas-compiled-snippets" 'noerror))
(load file))) (message "Loading much faster .yas-compiled-snippets from %s" directory)
;;
;;
(unless (file-exists-p (concat directory "/" ".yas-skip"))
(let* ((major-mode-and-parents (if mode-sym (let* ((major-mode-and-parents (if mode-sym
(cons mode-sym parents) (cons mode-sym parents)
(yas/compute-major-mode-and-parents (concat directory (yas/compute-major-mode-and-parents (concat directory
@ -1638,24 +1634,22 @@ TEMPLATES is a list of `yas/template'."
(dolist (subdir (yas/subdirs directory)) (dolist (subdir (yas/subdirs directory))
(yas/load-directory-1 subdir (yas/load-directory-1 subdir
(car major-mode-and-parents) (car major-mode-and-parents)
(cdr major-mode-and-parents)))))) (cdr major-mode-and-parents)
t))))))
(defun yas/load-directory (directory) (defun yas/load-directory (top-level-dir)
"Load snippet definition from a directory hierarchy. "Load snippet definition from directory hierarchy under TOP-LEVEL-DIR.
Below the top-level directory, each directory is a mode Below TOP-LEVEL-DIR., each directory is a mode name."
name. And under each subdirectory, each file is a definition
of a snippet. The file name is the trigger key and the
content of the file is the template."
(interactive "DSelect the root directory: ") (interactive "DSelect the root directory: ")
(unless (file-directory-p directory) (unless (file-directory-p top-level-dir)
(error "%s is not a directory" directory)) (error "%s is not a directory" top-level-dir))
(unless yas/snippet-dirs (unless yas/snippet-dirs
(setq yas/snippet-dirs directory)) (setq yas/snippet-dirs top-level-dir))
(dolist (dir (yas/subdirs directory)) (dolist (dir (yas/subdirs top-level-dir))
(yas/load-directory-1 dir)) (yas/load-directory-1 dir))
(when (interactive-p) (when (interactive-p)
(message "[yas] Loaded snippets from %s." directory))) (message "[yas] Loaded snippets from %s." top-level-dir)))
(defun yas/load-snippet-dirs () (defun yas/load-snippet-dirs ()
"Reload the directories listed in `yas/snippet-dirs' or "Reload the directories listed in `yas/snippet-dirs' or
@ -1702,76 +1696,36 @@ foo\"bar\\! -> \"foo\\\"bar\\\\!\""
t) t)
"\"")) "\""))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Yasnippet Bundle ;;; Snippet compilation function
(defun yas/initialize () (defun yas/initialize ()
"For backward compatibility, enable `yas/minor-mode' globally" "For backward compatibility, enable `yas/minor-mode' globally"
(yas/global-mode 1)) (yas/global-mode 1))
(defun yas/compile-bundle (defun yas/compile-top-level-dir (top-level-dir)
(&optional yasnippet yasnippet-bundle snippet-roots code dropdown) "Create .yas-compiled-snippets.el files under subdirs of TOP-LEVEL-DIR."
"Compile snippets in SNIPPET-ROOTS to a single bundle file. (interactive "DTop level snippet directory?")
(dolist (dir (yas/subdirs top-level-dir))
(yas/compile-snippets dir)))
YASNIPPET is the yasnippet.el file path. (defun yas/compile-snippets (input-dir &optional output-file)
"Compile snippets files in INPUT-DIR to OUTPUT-FILE file.
YASNIPPET-BUNDLE is the output file of the compile result. Prompts for INPUT-DIR and OUTPUT-FILE if called-interactively"
(interactive (let* ((input-dir (read-directory-name "Snippet dir "))
SNIPPET-ROOTS is a list of root directories that contains the (output-file (let ((ido-everywhere nil))
snippets definition. (read-file-name "Output file "
input-dir nil nil
CODE is the code to be placed at the end of the generated file ".yas-compiled-snippets.el"
and that can initialize the YASnippet bundle. nil))))
(list input-dir output-file)))
Last optional argument DROPDOWN is the filename of the (let ((default-directory input-dir))
dropdown-list.el library. (with-temp-file (setq output-file (or output-file ".yas-compiled-snippets.el"))
Here's the default value for all the parameters:
(yas/compile-bundle \"yasnippet.el\"
\"yasnippet-bundle.el\"
\"snippets\")
\"(yas/initialize-bundle)
### autoload
(require 'yasnippet-bundle)`\"
\"dropdown-list.el\")
"
(interactive (concat "ffind the yasnippet.el file: \nFTarget bundle file: "
"\nDSnippet directory to bundle: \nMExtra code? \nfdropdown-library: "))
(let* ((yasnippet (or yasnippet
"yasnippet.el"))
(yasnippet-bundle (or yasnippet-bundle
"./yasnippet-bundle.el"))
(snippet-roots (or snippet-roots
"snippets"))
(dropdown (or dropdown
"dropdown-list.el"))
(code (or (and code
(condition-case err (read code) (error nil))
code)
(concat "(yas/initialize-bundle)"
"\n;;;###autoload" ; break through so that won't
"(require 'yasnippet-bundle)")))
(dirs (or (and (listp snippet-roots) snippet-roots)
(list snippet-roots)))
(bundle-buffer nil))
(with-temp-file yasnippet-bundle
(insert ";;; yasnippet-bundle.el --- "
"Yet another snippet extension (Auto compiled bundle)\n")
(insert-file-contents yasnippet)
(goto-char (point-max))
(insert "\n")
(when dropdown
(insert-file-contents dropdown))
(goto-char (point-max))
(insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(insert ";;;; Auto-generated code ;;;;\n")
(insert ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(insert "(defun yas/initialize-bundle ()\n"
" \"Initialize YASnippet and load snippets in the bundle.\"")
(flet ((yas/define-snippets (flet ((yas/define-snippets
(mode snippets &optional parent-or-parents) (mode snippets &optional parent-or-parents)
(insert ";;; snippets for " (symbol-name mode) ", subdir " (file-name-nondirectory (replace-regexp-in-string "/$" "" default-directory)) "\n") (insert (format ";;; %s - automatically compiled snippets for `%s' , do not edit!\n"
(file-name-nondirectory output-file) mode))
(insert ";;;\n")
(let ((literal-snippets (list))) (let ((literal-snippets (list)))
(dolist (snippet snippets) (dolist (snippet snippets)
(let ((key (first snippet)) (let ((key (first snippet))
@ -1794,47 +1748,18 @@ Here's the default value for all the parameters:
,uuid) ,uuid)
literal-snippets))) literal-snippets)))
(insert (pp-to-string `(yas/define-snippets ',mode ',literal-snippets ',parent-or-parents))) (insert (pp-to-string `(yas/define-snippets ',mode ',literal-snippets ',parent-or-parents)))
(insert "\n\n")))) (insert "\n\n")
(dolist (dir dirs) (insert (format ";;; %s - automatically compiled snippets for `%s' end here\n"
(dolist (subdir (yas/subdirs dir)) (file-name-nondirectory output-file) mode))
(let ((file (concat subdir "/.yas-setup.el"))) (insert ";;;"))))
(when (file-readable-p file) (yas/load-directory-1 input-dir nil nil 'no-compiled-snippets))))
(insert "\n;; Supporting elisp for subdir " (file-name-nondirectory subdir) "\n\n")
(with-temp-buffer
(insert-file-contents file)
(replace-regexp "^;;.*$" "" nil (point-min) (point-max))
(replace-regexp "^[\s\t]*\n\\([\s\t]*\n\\)+" "\n" nil (point-min) (point-max))
(kill-region (point-min) (point-max)))
(yank)))
(yas/load-directory-1 subdir nil))))
(insert (pp-to-string `(yas/global-mode 1))) (if (and (called-interactively-p)
(insert ")\n\n" code "\n") (yes-or-no-p (format "Open the resulting file (%s)? "
(expand-file-name output-file))))
(find-file-other-window output-file)))
;; bundle-specific provide and value for yas/dont-activate
(let ((bundle-feature-name (file-name-nondirectory
(file-name-sans-extension
yasnippet-bundle))))
(insert (pp-to-string `(set-default 'yas/dont-activate
#'(lambda ()
(and (or yas/snippet-dirs
(featurep ',(make-symbol bundle-feature-name)))
(null (yas/get-snippet-tables)))))))
(insert (pp-to-string `(provide ',(make-symbol bundle-feature-name)))))
(insert ";;; "
(file-name-nondirectory yasnippet-bundle)
" ends here\n"))))
(defun yas/compile-textmate-bundle ()
(interactive)
(yas/compile-bundle "yasnippet.el"
"./yasnippet-textmate-bundle.el"
"extras/imported/"
(concat "(yas/initialize-bundle)"
"\n;;;###autoload" ; break through so that won't
"(require 'yasnippet-textmate-bundle)")
"dropdown-list.el"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Some user level functions ;;; Some user level functions