* I like. Very nice. New undo scheme is powerful for completely

emulating Textmate behaviour I think.
This commit is contained in:
capitaomorte 2008-09-12 13:35:57 +00:00
parent 38ce2aac82
commit d9cb83dc93

View File

@ -298,7 +298,7 @@ set to t."
(id (yas/snippet-next-id) :read-only t) (id (yas/snippet-next-id) :read-only t)
(control-overlay nil) (control-overlay nil)
(active-field-overlay nil) (active-field-overlay nil)
field-undo-saved-boundaries undo-saved-boundaries
(active-group nil) (active-group nil)
(end-marker nil)) (end-marker nil))
@ -1382,9 +1382,9 @@ up the snippet does not delete it!"
`post-command-hook' that should exist while at least one `post-command-hook' that should exist while at least one
registered snippet exists in the current buffer. Return snippet" registered snippet exists in the current buffer. Return snippet"
(puthash (yas/snippet-id snippet) snippet yas/registered-snippets) (puthash (yas/snippet-id snippet) snippet yas/registered-snippets)
(add-hook 'pre-command-hook 'yas/field-undo-before-hook 'append 'local) (add-hook 'pre-command-hook 'yas/undo-before-hook 'append 'local)
(add-hook 'post-command-hook 'yas/check-cleanup-snippet 'append 'local) (add-hook 'post-command-hook 'yas/check-cleanup-snippet 'append 'local)
(add-hook 'post-command-hook 'yas/field-undo-after-hook 'append 'local) (add-hook 'post-command-hook 'yas/undo-after-hook 'append 'local)
;; DEBUG ;; DEBUG
(add-hook 'post-command-hook 'yas/debug-some-vars 'append 'local) (add-hook 'post-command-hook 'yas/debug-some-vars 'append 'local)
snippet) snippet)
@ -1397,8 +1397,8 @@ current buffer."
(remhash (yas/snippet-id snippet) yas/registered-snippets) (remhash (yas/snippet-id snippet) yas/registered-snippets)
(when (eq 0 (when (eq 0
(hash-table-count yas/registered-snippets)) (hash-table-count yas/registered-snippets))
(remove-hook 'pre-command-hook 'yas/field-undo-before-hook 'local) (remove-hook 'pre-command-hook 'yas/undo-before-hook 'local)
(remove-hook 'post-command-hook 'yas/field-undo-after-hook 'local) (remove-hook 'post-command-hook 'yas/undo-after-hook 'local)
(remove-hook 'post-command-hook 'yas/check-cleanup-snippet 'local) (remove-hook 'post-command-hook 'yas/check-cleanup-snippet 'local)
;; DEBUG ;; DEBUG
(remove-hook 'post-command-hook 'yas/debug-some-vars ' 'local) (remove-hook 'post-command-hook 'yas/debug-some-vars ' 'local)
@ -1497,34 +1497,41 @@ registered snippets last."
;; ;;
;; ... ;; ...
(defun yas/field-undo-before-hook () (defun yas/undo-before-hook ()
"..." "..."
(let* ((snippet (yas/snippet-of-current-keymap)) (let* ((snippet (yas/snippet-of-current-keymap))
(field-overlay (and snippet (field-overlay (and snippet
(yas/snippet-active-field-overlay snippet)))) (yas/snippet-active-field-overlay snippet))))
(when (and field-overlay (when (and field-overlay
(overlay-buffer field-overlay)) (overlay-buffer field-overlay))
(setf (yas/snippet-field-undo-saved-boundaries snippet) (setf (yas/snippet-undo-saved-boundaries snippet)
(cons (overlay-start field-overlay) (cons (overlay-start field-overlay)
(overlay-end field-overlay)))))) (overlay-end field-overlay))))))
(defun yas/field-undo-after-hook () (defun yas/undo-after-hook ()
"..." "..."
(let* ((snippet (yas/snippet-of-current-keymap)) (let* ((snippet (yas/snippet-of-current-keymap))
(saved-boundaries (and snippet (saved-boundaries (and snippet
(yas/snippet-field-undo-saved-boundaries snippet)))) (yas/snippet-undo-saved-boundaries snippet))))
(unless (null saved-boundaries)
(yas/push-undo-action-maybe (list 'yas/field-undo-restore-boundaries
(car saved-boundaries)
(cdr saved-boundaries))))
(unless (null snippet) (unless (null snippet)
(yas/push-undo-action-maybe (list 'yas/restore-active-group nil))))) (yas/push-undo-action-maybe (list 'yas/undo-restore-active-group nil)))
(unless (null saved-boundaries)
(yas/push-undo-action-maybe (list 'yas/undo-restore-boundaries
(car saved-boundaries)
(cdr saved-boundaries))))))
(defun yas/restore-active-group (snippet) (defun yas/undo-restore-active-group (&optional point)
"..." "..."
(message "Would be restoring the active group, but how????")) (let* ((point (or point
(point)))
(snippet (yas/snippet-of-current-keymap point)))
(message "Would restoring group point %s and %s"
point
(if snippet
(format "snippet id %d" (yas/snippet-id snippet))
"NO SNIPPET!!!"))))
(defun yas/push-undo-action-maybe (apply-args) (defun yas/push-undo-action-maybe (apply-args)
@ -1563,7 +1570,7 @@ registered snippets last."
target-separator)))))) target-separator))))))
(defun yas/field-undo-restore-boundaries (start end) (defun yas/undo-restore-boundaries (start end)
"..." "..."
(let* ((snippet (yas/snippet-of-current-keymap)) (let* ((snippet (yas/snippet-of-current-keymap))
(field-overlay (and snippet (field-overlay (and snippet