[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master f9231b0 47/51: Work around Emacs Bug#30931 (Misc_Free in u
From: |
Noam Postavsky |
Subject: |
[elpa] master f9231b0 47/51: Work around Emacs Bug#30931 (Misc_Free in undo list) |
Date: |
Sun, 13 May 2018 13:11:47 -0400 (EDT) |
branch: master
commit f9231b0e3d43cfcf69198f72af3a048ca60aec6e
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Work around Emacs Bug#30931 (Misc_Free in undo list)
* yasnippet.el (yas--remove-misc-free-from-undo): New function.
(yas--save-restriction-and-widen): New macro.
(yas--eval-for-string, yas--snippet-parse-create)
(yas--indent-region, yas--save-backquotes)
(yas--restore-backquotes, yas--update-mirrors): Use it.
---
yasnippet.el | 59 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 45 insertions(+), 14 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index cc87d95..87536a2 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -1412,15 +1412,51 @@ Returns (TEMPLATES START END). This function respects
;;; Internal functions and macros:
+(defun yas--remove-misc-free-from-undo (old-undo-list)
+ "Tries to work around Emacs Bug#30931.
+Helper function for `yas--save-restriction-and-widen'."
+ ;; If Bug#30931 is unfixed, we get (#<Lisp_Misc_Free> . INTEGER)
+ ;; entries in the undo list. If we call `type-of' on the
+ ;; Lisp_Misc_Free object then Emacs aborts, so try to find it by
+ ;; checking that its type is none of the expected ones.
+ (when (consp buffer-undo-list)
+ (let* ((prev buffer-undo-list)
+ (undo-list prev))
+ (while (and (consp undo-list)
+ ;; Only check new entries.
+ (not (eq undo-list old-undo-list)))
+ (let ((entry (pop undo-list)))
+ (when (consp entry)
+ (let ((head (car entry)))
+ (unless (or (stringp head)
+ (markerp head)
+ (integerp head)
+ (symbolp head)
+ (not (integerp (cdr entry))))
+ ;; (message "removing misc free %S" entry)
+ (setcdr prev undo-list)))))
+ (setq prev undo-list)))))
+
+(defmacro yas--save-restriction-and-widen (&rest body)
+ "Equivalent to (save-restriction (widen) BODY).
+Also tries to work around Emacs Bug#30931."
+ (declare (debug (body)) (indent 0))
+ ;; Disable garbage collection, since it could cause an abort.
+ `(let ((gc-cons-threshold most-positive-fixnum)
+ (old-undo-list buffer-undo-list))
+ (prog1 (save-restriction
+ (widen)
+ ,@body)
+ (yas--remove-misc-free-from-undo old-undo-list))))
+
(defun yas--eval-for-string (form)
"Evaluate FORM and convert the result to string."
(let ((debug-on-error (and (not (memq yas-good-grace '(t inline)))
debug-on-error)))
(condition-case oops
(save-excursion
- (save-restriction
+ (yas--save-restriction-and-widen
(save-match-data
- (widen)
(let ((result (eval form)))
(when result
(format "%s" result))))))
@@ -4187,8 +4223,7 @@ Meant to be called in a narrowed buffer, does various
passes"
(syntax-ppss-flush-cache parse-start))
;; Set "next" links of fields & mirrors.
(yas--calculate-adjacencies snippet)
- (save-restriction
- (widen) ; Delete $-constructs.
+ (yas--save-restriction-and-widen ; Delete $-constructs.
(yas--delete-regions yas--dollar-regions))
;; Make sure to do this insertion *after* deleting the dollar
;; regions, otherwise we invalidate the calculated positions of
@@ -4329,8 +4364,7 @@ Buffer must be narrowed to BEG..END used to create the
snapshot info."
"Indent the lines between FROM and TO with `indent-according-to-mode'.
The SNIPPET's markers are preserved."
(save-excursion
- (save-restriction
- (widen)
+ (yas--save-restriction-and-widen
(let* ((snippet-markers (yas--collect-snippet-markers snippet))
(to (set-marker (make-marker) to)))
(goto-char from)
@@ -4439,8 +4473,8 @@ Lisp expression."
(setq yas--change-detected t)))))
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
(let ((current-string (match-string-no-properties 1)) transformed)
- (save-restriction (widen)
- (delete-region (match-beginning 0) (match-end 0)))
+ (yas--save-restriction-and-widen
+ (delete-region (match-beginning 0) (match-end 0)))
(let ((before-change-functions
(cons detect-change before-change-functions)))
(setq transformed (yas--eval-for-string (yas--read-lisp
@@ -4450,8 +4484,7 @@ Lisp expression."
(when transformed
(let ((marker (make-marker))
(before-change-functions (cdr before-change-functions)))
- (save-restriction
- (widen)
+ (yas--save-restriction-and-widen
(insert "Y") ;; quite horrendous, I love it :)
(set-marker marker (point))
(insert "Y"))
@@ -4471,8 +4504,7 @@ SAVED-QUOTES is the in format returned by
`yas--save-backquotes'."
(cl-loop for (marker . string) in saved-quotes do
(save-excursion
(goto-char marker)
- (save-restriction
- (widen)
+ (yas--save-restriction-and-widen
(delete-char -1)
(insert string)
(delete-char 1))
@@ -4653,8 +4685,7 @@ When multiple expressions are found, only the last one
counts."
(defun yas--update-mirrors (snippet)
"Update all the mirrors of SNIPPET."
- (save-restriction
- (widen)
+ (yas--save-restriction-and-widen
(save-excursion
(cl-loop
for (field . mirror)
- [elpa] master 5a29fe6 50/51: Release 0.13.0, (continued)
- [elpa] master 5a29fe6 50/51: Release 0.13.0, Noam Postavsky, 2018/05/13
- [elpa] master 8b421bc 20/51: Reinstate the old debug behaviour for yas-tryout-snippet, Noam Postavsky, 2018/05/13
- [elpa] master 074d670 26/51: Add yasnippet-unload-function, Noam Postavsky, 2018/05/13
- [elpa] master d364425 38/51: * yasnippet.el (yas-field-value): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 05ac1da 31/51: ; yasnippet-tests.el (yas-no-memory-of-bad-snippet): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 3032337 37/51: Improve rendering of docstrings in manual's reference section, Noam Postavsky, 2018/05/13
- [elpa] master ae95810 43/51: ; Try to get more info about 873/919, Noam Postavsky, 2018/05/13
- [elpa] master 15761e8 41/51: Adjust previous fix, Noam Postavsky, 2018/05/13
- [elpa] master 0afc638 35/51: Fix docs for new org mode, Noam Postavsky, 2018/05/13
- [elpa] master 1668607 46/51: Don't add to disabled undo list, Noam Postavsky, 2018/05/13
- [elpa] master f9231b0 47/51: Work around Emacs Bug#30931 (Misc_Free in undo list),
Noam Postavsky <=
- [elpa] master 4755aa9 49/51: Clarify behavior of mirror transforms, Noam Postavsky, 2018/05/13
- [elpa] master e261832 36/51: Add some styling to doc, improve top menu, Noam Postavsky, 2018/05/13
- [elpa] master 58b88d8 39/51: Merge: doc style improvements, Noam Postavsky, 2018/05/13
- [elpa] master e64297e 51/51: * packages/yasnippet: Merge version 0.13.0 from upstream., Noam Postavsky, 2018/05/13