* more little bugs with field deletions and adjancencies fixed...

* also the menu problem is fixed now
This commit is contained in:
capitaomorte 2009-07-21 10:06:11 +00:00
parent 5b48e2ec15
commit 17e7a385f7

View File

@ -1,9 +1,9 @@
;;; yasnippet.el --- Yet another snippet extension for Emacs. ;;; Yasnippet.el --- Yet another snippet extension for Emacs.
;; Copyright 2008 pluskid ;; Copyright 2008 pluskid
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com> ;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
;; Version: 0.6.0 ;; Version: 0.6.0 beta
;; X-URL: http://code.google.com/p/yasnippet/ ;; X-URL: http://code.google.com/p/yasnippet/
;; Keywords: snippet, textmate ;; Keywords: snippet, textmate
;; URL: http://code.google.com/p/yasnippet/ ;; URL: http://code.google.com/p/yasnippet/
@ -340,7 +340,7 @@ Here's an example:
;; Internal variables ;; Internal variables
;; ;;
(defvar yas/version "0.5.6-nested-placeholders") (defvar yas/version "0.6.0-beta")
(defvar yas/snippet-tables (make-hash-table) (defvar yas/snippet-tables (make-hash-table)
"A hash table of snippet tables corresponding to each major-mode.") "A hash table of snippet tables corresponding to each major-mode.")
@ -386,37 +386,58 @@ snippet templates")
id)) id))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; YASnippet minor mode ;; Minor mode stuff
;; ;;
(defvar yas/minor-mode-map (make-sparse-keymap) (defvar yas/minor-mode-map (make-sparse-keymap)
"The keymap used when `yas/minor-mode' is active.") "The keymap used when `yas/minor-mode' is active.")
(defvar yas/minor-mode-menu (make-sparse-keymap) (easy-menu-define yas/minor-mode-menu
"The menu bar menu used when `yas/minor-mode' is active.") yas/minor-mode-map
"Menu used when YAS/minor-mode is active."
(cons "YASnippet"
(mapcar #'(lambda (ent)
(when (third ent)
(define-key yas/minor-mode-map (third ent) (second ent)))
(vector (first ent) (second ent) t))
(list (list "--")
(list "Expand trigger" 'yas/expand (read-kbd-macro yas/trigger-key))
(list "Insert at point" 'yas/insert-snippet "\C-c&\C-s")
(list "About" 'yas/about)
(list "Reload-all-snippets" 'yas/reload-all)
(list "Load snippets..." 'yas/load-directory)))))
;; (define-minor-mode yas/minor-mode
;; This bit of code inspired from hideshow.el "Toggle YASnippet mode.
;;
(defun yas/init-keymap-and-menu ()
(setq yas/minor-mode-map (make-sparse-keymap))
(setq yas/minor-mode-menu nil)
(easy-menu-define yas/minor-mode-menu When YASnippet mode is enabled, the `tas/trigger-key' key expands
yas/minor-mode-map snippets of code depending on the mode.
"Menu used when YAS/minor-mode is active."
(cons "YASnippet" With no argument, this command toggles the mode.
(mapcar #'(lambda (ent) positive prefix argument turns on the mode.
(when (third ent) Negative prefix argument turns off the mode.
(define-key yas/minor-mode-map (third ent) (second ent)))
(vector (first ent) (second ent) t)) You can customize the key through `yas/trigger-key'.
(list (list "--")
(list "Expand trigger" 'yas/expand (read-kbd-macro yas/trigger-key)) Key bindings:
(list "Insert at point" 'yas/insert-snippet "\C-c&\C-s") \\{yas/minor-mode-map}"
(list "About" 'yas/about) nil
(list "Reload-all-snippets" 'yas/reload-all) ;; The indicator for the mode line.
(list "Load snippets..." 'yas/load-directory))))) " yas"
(define-key snippet-mode-map "\C-c\C-c" 'yas/load-snippet-buffer)) :group 'yasnippet)
(defun yas/minor-mode-on ()
"Turn on YASnippet minor mode."
(interactive)
(yas/minor-mode 1))
(defun yas/minor-mode-off ()
"Turn off YASnippet minor mode."
(interactive)
(yas/minor-mode -1))
(define-globalized-minor-mode yas/global-mode yas/minor-mode yas/minor-mode-on
:group 'yasnippet)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Major mode stuff ;; Major mode stuff
@ -439,6 +460,8 @@ snippet templates")
(0 font-lock-keyword-face))))) (0 font-lock-keyword-face)))))
(defvar snippet-mode-map (make-sparse-keymap)) (defvar snippet-mode-map (make-sparse-keymap))
(define-key snippet-mode-map "\C-c\C-c" 'yas/load-snippet-buffer)
(define-derived-mode snippet-mode text-mode "YASnippet" (define-derived-mode snippet-mode text-mode "YASnippet"
"A mode for editing yasnippets" "A mode for editing yasnippets"
@ -446,42 +469,7 @@ snippet templates")
(set (make-local-variable 'require-final-newline) nil) (set (make-local-variable 'require-final-newline) nil)
(use-local-map snippet-mode-map)) (use-local-map snippet-mode-map))
(define-minor-mode yas/minor-mode
"Toggle YASnippet mode.
When YASnippet mode is enabled, the `tas/trigger-key' key expands
snippets of code depending on the mode.
With no argument, this command toggles the mode.
positive prefix argument turns on the mode.
Negative prefix argument turns off the mode.
You can customize the key through `yas/trigger-key'.
Key bindings:
\\{yas/minor-mode-map}"
;; The initial value.
:keymap yas/minor-mode-map
;; The indicator for the mode line.
" yas"
:group 'yasnippet
(unless (and yas/minor-mode-map
(second yas/minor-mode-map))
(yas/init-keymap-and-menu))
(easy-menu-add yas/minor-mode-menu))
(defun yas/minor-mode-on ()
"Turn on YASnippet minor mode."
(interactive)
(yas/minor-mode 1))
(defun yas/minor-mode-off ()
"Turn off YASnippet minor mode."
(interactive)
(yas/minor-mode -1))
(define-globalized-minor-mode yas/global-mode yas/minor-mode yas/minor-mode-on
:group 'yasnippet)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal structs for template management ;; Internal structs for template management
@ -1466,9 +1454,12 @@ delegate to `yas/next-field'."
1)) 1))
(snippet (first (yas/snippets-at-point))) (snippet (first (yas/snippets-at-point)))
(active-field (overlay-get yas/active-field-overlay 'yas/field)) (active-field (overlay-get yas/active-field-overlay 'yas/field))
(live-fields (remove-if #'yas/field-probably-deleted-p (yas/snippet-fields snippet))) (live-fields (remove-if #'(lambda (field)
(and (not (eq field active-field))
(yas/field-probably-deleted-p field)))
(yas/snippet-fields snippet)))
(active-field-pos (position active-field live-fields)) (active-field-pos (position active-field live-fields))
(target-pos (+ arg active-field-pos)) (target-pos (and active-field-pos (+ arg active-field-pos)))
(target-field (nth target-pos live-fields))) (target-field (nth target-pos live-fields)))
;; First check if we're moving out of a field with a transform ;; First check if we're moving out of a field with a transform
;; ;;
@ -1737,7 +1728,9 @@ This is needed since markers don't \"rear-advance\" like overlays"
(let ((adjacents (yas/field-back-adjacent-fields field))) (let ((adjacents (yas/field-back-adjacent-fields field)))
(when adjacents (when adjacents
(dolist (adjacent adjacents) (dolist (adjacent adjacents)
(set-marker (yas/field-start adjacent) end))))) (when (< (yas/field-start adjacent) end)
(set-marker (yas/field-start adjacent) end))
(yas/advance-field-and-parents-maybe adjacent end)))))
(defun yas/make-move-active-field-overlay (snippet field) (defun yas/make-move-active-field-overlay (snippet field)
"Place the active field overlay in SNIPPET's FIELD. "Place the active field overlay in SNIPPET's FIELD.
@ -2299,8 +2292,9 @@ When multiple expressions are found, only the last one counts."
(princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point)))) (princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point))))
(dolist (snippet (yas/snippets-at-point)) (dolist (snippet (yas/snippets-at-point))
(princ (format "\tid: %s and active field from %s to %s covering \"%s\"\n" (princ (format "\tid: %s active field %d from %s to %s covering \"%s\"\n"
(yas/snippet-id snippet) (yas/snippet-id snippet)
(yas/field-number (yas/snippet-active-field snippet))
(marker-position (yas/field-start (yas/snippet-active-field snippet))) (marker-position (yas/field-start (yas/snippet-active-field snippet)))
(marker-position (yas/field-end (yas/snippet-active-field snippet))) (marker-position (yas/field-end (yas/snippet-active-field snippet)))
(buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet))))) (buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet)))))
@ -2343,13 +2337,13 @@ When multiple expressions are found, only the last one counts."
(erase-buffer) (erase-buffer)
(setq buffer-undo-list nil) (setq buffer-undo-list nil)
(setq undo-in-progress nil) (setq undo-in-progress nil)
(c-mode) (snippet-mode)
(yas/minor-mode 1) (yas/minor-mode 1)
(let ((abbrev)) (let ((abbrev))
;; (if (require 'ido nil t) ;; (if (require 'ido nil t)
;; (setq abbrev (ido-completing-read "Snippet abbrev: " '("crazy" "prip" "prop"))) ;; (setq abbrev (ido-completing-read "Snippet abbrev: " '("crazy" "prip" "prop")))
;; (setq abbrev "prop")) ;; (setq abbrev "prop"))
(setq abbrev "bosta") (setq abbrev "$f")
(insert abbrev)) (insert abbrev))
(unless quiet (unless quiet
(add-hook 'post-command-hook 'yas/debug-some-vars 't 'local))) (add-hook 'post-command-hook 'yas/debug-some-vars 't 'local)))