diff options
| author | Eli Zaretskii | 2024-01-13 05:36:15 -0500 |
|---|---|---|
| committer | Eli Zaretskii | 2024-01-13 05:36:15 -0500 |
| commit | 79a150ffa492709e04acbb646ff0a050fa90d5c9 (patch) | |
| tree | 117ac13e8b494f240baebac85b59eeb695659e43 | |
| parent | 740953d1a2f4ea4a200637872b9ecb7dfddfdbe4 (diff) | |
| parent | d58d0fa52ff22e147b8328759d5f0f762e15bbb5 (diff) | |
| download | emacs-79a150ffa492709e04acbb646ff0a050fa90d5c9.tar.gz emacs-79a150ffa492709e04acbb646ff0a050fa90d5c9.zip | |
Merge from origin/emacs-29
d58d0fa52ff Introduce 'let' using lexical binding in the Lisp Introdu...
1b123972636 ; Don't record multiple versions of use-package
8729a2a10d9 Fix 'rmail-summary-by-thread'
2a8c00bfc07 * doc/emacs/back.texi: Fix a typo.
| -rw-r--r-- | doc/emacs/back.texi | 2 | ||||
| -rw-r--r-- | doc/lispintro/emacs-lisp-intro.texi | 171 | ||||
| -rw-r--r-- | lisp/mail/rmailsum.el | 24 | ||||
| -rw-r--r-- | lisp/use-package/use-package-ensure-system-package.el | 1 |
4 files changed, 162 insertions, 36 deletions
diff --git a/doc/emacs/back.texi b/doc/emacs/back.texi index b8094c6cf36..ff6905d8b02 100644 --- a/doc/emacs/back.texi +++ b/doc/emacs/back.texi | |||
| @@ -78,7 +78,7 @@ And much more! | |||
| 78 | Emacs comes with an introductory online tutorial available in many | 78 | Emacs comes with an introductory online tutorial available in many |
| 79 | languages, and this nineteenth edition of the manual picks up where | 79 | languages, and this nineteenth edition of the manual picks up where |
| 80 | that tutorial ends. It explains the full range of the power of Emacs, | 80 | that tutorial ends. It explains the full range of the power of Emacs, |
| 81 | now up to @strong[version 27.2,} and contains reference material | 81 | now up to @strong{version 27.2,} and contains reference material |
| 82 | useful to expert users. It also includes appendices with specific | 82 | useful to expert users. It also includes appendices with specific |
| 83 | material about X and GTK resources, and with details for users of | 83 | material about X and GTK resources, and with details for users of |
| 84 | macOS and Microsoft Windows. | 84 | macOS and Microsoft Windows. |
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index 1e10f62104a..b3fe8ce4589 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi | |||
| @@ -3556,6 +3556,7 @@ and the two are not intended to refer to the same value. The | |||
| 3556 | * Parts of let Expression:: | 3556 | * Parts of let Expression:: |
| 3557 | * Sample let Expression:: | 3557 | * Sample let Expression:: |
| 3558 | * Uninitialized let Variables:: | 3558 | * Uninitialized let Variables:: |
| 3559 | * How let Binds Variables:: | ||
| 3559 | @end menu | 3560 | @end menu |
| 3560 | 3561 | ||
| 3561 | @ifnottex | 3562 | @ifnottex |
| @@ -3569,24 +3570,26 @@ and the two are not intended to refer to the same value. The | |||
| 3569 | @cindex @samp{variable, local}, defined | 3570 | @cindex @samp{variable, local}, defined |
| 3570 | The @code{let} special form prevents confusion. @code{let} creates a | 3571 | The @code{let} special form prevents confusion. @code{let} creates a |
| 3571 | name for a @dfn{local variable} that overshadows any use of the same | 3572 | name for a @dfn{local variable} that overshadows any use of the same |
| 3572 | name outside the @code{let} expression. This is like understanding | 3573 | name outside the @code{let} expression (in computer science jargon, we |
| 3573 | that whenever your host refers to ``the house'', he means his house, not | 3574 | call this @dfn{binding} the variable). This is like understanding |
| 3574 | yours. (Symbols used in argument lists work the same way. | 3575 | that in your host's home, whenever he refers to ``the house'', he |
| 3576 | means his house, not yours. (The symbols used to name function | ||
| 3577 | arguments are bound as local variables in exactly the same way. | ||
| 3575 | @xref{defun, , The @code{defun} Macro}.) | 3578 | @xref{defun, , The @code{defun} Macro}.) |
| 3576 | 3579 | ||
| 3577 | Local variables created by a @code{let} expression retain their value | 3580 | Another way to think about @code{let} is that it defines a special |
| 3578 | @emph{only} within the @code{let} expression itself (and within | 3581 | region in your code: within the body of the @code{let} expression, the |
| 3579 | expressions called within the @code{let} expression); the local | 3582 | variables you've named have their own local meaning. Outside of the |
| 3580 | variables have no effect outside the @code{let} expression. | 3583 | @code{let} body, they have other meanings (or they may not be defined |
| 3581 | 3584 | at all). This means that inside the @code{let} body, calling | |
| 3582 | Another way to think about @code{let} is that it is like a @code{setq} | 3585 | @code{setq} for a variable named by the @code{let} expression will set |
| 3583 | that is temporary and local. The values set by @code{let} are | 3586 | the value of the @emph{local} variable of that name. However, outside |
| 3584 | automatically undone when the @code{let} is finished. The setting | 3587 | of the @code{let} body (such as when calling a function that was |
| 3585 | only affects expressions that are inside the bounds of the @code{let} | 3588 | defined elsewhere), calling @code{setq} for a variable named by the |
| 3586 | expression. In computer science jargon, we would say the binding of | 3589 | @code{let} expression will @emph{not} affect that local |
| 3587 | a symbol is visible only in functions called in the @code{let} form; | 3590 | variable.@footnote{This describes the behavior of @code{let} when |
| 3588 | in Emacs Lisp, the default scoping is dynamic, not lexical. (The | 3591 | using a style called ``lexical binding'' (@pxref{How let Binds |
| 3589 | non-default lexical binding is not discussed in this manual.) | 3592 | Variables}).} |
| 3590 | 3593 | ||
| 3591 | @code{let} can create more than one variable at once. Also, | 3594 | @code{let} can create more than one variable at once. Also, |
| 3592 | @code{let} gives each variable it creates an initial value, either a | 3595 | @code{let} gives each variable it creates an initial value, either a |
| @@ -3746,6 +3749,128 @@ number is printed in the message using a @samp{%d} rather than a | |||
| 3746 | @samp{%s}.) The four variables as a group are put into a list to | 3749 | @samp{%s}.) The four variables as a group are put into a list to |
| 3747 | delimit them from the body of the @code{let}. | 3750 | delimit them from the body of the @code{let}. |
| 3748 | 3751 | ||
| 3752 | @node How let Binds Variables | ||
| 3753 | @subsection How @code{let} Binds Variables | ||
| 3754 | |||
| 3755 | Emacs Lisp supports two different ways of binding variable names to | ||
| 3756 | their values. These ways affect the parts of your program where a | ||
| 3757 | particular binding is valid. For historical reasons, Emacs Lisp uses | ||
| 3758 | a form of variable binding called @dfn{dynamic binding} by default. | ||
| 3759 | However, in this manual we discuss the preferred form of binding, | ||
| 3760 | called @dfn{lexical binding}, unless otherwise noted (in the future, | ||
| 3761 | the Emacs maintainers plan to change the default to lexical binding). | ||
| 3762 | If you have programmed in other languages before, you're likely | ||
| 3763 | already familiar with how lexical binding behaves. | ||
| 3764 | |||
| 3765 | In order to use lexical binding in a program, you should add this to | ||
| 3766 | the first line of your Emacs Lisp file: | ||
| 3767 | |||
| 3768 | @example | ||
| 3769 | ;;; -*- lexical-binding: t -*- | ||
| 3770 | @end example | ||
| 3771 | |||
| 3772 | For more information about this, @pxref{Selecting Lisp Dialect, , , | ||
| 3773 | elisp, The Emacs Lisp Reference Manual}. | ||
| 3774 | |||
| 3775 | @menu | ||
| 3776 | * Lexical & Dynamic Binding Differences:: | ||
| 3777 | * Lexical vs. Dynamic Binding Example:: | ||
| 3778 | @end menu | ||
| 3779 | |||
| 3780 | @node Lexical & Dynamic Binding Differences | ||
| 3781 | @unnumberedsubsubsec Differences Between Lexical and Dynamic Binding | ||
| 3782 | |||
| 3783 | @cindex Lexical binding | ||
| 3784 | @cindex Binding, lexical | ||
| 3785 | As we discussed before (@pxref{Prevent confusion}), when you create | ||
| 3786 | local variables with @code{let} under lexical binding, those variables | ||
| 3787 | are valid only within the body of the @code{let} expression. In other | ||
| 3788 | parts of your code, they have other meanings, so if you call a | ||
| 3789 | function defined elsewhere within the @code{let} body, that function | ||
| 3790 | would be unable to ``see'' the local variables you've created. (On | ||
| 3791 | the other hand, if you call a function that was defined within a | ||
| 3792 | @code{let} body, that function @emph{would} be able to see---and | ||
| 3793 | modify---the local variables from that @code{let} expression.) | ||
| 3794 | |||
| 3795 | @cindex Dynamic binding | ||
| 3796 | @cindex Binding, dynamic | ||
| 3797 | Under dynamic binding, the rules are different: instead, when you use | ||
| 3798 | @code{let}, the local variables you've created are valid during | ||
| 3799 | execution of the @code{let} expression. This means that, if your | ||
| 3800 | @code{let} expression calls a function, that function can see these | ||
| 3801 | local variables, regardless of where the function is defined | ||
| 3802 | (including in another file entirely). | ||
| 3803 | |||
| 3804 | Another way to think about @code{let} when using dynamic binding is | ||
| 3805 | that every variable name has a global ``stack'' of bindings, and | ||
| 3806 | whenever you use that variable's name, it refers to the binding on the | ||
| 3807 | top of the stack. (You can imagine this like a stack of papers on | ||
| 3808 | your desk with the values written on them.) When you bind a variable | ||
| 3809 | dynamically with @code{let}, it puts the new binding you've specified | ||
| 3810 | on the top of the stack, and then executes the @code{let} body. Once | ||
| 3811 | the @code{let} body finishes, it takes that binding off of the stack, | ||
| 3812 | revealing the one it had (if any) before the @code{let} expression. | ||
| 3813 | |||
| 3814 | @node Lexical vs. Dynamic Binding Example | ||
| 3815 | @unnumberedsubsubsec Example of Lexical vs. Dynamic Binding | ||
| 3816 | In some cases, both lexical and dynamic binding behave identically. | ||
| 3817 | However, in other cases, they can change the meaning of your program. | ||
| 3818 | For example, see what happens in this code under lexical binding: | ||
| 3819 | |||
| 3820 | @example | ||
| 3821 | ;;; -*- lexical-binding: t -*- | ||
| 3822 | |||
| 3823 | (setq x 0) | ||
| 3824 | |||
| 3825 | (defun getx () | ||
| 3826 | x) | ||
| 3827 | |||
| 3828 | (setq x 1) | ||
| 3829 | |||
| 3830 | (let ((x 2)) | ||
| 3831 | (getx)) | ||
| 3832 | @result{} 1 | ||
| 3833 | @end example | ||
| 3834 | |||
| 3835 | @noindent | ||
| 3836 | Here, the result of @code{(getx)} is @code{1}. Under lexical binding, | ||
| 3837 | @code{getx} doesn't see the value from our @code{let} expression. | ||
| 3838 | That's because the body of @code{getx} is outside of the body of our | ||
| 3839 | @code{let} expression. Since @code{getx} is defined at the top, | ||
| 3840 | global level of our code (i.e.@: not inside the body of any @code{let} | ||
| 3841 | expression), it looks for and finds @code{x} at the global level as | ||
| 3842 | well. When executing @code{getx}, the current global value of | ||
| 3843 | @code{x} is @code{1}, so that's what @code{getx} returns. | ||
| 3844 | |||
| 3845 | If we use dynamic binding instead, the behavior is different: | ||
| 3846 | |||
| 3847 | @example | ||
| 3848 | ;;; -*- lexical-binding: nil -*- | ||
| 3849 | |||
| 3850 | (setq x 0) | ||
| 3851 | |||
| 3852 | (defun getx () | ||
| 3853 | x) | ||
| 3854 | |||
| 3855 | (setq x 1) | ||
| 3856 | |||
| 3857 | (let ((x 2)) | ||
| 3858 | (getx)) | ||
| 3859 | @result{} 2 | ||
| 3860 | @end example | ||
| 3861 | |||
| 3862 | @noindent | ||
| 3863 | Now, the result of @code{(getx)} is @code{2}! That's because under | ||
| 3864 | dynamic binding, when executing @code{getx}, the current binding for | ||
| 3865 | @code{x} at the top of our stack is the one from our @code{let} | ||
| 3866 | binding. This time, @code{getx} doesn't see the global value for | ||
| 3867 | @code{x}, since its binding is below the one from our @code{let} | ||
| 3868 | expression in the stack of bindings. | ||
| 3869 | |||
| 3870 | (Some variables are also ``special'', and they are always dynamically | ||
| 3871 | bound even when @code{lexical-binding} is @code{t}. @xref{defvar, , | ||
| 3872 | Initializing a Variable with @code{defvar}}.) | ||
| 3873 | |||
| 3749 | @node if | 3874 | @node if |
| 3750 | @section The @code{if} Special Form | 3875 | @section The @code{if} Special Form |
| 3751 | @findex if | 3876 | @findex if |
| @@ -9101,12 +9226,14 @@ In Emacs Lisp, a variable such as the @code{kill-ring} is created and | |||
| 9101 | given an initial value by using the @code{defvar} special form. The | 9226 | given an initial value by using the @code{defvar} special form. The |
| 9102 | name comes from ``define variable''. | 9227 | name comes from ``define variable''. |
| 9103 | 9228 | ||
| 9104 | The @code{defvar} special form is similar to @code{setq} in that it sets | 9229 | The @code{defvar} special form is similar to @code{setq} in that it |
| 9105 | the value of a variable. It is unlike @code{setq} in two ways: first, | 9230 | sets the value of a variable. It is unlike @code{setq} in three ways: |
| 9106 | it only sets the value of the variable if the variable does not already | 9231 | first, it marks the variable as ``special'' so that it is always |
| 9107 | have a value. If the variable already has a value, @code{defvar} does | 9232 | dynamically bound, even when @code{lexical-binding} is @code{t} |
| 9108 | not override the existing value. Second, @code{defvar} has a | 9233 | (@pxref{How let Binds Variables}). Second, it only sets the value of |
| 9109 | documentation string. | 9234 | the variable if the variable does not already have a value. If the |
| 9235 | variable already has a value, @code{defvar} does not override the | ||
| 9236 | existing value. Third, @code{defvar} has a documentation string. | ||
| 9110 | 9237 | ||
| 9111 | (There is a related macro, @code{defcustom}, designed for variables | 9238 | (There is a related macro, @code{defcustom}, designed for variables |
| 9112 | that people customize. It has more features than @code{defvar}. | 9239 | that people customize. It has more features than @code{defvar}. |
diff --git a/lisp/mail/rmailsum.el b/lisp/mail/rmailsum.el index 18a36e5f0e9..48c5cb70b33 100644 --- a/lisp/mail/rmailsum.el +++ b/lisp/mail/rmailsum.el | |||
| @@ -436,19 +436,19 @@ headers of the messages." | |||
| 436 | (unless (and rmail-summary-message-parents-vector | 436 | (unless (and rmail-summary-message-parents-vector |
| 437 | (= (length rmail-summary-message-parents-vector) | 437 | (= (length rmail-summary-message-parents-vector) |
| 438 | (1+ rmail-total-messages))) | 438 | (1+ rmail-total-messages))) |
| 439 | (rmail-summary-fill-message-parents-and-descs-vectors)) | 439 | (rmail-summary-fill-message-parents-and-descs-vectors))) |
| 440 | (let ((enc-msgs (make-bool-vector (1+ rmail-total-messages) nil))) | 440 | (let ((enc-msgs (make-bool-vector (1+ rmail-total-messages) nil))) |
| 441 | (rmail-summary--walk-thread-message-recursively msgnum enc-msgs) | 441 | (rmail-summary--walk-thread-message-recursively msgnum enc-msgs) |
| 442 | (rmail-new-summary (format "thread containing message %d" msgnum) | 442 | (rmail-new-summary (format "thread containing message %d" msgnum) |
| 443 | (list 'rmail-summary-by-thread msgnum) | 443 | (list 'rmail-summary-by-thread msgnum) |
| 444 | (if (and rmail-summary-progressively-narrow | 444 | (if (and rmail-summary-progressively-narrow |
| 445 | (rmail-summary--exists-1)) | 445 | (rmail-summary--exists-1)) |
| 446 | (lambda (msg _msgnum) | ||
| 447 | (and (aref rmail-summary-currently-displayed-msgs msg) | ||
| 448 | (aref enc-msgs msg))) | ||
| 449 | (lambda (msg _msgnum) | 446 | (lambda (msg _msgnum) |
| 450 | (aref enc-msgs msg))) | 447 | (and (aref rmail-summary-currently-displayed-msgs msg) |
| 451 | msgnum)))) | 448 | (aref enc-msgs msg))) |
| 449 | (lambda (msg _msgnum) | ||
| 450 | (aref enc-msgs msg))) | ||
| 451 | msgnum))) | ||
| 452 | 452 | ||
| 453 | ;;;###autoload | 453 | ;;;###autoload |
| 454 | (defun rmail-summary-by-labels (labels) | 454 | (defun rmail-summary-by-labels (labels) |
diff --git a/lisp/use-package/use-package-ensure-system-package.el b/lisp/use-package/use-package-ensure-system-package.el index 025721746cc..6c7f8c0a1ea 100644 --- a/lisp/use-package/use-package-ensure-system-package.el +++ b/lisp/use-package/use-package-ensure-system-package.el | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | ;; Author: Justin Talbott <justin@waymondo.com> | 5 | ;; Author: Justin Talbott <justin@waymondo.com> |
| 6 | ;; Keywords: convenience, tools, extensions | 6 | ;; Keywords: convenience, tools, extensions |
| 7 | ;; URL: https://github.com/waymondo/use-package-ensure-system-package | 7 | ;; URL: https://github.com/waymondo/use-package-ensure-system-package |
| 8 | ;; Version: 0.2 | ||
| 9 | ;; Package-Requires: ((use-package "2.1") (system-packages "1.0.4")) | 8 | ;; Package-Requires: ((use-package "2.1") (system-packages "1.0.4")) |
| 10 | ;; Filename: use-package-ensure-system-package.el | 9 | ;; Filename: use-package-ensure-system-package.el |
| 11 | 10 | ||