Decide field clearing commands based on delsel

* yasnippet.el (yas--skip-and-clear-field-p): Check `delete-selection'
  of `this-command'.

Fix #644, close #645.
This commit is contained in:
Noam Postavsky 2016-01-10 18:44:36 -05:00
parent 4a6d923c9d
commit acf2cdd03e
2 changed files with 16 additions and 11 deletions

View File

@ -160,20 +160,17 @@
(ert-simulate-command '(yas-prev-field)) (ert-simulate-command '(yas-prev-field))
(should (looking-at "brother")))) (should (looking-at "brother"))))
(ert-deftest dont-clear-on-yank-issue-515 () (ert-deftest do-clear-on-yank-issue-515 ()
"A yank shouldn't clear and unmodified field." ; or should it? -- jt "A yank should clear an unmodified field."
(with-temp-buffer (with-temp-buffer
(yas-minor-mode 1) (yas-minor-mode 1)
(yas-expand-snippet "my ${1:kid brother} from another ${2:mother}") (yas-expand-snippet "my ${1:kid brother} from another ${2:mother}")
(yas-mock-yank "little sibling")
(yas-mock-yank "little")
(yas-mock-insert " ")
(should (string= (yas--buffer-contents) (should (string= (yas--buffer-contents)
"my little kid brother from another mother")) "my little sibling from another mother"))
(ert-simulate-command '(yas-next-field)) (ert-simulate-command '(yas-next-field))
(ert-simulate-command '(yas-prev-field)) (ert-simulate-command '(yas-prev-field))
(should (looking-at "little kid brother")))) (should (looking-at "little sibling"))))
;;; Snippet expansion and character escaping ;;; Snippet expansion and character escaping

View File

@ -3388,9 +3388,17 @@ Move the overlay, or create it if it does not exit."
(defun yas--skip-and-clear-field-p (field _beg _end &optional _length) (defun yas--skip-and-clear-field-p (field _beg _end &optional _length)
"Tell if newly modified FIELD should be cleared and skipped. "Tell if newly modified FIELD should be cleared and skipped.
BEG, END and LENGTH like overlay modification hooks." BEG, END and LENGTH like overlay modification hooks."
(and (eq this-command 'self-insert-command) (and (not (yas--field-modified-p field))
(not (yas--field-modified-p field)) (= (point) (yas--field-start field))
(= (point) (yas--field-start field)))) (require 'delsel)
;; `yank' sets `this-command' to t during execution.
(let ((clearp (get (if (commandp this-command) this-command
this-original-command)
'delete-selection)))
(when (and (not (memq clearp '(yank supersede kill)))
(functionp clearp))
(setq clearp (funcall clearp)))
clearp)))
(defun yas--on-field-overlay-modification (overlay after? beg end &optional length) (defun yas--on-field-overlay-modification (overlay after? beg end &optional length)
"Clears the field and updates mirrors, conditionally. "Clears the field and updates mirrors, conditionally.