@@ -1777,6 +1777,21 @@ all symbols are bound before any of the VALUEFORMs are evalled."
1777
1777
,@(mapcar (lambda (binder ) `(setq ,@binder )) binders)
1778
1778
,@body ))
1779
1779
1780
+ (defmacro dlet (binders &rest body )
1781
+ " Like `let*' but using dynamic scoping."
1782
+ (declare (indent 1 ) (debug let ))
1783
+ ; ; (defvar FOO) only affects the current scope, but in order for
1784
+ ; ; this not to affect code after the `let*' we need to create a new scope,
1785
+ ; ; which is what the surrounding `let' is for.
1786
+ ; ; FIXME: (let () ...) currently doesn't actually create a new scope,
1787
+ ; ; which is why we use (let (_) ...).
1788
+ `(let (_)
1789
+ ,@(mapcar (lambda (binder )
1790
+ `(defvar ,(if (consp binder) (car binder) binder)))
1791
+ binders)
1792
+ (let* , binders ,@body )))
1793
+
1794
+
1780
1795
(defmacro with-wrapper-hook (hook args &rest body )
1781
1796
" Run BODY, using wrapper functions from HOOK with additional ARGS.
1782
1797
HOOK is an abnormal hook. Each hook function in HOOK \" wraps\"
@@ -2972,13 +2987,14 @@ This finishes the change group by reverting all of its changes."
2972
2987
; ; the body of `atomic-change-group' all changes can be undone.
2973
2988
(widen )
2974
2989
(let ((old-car (car-safe elt))
2975
- (old-cdr (cdr-safe elt)))
2990
+ (old-cdr (cdr-safe elt))
2991
+ (start-pul pending-undo-list))
2976
2992
(unwind-protect
2977
2993
(progn
2978
2994
; ; Temporarily truncate the undo log at ELT.
2979
2995
(when (consp elt)
2980
2996
(setcar elt nil ) (setcdr elt nil ))
2981
- (unless ( eq last-command ' undo) ( undo-start ) )
2997
+ (setq pending- undo-list buffer- undo-list )
2982
2998
; ; Make sure there's no confusion.
2983
2999
(when (and (consp elt) (not (eq elt (last pending-undo-list))))
2984
3000
(error " Undoing to some unrelated state " ))
@@ -2991,7 +3007,13 @@ This finishes the change group by reverting all of its changes."
2991
3007
; ; Reset the modified cons cell ELT to its original content.
2992
3008
(when (consp elt)
2993
3009
(setcar elt old-car)
2994
- (setcdr elt old-cdr))))))))
3010
+ (setcdr elt old-cdr)))
3011
+ ; ; Let's not break a sequence of undos just because we
3012
+ ; ; tried to make a change and then undid it: preserve
3013
+ ; ; the original `pending-undo-list' if it's still valid.
3014
+ (if (eq (undo--last-change-was-undo-p buffer-undo-list)
3015
+ start-pul)
3016
+ (setq pending-undo-list start-pul)))))))
2995
3017
2996
3018
; ;;; Display-related functions.
2997
3019
@@ -3970,7 +3992,7 @@ the function `undo--wrap-and-run-primitive-undo'."
3970
3992
(let (; ; (inhibit-modification-hooks t)
3971
3993
(before-change-functions
3972
3994
; ; Ugly Hack: if the body uses syntax-ppss/syntax-propertize
3973
- ; ; (e.g. via a regexp-search or sexp-movement trigerring
3995
+ ; ; (e.g. via a regexp-search or sexp-movement triggering
3974
3996
; ; on-the-fly syntax-propertize), make sure that this gets
3975
3997
; ; properly refreshed after subsequent changes.
3976
3998
(if (memq #'syntax-ppss-flush-cache before-change-functions)
0 commit comments