Clean up previous change

* yasnippet.el: Update comment.
(yas--protection-violation): Removed.
(yas--on-protection-overlay-modification): Simplified.
(yas--post-command-handler): No longer reference
`yas--protection-violation'
This commit is contained in:
João Távora 2014-11-17 11:27:30 +00:00
parent 596e6b2640
commit 175e0a3a10

View File

@ -3438,16 +3438,9 @@ progress."
;; snippet outside the active field. Actual protection happens in ;; snippet outside the active field. Actual protection happens in
;; `yas--on-protection-overlay-modification'. ;; `yas--on-protection-overlay-modification'.
;; ;;
;; Currently this signals an error which inhibits the command. For ;; As of github #537 this no longer inhibits the command by issuing an
;; commands that move point (like `kill-line'), point is restored in ;; error: all the snippets at point, including nested snippets, are
;; the `yas--post-command-handler' using a global ;; automatically commited and the current command can proceed.
;; `yas--protection-violation' variable.
;;
;; Alternatively, I've experimented with an implementation that
;; commits the snippet before actually calling `this-command'
;; interactively, and then signals an error, which is ignored. but
;; blocks all other million modification hooks. This presented some
;; problems with stacked expansion.
;; ;;
(defun yas--make-move-field-protection-overlays (snippet field) (defun yas--make-move-field-protection-overlays (snippet field)
"Place protection overlays surrounding SNIPPET's FIELD. "Place protection overlays surrounding SNIPPET's FIELD.
@ -3481,29 +3474,17 @@ Move the overlays, or create them if they do not exit."
;; (overlay-put ov 'evaporate t) ;; (overlay-put ov 'evaporate t)
(overlay-put ov 'modification-hooks '(yas--on-protection-overlay-modification))))))) (overlay-put ov 'modification-hooks '(yas--on-protection-overlay-modification)))))))
(defvar yas--protection-violation nil
"When non-nil, signals attempts to erroneously exit or modify the snippet.
Functions in the `post-command-hook', for example
`yas--post-command-handler' can check it and reset its value to
nil. The variables value is the point where the violation
originated")
(defun yas--on-protection-overlay-modification (_overlay after? _beg _end &optional _length) (defun yas--on-protection-overlay-modification (_overlay after? _beg _end &optional _length)
"Signals a snippet violation, then issues error. "Signals a snippet violation, then issues error.
The error should be ignored in `debug-ignored-errors'" The error should be ignored in `debug-ignored-errors'"
(unless yas--inhibit-overlay-hooks (unless (or yas--inhibit-overlay-hooks
(cond ((not (or after? after?
(yas--undo-in-progress))) (yas--undo-in-progress))
(cond (t
(let ((snippets (yas--snippets-at-point))) (let ((snippets (yas--snippets-at-point)))
(yas--message 3 "Comitting snippets. Action would destroy a protection overlay.") (yas--message 3 "Comitting snippets. Action would destroy a protection overlay.")
(cl-loop for snippet in snippets (cl-loop for snippet in snippets
do (yas--commit-snippet snippet)))) do (yas--commit-snippet snippet)))))
(nil
(setq yas--protection-violation (point))
(error "Exit the snippet first!")))))))
(add-to-list 'debug-ignored-errors "^Exit the snippet first!$") (add-to-list 'debug-ignored-errors "^Exit the snippet first!$")
@ -4302,10 +4283,7 @@ When multiple expressions are found, only the last one counts."
;; ;;
(defun yas--post-command-handler () (defun yas--post-command-handler ()
"Handles various yasnippet conditions after each command." "Handles various yasnippet conditions after each command."
(cond (yas--protection-violation (cond ((eq 'undo this-command)
(goto-char yas--protection-violation)
(setq yas--protection-violation nil))
((eq 'undo this-command)
;; ;;
;; After undo revival the correct field is sometimes not ;; After undo revival the correct field is sometimes not
;; restored correctly, this condition handles that ;; restored correctly, this condition handles that