yasnippet.el: Minor simplifications

(yas--check-commit-snippet): De Morgan.
(yas-expand-snippet): Use `yas-current-field`.
This commit is contained in:
Stefan Monnier 2024-01-17 13:07:51 -05:00
parent c6488ac6fb
commit 23c7a6fa51
2 changed files with 9 additions and 10 deletions

View File

@ -711,7 +711,7 @@ mapconcat #'(lambda (arg)
;;; Snippet expansion and character escaping ;;; Snippet expansion and character escaping
;;; Thanks to @zw963 (Billy) for the testing ;; Thanks to @zw963 (Billy) for the testing
;;; ;;;
(ert-deftest escape-dollar () (ert-deftest escape-dollar ()
(with-temp-buffer (with-temp-buffer
@ -1227,6 +1227,9 @@ hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \
(defmacro yas-with-overriden-buffer-list (&rest body) (defmacro yas-with-overriden-buffer-list (&rest body)
(declare (debug t)) (declare (debug t))
;; FIXME: This macro was added by commit 185c771dedea as part of the
;; fix for https://github.com/joaotavora/yasnippet/issues/253,
;; but I don't know why it was/is needed.
(let ((saved-sym (make-symbol "yas--buffer-list"))) (let ((saved-sym (make-symbol "yas--buffer-list")))
`(let ((,saved-sym (symbol-function 'buffer-list))) `(let ((,saved-sym (symbol-function 'buffer-list)))
(cl-letf (((symbol-function 'buffer-list) (cl-letf (((symbol-function 'buffer-list)

View File

@ -3606,8 +3606,8 @@ If so cleans up the whole snippet up."
(yas--commit-snippet snippet) (yas--commit-snippet snippet)
(setq exited-snippets-p t)) (setq exited-snippets-p t))
((and active-field ((and active-field
(or (not yas--active-field-overlay) (not (and yas--active-field-overlay
(not (overlay-buffer yas--active-field-overlay)))) (overlay-buffer yas--active-field-overlay))))
;; ;;
;; stacked expansion: this case is mainly for recent ;; stacked expansion: this case is mainly for recent
;; snippet exits that place us back int the field of ;; snippet exits that place us back int the field of
@ -3721,7 +3721,7 @@ Otherwise deletes a character normally by calling `delete-char'."
(t (call-interactively 'delete-char)))) (t (call-interactively 'delete-char))))
(defun yas--skip-and-clear (field &optional from) (defun yas--skip-and-clear (field &optional from)
"Deletes the region of FIELD and sets it's modified state to t. "Delete the region of FIELD and set its modified state to t.
If given, FROM indicates position to start at instead of FIELD's beginning." If given, FROM indicates position to start at instead of FIELD's beginning."
;; Just before skipping-and-clearing the field, mark its children ;; Just before skipping-and-clearing the field, mark its children
;; fields as modified, too. If the children have mirrors-in-fields ;; fields as modified, too. If the children have mirrors-in-fields
@ -3994,9 +3994,7 @@ for normal snippets, and a list for command snippets)."
(run-hooks 'yas-before-expand-snippet-hook) (run-hooks 'yas-before-expand-snippet-hook)
(let* ((clear-field (let* ((clear-field
(let ((field (and yas--active-field-overlay (let ((field (yas-current-field)))
(overlay-buffer yas--active-field-overlay)
(overlay-get yas--active-field-overlay 'yas--field))))
(and field (yas--skip-and-clear-field-p (and field (yas--skip-and-clear-field-p
field (point) (point) 0) field (point) (point) 0)
field))) field)))
@ -4043,9 +4041,7 @@ for normal snippets, and a list for command snippets)."
;; Stacked-expansion: This checks for stacked expansion, save the ;; Stacked-expansion: This checks for stacked expansion, save the
;; `yas--previous-active-field' and advance its boundary. ;; `yas--previous-active-field' and advance its boundary.
(let ((existing-field (and yas--active-field-overlay (let ((existing-field (yas-current-field)))
(overlay-buffer yas--active-field-overlay)
(overlay-get yas--active-field-overlay 'yas--field))))
(when existing-field (when existing-field
(setf (yas--snippet-previous-active-field snippet) existing-field) (setf (yas--snippet-previous-active-field snippet) existing-field)
(yas--advance-end-maybe-previous-fields (yas--advance-end-maybe-previous-fields