diff options
| author | Stefan Monnier | 2020-03-10 12:00:51 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-03-10 12:00:51 -0400 |
| commit | 297d3d2e0e17185387c47ad5a0ce4dd448ef7a29 (patch) | |
| tree | 85b5a2397633c4854c11b8fd56c997f543401169 | |
| parent | a98c8f5a098cf646c282be67cce9fb7999d353d7 (diff) | |
| download | emacs-297d3d2e0e17185387c47ad5a0ce4dd448ef7a29.tar.gz emacs-297d3d2e0e17185387c47ad5a0ce4dd448ef7a29.zip | |
* lisp/subr.el (dlet): New macro
* lisp/calendar/calendar.el (calendar-dlet*): Use it.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/calendar/calendar.el | 13 | ||||
| -rw-r--r-- | lisp/subr.el | 30 |
3 files changed, 34 insertions, 11 deletions
| @@ -216,6 +216,8 @@ This is no longer supported, and setting this variable has no effect. | |||
| 216 | 216 | ||
| 217 | * Lisp Changes in Emacs 28.1 | 217 | * Lisp Changes in Emacs 28.1 |
| 218 | 218 | ||
| 219 | ** New macro 'dlet' to dynamically bind variables | ||
| 220 | |||
| 219 | ** The variable 'force-new-style-backquotes' has been removed. | 221 | ** The variable 'force-new-style-backquotes' has been removed. |
| 220 | This removes the final remaining trace of old-style backquotes. | 222 | This removes the final remaining trace of old-style backquotes. |
| 221 | 223 | ||
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 1ae39445680..1d5b9479e2b 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el | |||
| @@ -136,14 +136,13 @@ | |||
| 136 | ;; - whatever is passed to diary-remind | 136 | ;; - whatever is passed to diary-remind |
| 137 | 137 | ||
| 138 | (defmacro calendar-dlet* (binders &rest body) | 138 | (defmacro calendar-dlet* (binders &rest body) |
| 139 | "Like `let*' but using dynamic scoping." | 139 | "Like `dlet' but without warnings about non-prefixed var names." |
| 140 | (declare (indent 1) (debug let)) | 140 | (declare (indent 1) (debug let)) |
| 141 | `(progn | 141 | (let ((vars (mapcar (lambda (binder) |
| 142 | (with-no-warnings ;Silence "lacks a prefix" warnings! | 142 | (if (consp binder) (car binder) binder)) |
| 143 | ,@(mapcar (lambda (binder) | 143 | binders))) |
| 144 | `(defvar ,(if (consp binder) (car binder) binder))) | 144 | `(with-suppressed-warnings ((lexical ,@vars)) |
| 145 | binders)) | 145 | (dlet ,binders ,@body)))) |
| 146 | (let* ,binders ,@body))) | ||
| 147 | 146 | ||
| 148 | ;; Avoid recursive load of calendar when loading cal-menu. Yuck. | 147 | ;; Avoid recursive load of calendar when loading cal-menu. Yuck. |
| 149 | (provide 'calendar) | 148 | (provide 'calendar) |
diff --git a/lisp/subr.el b/lisp/subr.el index 13515ca7da1..359f51c0d0c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1777,6 +1777,21 @@ all symbols are bound before any of the VALUEFORMs are evalled." | |||
| 1777 | ,@(mapcar (lambda (binder) `(setq ,@binder)) binders) | 1777 | ,@(mapcar (lambda (binder) `(setq ,@binder)) binders) |
| 1778 | ,@body)) | 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 | (defmacro with-wrapper-hook (hook args &rest body) | 1795 | (defmacro with-wrapper-hook (hook args &rest body) |
| 1781 | "Run BODY, using wrapper functions from HOOK with additional ARGS. | 1796 | "Run BODY, using wrapper functions from HOOK with additional ARGS. |
| 1782 | HOOK is an abnormal hook. Each hook function in HOOK \"wraps\" | 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 | ;; the body of `atomic-change-group' all changes can be undone. | 2987 | ;; the body of `atomic-change-group' all changes can be undone. |
| 2973 | (widen) | 2988 | (widen) |
| 2974 | (let ((old-car (car-safe elt)) | 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 | (unwind-protect | 2992 | (unwind-protect |
| 2977 | (progn | 2993 | (progn |
| 2978 | ;; Temporarily truncate the undo log at ELT. | 2994 | ;; Temporarily truncate the undo log at ELT. |
| 2979 | (when (consp elt) | 2995 | (when (consp elt) |
| 2980 | (setcar elt nil) (setcdr elt nil)) | 2996 | (setcar elt nil) (setcdr elt nil)) |
| 2981 | (unless (eq last-command 'undo) (undo-start)) | 2997 | (setq pending-undo-list buffer-undo-list) |
| 2982 | ;; Make sure there's no confusion. | 2998 | ;; Make sure there's no confusion. |
| 2983 | (when (and (consp elt) (not (eq elt (last pending-undo-list)))) | 2999 | (when (and (consp elt) (not (eq elt (last pending-undo-list)))) |
| 2984 | (error "Undoing to some unrelated state")) | 3000 | (error "Undoing to some unrelated state")) |
| @@ -2991,7 +3007,13 @@ This finishes the change group by reverting all of its changes." | |||
| 2991 | ;; Reset the modified cons cell ELT to its original content. | 3007 | ;; Reset the modified cons cell ELT to its original content. |
| 2992 | (when (consp elt) | 3008 | (when (consp elt) |
| 2993 | (setcar elt old-car) | 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 | ;;;; Display-related functions. | 3018 | ;;;; Display-related functions. |
| 2997 | 3019 | ||
| @@ -3970,7 +3992,7 @@ the function `undo--wrap-and-run-primitive-undo'." | |||
| 3970 | (let (;; (inhibit-modification-hooks t) | 3992 | (let (;; (inhibit-modification-hooks t) |
| 3971 | (before-change-functions | 3993 | (before-change-functions |
| 3972 | ;; Ugly Hack: if the body uses syntax-ppss/syntax-propertize | 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 | ;; on-the-fly syntax-propertize), make sure that this gets | 3996 | ;; on-the-fly syntax-propertize), make sure that this gets |
| 3975 | ;; properly refreshed after subsequent changes. | 3997 | ;; properly refreshed after subsequent changes. |
| 3976 | (if (memq #'syntax-ppss-flush-cache before-change-functions) | 3998 | (if (memq #'syntax-ppss-flush-cache before-change-functions) |