summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.emacs.d/lisp/yasnippet.el79
1 files changed, 56 insertions, 23 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index 9c7e88f..87536a2 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -1412,15 +1412,51 @@ Returns (TEMPLATES START END). This function respects
1412 1412
1413;;; Internal functions and macros: 1413;;; Internal functions and macros:
1414 1414
1415(defun yas--remove-misc-free-from-undo (old-undo-list)
1416 "Tries to work around Emacs Bug#30931.
1417Helper function for `yas--save-restriction-and-widen'."
1418 ;; If Bug#30931 is unfixed, we get (#<Lisp_Misc_Free> . INTEGER)
1419 ;; entries in the undo list. If we call `type-of' on the
1420 ;; Lisp_Misc_Free object then Emacs aborts, so try to find it by
1421 ;; checking that its type is none of the expected ones.
1422 (when (consp buffer-undo-list)
1423 (let* ((prev buffer-undo-list)
1424 (undo-list prev))
1425 (while (and (consp undo-list)
1426 ;; Only check new entries.
1427 (not (eq undo-list old-undo-list)))
1428 (let ((entry (pop undo-list)))
1429 (when (consp entry)
1430 (let ((head (car entry)))
1431 (unless (or (stringp head)
1432 (markerp head)
1433 (integerp head)
1434 (symbolp head)
1435 (not (integerp (cdr entry))))
1436 ;; (message "removing misc free %S" entry)
1437 (setcdr prev undo-list)))))
1438 (setq prev undo-list)))))
1439
1440(defmacro yas--save-restriction-and-widen (&rest body)
1441 "Equivalent to (save-restriction (widen) BODY).
1442Also tries to work around Emacs Bug#30931."
1443 (declare (debug (body)) (indent 0))
1444 ;; Disable garbage collection, since it could cause an abort.
1445 `(let ((gc-cons-threshold most-positive-fixnum)
1446 (old-undo-list buffer-undo-list))
1447 (prog1 (save-restriction
1448 (widen)
1449 ,@body)
1450 (yas--remove-misc-free-from-undo old-undo-list))))
1451
1415(defun yas--eval-for-string (form) 1452(defun yas--eval-for-string (form)
1416 "Evaluate FORM and convert the result to string." 1453 "Evaluate FORM and convert the result to string."
1417 (let ((debug-on-error (and (not (memq yas-good-grace '(t inline))) 1454 (let ((debug-on-error (and (not (memq yas-good-grace '(t inline)))
1418 debug-on-error))) 1455 debug-on-error)))
1419 (condition-case oops 1456 (condition-case oops
1420 (save-excursion 1457 (save-excursion
1421 (save-restriction 1458 (yas--save-restriction-and-widen
1422 (save-match-data 1459 (save-match-data
1423 (widen)
1424 (let ((result (eval form))) 1460 (let ((result (eval form)))
1425 (when result 1461 (when result
1426 (format "%s" result)))))) 1462 (format "%s" result))))))
@@ -3390,9 +3426,8 @@ This renders the snippet as ordinary text."
3390 ;; 3426 ;;
3391 (yas--markers-to-points snippet) 3427 (yas--markers-to-points snippet)
3392 3428
3393 ;; Take care of snippet revival 3429 ;; Take care of snippet revival on undo.
3394 ;; 3430 (if (and yas-snippet-revival (listp buffer-undo-list))
3395 (if yas-snippet-revival
3396 (push `(apply yas--snippet-revive ,yas-snippet-beg ,yas-snippet-end ,snippet) 3431 (push `(apply yas--snippet-revive ,yas-snippet-beg ,yas-snippet-end ,snippet)
3397 buffer-undo-list) 3432 buffer-undo-list)
3398 ;; Dismember the snippet... this is useful if we get called 3433 ;; Dismember the snippet... this is useful if we get called
@@ -3963,8 +3998,9 @@ After revival, push the `yas--take-care-of-redo' in the
3963 (when (yas--maybe-move-to-active-field snippet) 3998 (when (yas--maybe-move-to-active-field snippet)
3964 (setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay snippet beg end)) 3999 (setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay snippet beg end))
3965 (overlay-put (yas--snippet-control-overlay snippet) 'yas--snippet snippet) 4000 (overlay-put (yas--snippet-control-overlay snippet) 'yas--snippet snippet)
3966 (push `(apply yas--take-care-of-redo ,snippet) 4001 (when (listp buffer-undo-list)
3967 buffer-undo-list))) 4002 (push `(apply yas--take-care-of-redo ,snippet)
4003 buffer-undo-list))))
3968 4004
3969(defun yas--snippet-create (content expand-env begin end) 4005(defun yas--snippet-create (content expand-env begin end)
3970 "Create a snippet from a template inserted at BEGIN to END. 4006 "Create a snippet from a template inserted at BEGIN to END.
@@ -3984,16 +4020,18 @@ Returns the newly created snippet."
3984 (narrow-to-region begin end) 4020 (narrow-to-region begin end)
3985 (goto-char (point-min)) 4021 (goto-char (point-min))
3986 (yas--snippet-parse-create snippet)) 4022 (yas--snippet-parse-create snippet))
3987 (push (cons (point-min) (point-max)) 4023 (when (listp buffer-undo-list)
3988 buffer-undo-list) 4024 (push (cons (point-min) (point-max))
4025 buffer-undo-list))
3989 4026
3990 ;; Indent, collecting undo information normally. 4027 ;; Indent, collecting undo information normally.
3991 (yas--indent snippet) 4028 (yas--indent snippet)
3992 4029
3993 ;; Follow up with `yas--take-care-of-redo' on the newly 4030 ;; Follow up with `yas--take-care-of-redo' on the newly
3994 ;; inserted snippet boundaries. 4031 ;; inserted snippet boundaries.
3995 (push `(apply yas--take-care-of-redo ,snippet) 4032 (when (listp buffer-undo-list)
3996 buffer-undo-list) 4033 (push `(apply yas--take-care-of-redo ,snippet)
4034 buffer-undo-list))
3997 4035
3998 ;; Sort and link each field 4036 ;; Sort and link each field
3999 (yas--snippet-sort-fields snippet) 4037 (yas--snippet-sort-fields snippet)
@@ -4185,8 +4223,7 @@ Meant to be called in a narrowed buffer, does various passes"
4185 (syntax-ppss-flush-cache parse-start)) 4223 (syntax-ppss-flush-cache parse-start))
4186 ;; Set "next" links of fields & mirrors. 4224 ;; Set "next" links of fields & mirrors.
4187 (yas--calculate-adjacencies snippet) 4225 (yas--calculate-adjacencies snippet)
4188 (save-restriction 4226 (yas--save-restriction-and-widen ; Delete $-constructs.
4189 (widen) ; Delete $-constructs.
4190 (yas--delete-regions yas--dollar-regions)) 4227 (yas--delete-regions yas--dollar-regions))
4191 ;; Make sure to do this insertion *after* deleting the dollar 4228 ;; Make sure to do this insertion *after* deleting the dollar
4192 ;; regions, otherwise we invalidate the calculated positions of 4229 ;; regions, otherwise we invalidate the calculated positions of
@@ -4327,8 +4364,7 @@ Buffer must be narrowed to BEG..END used to create the snapshot info."
4327 "Indent the lines between FROM and TO with `indent-according-to-mode'. 4364 "Indent the lines between FROM and TO with `indent-according-to-mode'.
4328The SNIPPET's markers are preserved." 4365The SNIPPET's markers are preserved."
4329 (save-excursion 4366 (save-excursion
4330 (save-restriction 4367 (yas--save-restriction-and-widen
4331 (widen)
4332 (let* ((snippet-markers (yas--collect-snippet-markers snippet)) 4368 (let* ((snippet-markers (yas--collect-snippet-markers snippet))
4333 (to (set-marker (make-marker) to))) 4369 (to (set-marker (make-marker) to)))
4334 (goto-char from) 4370 (goto-char from)
@@ -4437,8 +4473,8 @@ Lisp expression."
4437 (setq yas--change-detected t))))) 4473 (setq yas--change-detected t)))))
4438 (while (re-search-forward yas--backquote-lisp-expression-regexp nil t) 4474 (while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
4439 (let ((current-string (match-string-no-properties 1)) transformed) 4475 (let ((current-string (match-string-no-properties 1)) transformed)
4440 (save-restriction (widen) 4476 (yas--save-restriction-and-widen
4441 (delete-region (match-beginning 0) (match-end 0))) 4477 (delete-region (match-beginning 0) (match-end 0)))
4442 (let ((before-change-functions 4478 (let ((before-change-functions
4443 (cons detect-change before-change-functions))) 4479 (cons detect-change before-change-functions)))
4444 (setq transformed (yas--eval-for-string (yas--read-lisp 4480 (setq transformed (yas--eval-for-string (yas--read-lisp
@@ -4448,8 +4484,7 @@ Lisp expression."
4448 (when transformed 4484 (when transformed
4449 (let ((marker (make-marker)) 4485 (let ((marker (make-marker))
4450 (before-change-functions (cdr before-change-functions))) 4486 (before-change-functions (cdr before-change-functions)))
4451 (save-restriction 4487 (yas--save-restriction-and-widen
4452 (widen)
4453 (insert "Y") ;; quite horrendous, I love it :) 4488 (insert "Y") ;; quite horrendous, I love it :)
4454 (set-marker marker (point)) 4489 (set-marker marker (point))
4455 (insert "Y")) 4490 (insert "Y"))
@@ -4469,8 +4504,7 @@ SAVED-QUOTES is the in format returned by `yas--save-backquotes'."
4469 (cl-loop for (marker . string) in saved-quotes do 4504 (cl-loop for (marker . string) in saved-quotes do
4470 (save-excursion 4505 (save-excursion
4471 (goto-char marker) 4506 (goto-char marker)
4472 (save-restriction 4507 (yas--save-restriction-and-widen
4473 (widen)
4474 (delete-char -1) 4508 (delete-char -1)
4475 (insert string) 4509 (insert string)
4476 (delete-char 1)) 4510 (delete-char 1))
@@ -4651,8 +4685,7 @@ When multiple expressions are found, only the last one counts."
4651 4685
4652(defun yas--update-mirrors (snippet) 4686(defun yas--update-mirrors (snippet)
4653 "Update all the mirrors of SNIPPET." 4687 "Update all the mirrors of SNIPPET."
4654 (save-restriction 4688 (yas--save-restriction-and-widen
4655 (widen)
4656 (save-excursion 4689 (save-excursion
4657 (cl-loop 4690 (cl-loop
4658 for (field . mirror) 4691 for (field . mirror)