Use filename for snippet name if no "name" property is defined.

This commit is contained in:
Zhang Chiyuan 2008-07-31 07:05:53 +00:00
parent 6ea153b0df
commit e9cd192bda

View File

@ -804,7 +804,7 @@ will be deleted before inserting template."
(yas/group-primary-field target)))) (yas/group-primary-field target))))
(yas/exit-snippet (yas/group-snippet group))))) (yas/exit-snippet (yas/group-snippet group)))))
(defun yas/parse-template () (defun yas/parse-template (&optional file-name)
"Parse the template in the current buffer. "Parse the template in the current buffer.
If the buffer contains a line of \"# --\" then the contents If the buffer contains a line of \"# --\" then the contents
above this line are ignored. Variables can be set above this above this line are ignored. Variables can be set above this
@ -822,7 +822,7 @@ Here's a list of currently recognized variables:
# -- # --
#include \"$1\"" #include \"$1\""
(goto-char (point-min)) (goto-char (point-min))
(let (template name bound condition) (let ((name file-name) template bound condition)
(if (re-search-forward "^# --\n" nil t) (if (re-search-forward "^# --\n" nil t)
(progn (setq template (progn (setq template
(buffer-substring-no-properties (point) (buffer-substring-no-properties (point)
@ -925,9 +925,10 @@ hierarchy."
(dolist (file (yas/directory-files directory t)) (dolist (file (yas/directory-files directory t))
(when (file-readable-p file) (when (file-readable-p file)
(insert-file-contents file nil nil nil t) (insert-file-contents file nil nil nil t)
(push (cons (file-name-nondirectory file) (let ((snippet-file-name (file-name-nondirectory file)))
(yas/parse-template)) (push (cons snippet-file-name
snippets)))) (yas/parse-template snippet-file-name))
snippets)))))
(yas/define-snippets mode-sym (yas/define-snippets mode-sym
snippets snippets
parent) parent)