Merge pull request #223 from lewang/master

define comment-start snippet and some code cleanup
This commit is contained in:
João Távora 2012-03-05 04:17:28 -08:00
commit b392dd3726

View File

@ -29,7 +29,7 @@
;;; Commentary: ;;; Commentary:
;; Basic steps to setup: ;; Basic steps to setup:
;; ;;
;; (add-to-list 'load-path ;; (add-to-list 'load-path
;; "~/.emacs.d/plugins/yasnippet") ;; "~/.emacs.d/plugins/yasnippet")
;; (require 'yasnippet) ;; (require 'yasnippet)
@ -878,10 +878,10 @@ Do this unless `yas/dont-activate' is truish "
(define-derived-mode snippet-mode text-mode "Snippet" (define-derived-mode snippet-mode text-mode "Snippet"
"A mode for editing yasnippets" "A mode for editing yasnippets"
(set-syntax-table (standard-syntax-table))
(setq font-lock-defaults '(yas/font-lock-keywords)) (setq font-lock-defaults '(yas/font-lock-keywords))
(set (make-local-variable 'require-final-newline) nil) (set (make-local-variable 'require-final-newline) nil)
(use-local-map snippet-mode-map)) (set (make-local-variable 'comment-start) "#")
(set (make-local-variable 'comment-start-skip) "#+[\t ]*"))
@ -899,7 +899,7 @@ Do this unless `yas/dont-activate' is truish "
keybinding keybinding
uuid uuid
menu-binding-pair menu-binding-pair
group ;; as dictated by the #group: directive or .yas-make-groups group ;; as dictated by the #group: directive or .yas-make-groups
perm-group ;; as dictated by `yas/define-menu' perm-group ;; as dictated by `yas/define-menu'
) )
@ -1051,7 +1051,7 @@ Also takes care of adding and updaring to the associated menu."
(yas/delete-from-keymap keymap (yas/template-uuid template)) (yas/delete-from-keymap keymap (yas/template-uuid template))
;; Add necessary subgroups as necessary. ;; Add necessary subgroups as necessary.
;; ;;
(dolist (subgroup group) (dolist (subgroup group)
(let ((subgroup-keymap (lookup-key keymap (vector (make-symbol subgroup))))) (let ((subgroup-keymap (lookup-key keymap (vector (make-symbol subgroup)))))
(unless (and subgroup-keymap (unless (and subgroup-keymap
@ -1060,9 +1060,9 @@ Also takes care of adding and updaring to the associated menu."
(define-key keymap (vector (make-symbol subgroup)) (define-key keymap (vector (make-symbol subgroup))
`(menu-item ,subgroup ,subgroup-keymap))) `(menu-item ,subgroup ,subgroup-keymap)))
(setq keymap subgroup-keymap))) (setq keymap subgroup-keymap)))
;; Add this entry to the keymap ;; Add this entry to the keymap
;; ;;
(let ((menu-binding-pair (yas/snippet-menu-binding-pair-get-create template))) (let ((menu-binding-pair (yas/snippet-menu-binding-pair-get-create template)))
(define-key keymap (vector (make-symbol (yas/template-uuid template))) (car menu-binding-pair)))))) (define-key keymap (vector (make-symbol (yas/template-uuid template))) (car menu-binding-pair))))))
@ -1304,7 +1304,7 @@ Guessing is done by looking up the MODE-SYMBOL's
(and (not dont-search-parents) (and (not dont-search-parents)
(get major-mode (get major-mode
'derived-mode-parent))))))))) 'derived-mode-parent)))))))))
(remove-duplicates (remove-duplicates
(append mode-tables (append mode-tables
(mapcan #'yas/table-get-all-parents mode-tables))))) (mapcan #'yas/table-get-all-parents mode-tables)))))
@ -1895,7 +1895,7 @@ not need to be a real mode."
"Recursively delete items with UUID from KEYMAP and its submenus." "Recursively delete items with UUID from KEYMAP and its submenus."
;; XXX: This used to skip any submenus named \"parent mode\" ;; XXX: This used to skip any submenus named \"parent mode\"
;; ;;
;; First of all, recursively enter submenus, i.e. the tree is ;; First of all, recursively enter submenus, i.e. the tree is
;; searched depth first so that stale submenus can be found in the ;; searched depth first so that stale submenus can be found in the
;; higher passes. ;; higher passes.
@ -1906,10 +1906,10 @@ not need to be a real mode."
(yas/delete-from-keymap (third (cdr item)) uuid))) (yas/delete-from-keymap (third (cdr item)) uuid)))
(rest keymap)) (rest keymap))
;; Set the uuid entry to nil ;; Set the uuid entry to nil
;; ;;
(define-key keymap (vector (make-symbol uuid)) nil) (define-key keymap (vector (make-symbol uuid)) nil)
;; Destructively modify keymap ;; Destructively modify keymap
;; ;;
(setcdr keymap (delete-if #'(lambda (item) (setcdr keymap (delete-if #'(lambda (item)
(or (null (cdr item)) (or (null (cdr item))
(and (keymapp (third (cdr item))) (and (keymapp (third (cdr item)))
@ -2394,7 +2394,7 @@ With optional prefix argument KILL quit the window and buffer."
;; neatly positioned,... ;; neatly positioned,...
;; ;;
(yas/editing-template (yas/editing-template
(yas/define-snippets-1 (yas/parse-template (yas/template-file yas/editing-template)) (yas/define-snippets-1 (yas/parse-template (yas/template-file yas/editing-template))
(yas/template-table yas/editing-template))) (yas/template-table yas/editing-template)))
;; Try to use `yas/guessed-modes'. If we don't have that use the ;; Try to use `yas/guessed-modes'. If we don't have that use the
;; value from `yas/compute-major-mode-and-parents' ;; value from `yas/compute-major-mode-and-parents'
@ -2418,7 +2418,7 @@ With optional prefix argument KILL quit the window and buffer."
nil nil
(if (first yas/guessed-modes) (if (first yas/guessed-modes)
(symbol-name (first yas/guessed-modes)))))))) (symbol-name (first yas/guessed-modes))))))))
(set (make-local-variable 'yas/editing-template) (set (make-local-variable 'yas/editing-template)
(yas/define-snippets-1 (yas/parse-template buffer-file-name) (yas/define-snippets-1 (yas/parse-template buffer-file-name)
table))))) table)))))
;; Now, offer to save this shit iff: ;; Now, offer to save this shit iff:
@ -2435,7 +2435,7 @@ With optional prefix argument KILL quit the window and buffer."
(second yas/snippet-dirs) (second yas/snippet-dirs)
(not (string-match (expand-file-name (first yas/snippet-dirs)) (not (string-match (expand-file-name (first yas/snippet-dirs))
(yas/template-file yas/editing-template))))) (yas/template-file yas/editing-template)))))
(when (y-or-n-p "[yas] Looks like a library or new snippet. Save to new file? ") (when (y-or-n-p "[yas] Looks like a library or new snippet. Save to new file? ")
(let* ((option (first (yas/guess-snippet-directories (yas/template-table yas/editing-template)))) (let* ((option (first (yas/guess-snippet-directories (yas/template-table yas/editing-template))))
(chosen (and option (chosen (and option
@ -2564,7 +2564,7 @@ With optional prefix argument KILL quit the window and buffer."
(setq group (or (yas/template-fine-group v) (setq group (or (yas/template-fine-group v)
"(top level)")) "(top level)"))
(when (yas/template-name v) (when (yas/template-name v)
(aput 'groups-alist group (cons v (aget groups-alist group))))) (aput 'groups-alist group (cons v (aget groups-alist group)))))
(yas/table-uuidhash table)) (yas/table-uuidhash table))
(dolist (group-and-templates groups-alist) (dolist (group-and-templates groups-alist)
@ -2575,7 +2575,7 @@ With optional prefix argument KILL quit the window and buffer."
(let ((name (truncate-string-to-width (propertize (format "\\\\snippet `%s'" (yas/template-name p)) (let ((name (truncate-string-to-width (propertize (format "\\\\snippet `%s'" (yas/template-name p))
'yasnippet p) 'yasnippet p)
50 0 ? "...")) 50 0 ? "..."))
(group (prog1 group (group (prog1 group
(setq group (make-string (length group) ? )))) (setq group (make-string (length group) ? ))))
(condition-string (let ((condition (yas/template-condition p))) (condition-string (let ((condition (yas/template-condition p)))
(if (and condition (if (and condition
@ -2587,7 +2587,7 @@ With optional prefix argument KILL quit the window and buffer."
"(a)")))) "(a)"))))
(insert group " ") (insert group " ")
(insert condition-string " ") (insert condition-string " ")
(insert name (insert name
(if (string-match "\\.\\.\\.$" name) (if (string-match "\\.\\.\\.$" name)
"'" "'"
" ") " ")
@ -2893,7 +2893,7 @@ Also create some protection overlays"
(yas/place-overlays snippet field) (yas/place-overlays snippet field)
(overlay-put yas/active-field-overlay 'yas/field field) (overlay-put yas/active-field-overlay 'yas/field field)
(let ((number (yas/field-number field))) (let ((number (yas/field-number field)))
;; check for the special ${0: ...} field ;; check for the special ${0: ...} field
(if (and number (zerop number)) (if (and number (zerop number))
(progn (progn
(set-mark (yas/field-end field)) (set-mark (yas/field-end field))
@ -3008,7 +3008,7 @@ snippet, if so cleans up the whole snippet up."
(snippet-exit-transform)) (snippet-exit-transform))
(dolist (snippet snippets) (dolist (snippet snippets)
(let ((active-field (yas/snippet-active-field snippet))) (let ((active-field (yas/snippet-active-field snippet)))
(setq snippet-exit-transform (yas/snippet-force-exit snippet)) (setq snippet-exit-transform (yas/snippet-force-exit snippet))
(cond ((or snippet-exit-transform (cond ((or snippet-exit-transform
(not (and active-field (yas/field-contains-point-p active-field)))) (not (and active-field (yas/field-contains-point-p active-field))))
(setq snippets-left (delete snippet snippets-left)) (setq snippets-left (delete snippet snippets-left))
@ -4133,10 +4133,10 @@ Remaining args as in `yas/expand-snippet'."
;;; Some hacks: ;;; Some hacks:
;;; ;;;
;; `locate-dominating-file' ;; `locate-dominating-file'
;; `region-active-p' ;; `region-active-p'
;; ;;
;; added for compatibility in emacs < 23 ;; added for compatibility in emacs < 23
(unless (>= emacs-major-version 23) (unless (>= emacs-major-version 23)
(unless (fboundp 'region-active-p) (unless (fboundp 'region-active-p)