diff options
| author | Chong Yidong | 2012-09-02 12:47:28 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-09-02 12:47:28 +0800 |
| commit | 6a787d9a30720e20053909e71d8b7bc313d37a94 (patch) | |
| tree | 258c7450b4a423bb597ae4eedc723ddb6bb2c211 | |
| parent | 48c948de78cfa6290ca79ab34b7a4d0cb0edfb69 (diff) | |
| download | emacs-6a787d9a30720e20053909e71d8b7bc313d37a94.tar.gz emacs-6a787d9a30720e20053909e71d8b7bc313d37a94.zip | |
Recommand against save-window-excursion in Lisp manual.
* windows.texi (Window Configurations): Recommend against using
save-window-excursion.
* control.texi (Catch and Throw):
* positions.texi (Excursions): Don't mention it.
Fixes: debbugs:12075
| -rw-r--r-- | doc/lispref/ChangeLog | 8 | ||||
| -rw-r--r-- | doc/lispref/control.texi | 14 | ||||
| -rw-r--r-- | doc/lispref/positions.texi | 3 | ||||
| -rw-r--r-- | doc/lispref/windows.texi | 61 |
4 files changed, 34 insertions, 52 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 30169d6b7a9..b0156e5ac7e 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-09-02 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * windows.texi (Window Configurations): Recommend against using | ||
| 4 | save-window-excursion (Bug#12075). | ||
| 5 | |||
| 6 | * control.texi (Catch and Throw): | ||
| 7 | * positions.texi (Excursions): Don't mention it. | ||
| 8 | |||
| 1 | 2012-09-01 Paul Eggert <eggert@cs.ucla.edu> | 9 | 2012-09-01 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 10 | ||
| 3 | Better seed support for (random). | 11 | Better seed support for (random). |
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 07d2d0d993c..25a7655b7b8 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -556,16 +556,14 @@ the @code{catch} in @code{foo-outer} specifies the same symbol, so that | |||
| 556 | @code{catch} in between). | 556 | @code{catch} in between). |
| 557 | 557 | ||
| 558 | Executing @code{throw} exits all Lisp constructs up to the matching | 558 | Executing @code{throw} exits all Lisp constructs up to the matching |
| 559 | @code{catch}, including function calls. When binding constructs such as | 559 | @code{catch}, including function calls. When binding constructs such |
| 560 | @code{let} or function calls are exited in this way, the bindings are | 560 | as @code{let} or function calls are exited in this way, the bindings |
| 561 | unbound, just as they are when these constructs exit normally | 561 | are unbound, just as they are when these constructs exit normally |
| 562 | (@pxref{Local Variables}). Likewise, @code{throw} restores the buffer | 562 | (@pxref{Local Variables}). Likewise, @code{throw} restores the buffer |
| 563 | and position saved by @code{save-excursion} (@pxref{Excursions}), and | 563 | and position saved by @code{save-excursion} (@pxref{Excursions}), and |
| 564 | the narrowing status saved by @code{save-restriction} and the window | 564 | the narrowing status saved by @code{save-restriction}. It also runs |
| 565 | selection saved by @code{save-window-excursion} (@pxref{Window | 565 | any cleanups established with the @code{unwind-protect} special form |
| 566 | Configurations}). It also runs any cleanups established with the | 566 | when it exits that form (@pxref{Cleanups}). |
| 567 | @code{unwind-protect} special form when it exits that form | ||
| 568 | (@pxref{Cleanups}). | ||
| 569 | 567 | ||
| 570 | The @code{throw} need not appear lexically within the @code{catch} | 568 | The @code{throw} need not appear lexically within the @code{catch} |
| 571 | that it jumps to. It can equally well be called from another function | 569 | that it jumps to. It can equally well be called from another function |
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi index a59a99d124c..a0c65319850 100644 --- a/doc/lispref/positions.texi +++ b/doc/lispref/positions.texi | |||
| @@ -850,9 +850,6 @@ after setting the desired current buffer, as in the following example: | |||
| 850 | @cindex window excursions | 850 | @cindex window excursions |
| 851 | Likewise, @code{save-excursion} does not restore window-buffer | 851 | Likewise, @code{save-excursion} does not restore window-buffer |
| 852 | correspondences altered by functions such as @code{switch-to-buffer}. | 852 | correspondences altered by functions such as @code{switch-to-buffer}. |
| 853 | One way to restore these correspondences, and the selected window, is to | ||
| 854 | use @code{save-window-excursion} inside @code{save-excursion} | ||
| 855 | (@pxref{Window Configurations}). | ||
| 856 | 853 | ||
| 857 | @strong{Warning:} Ordinary insertion of text adjacent to the saved | 854 | @strong{Warning:} Ordinary insertion of text adjacent to the saved |
| 858 | point value relocates the saved value, just as it relocates all | 855 | point value relocates the saved value, just as it relocates all |
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index ba2a944215d..5fe007ba02d 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -3153,42 +3153,21 @@ as @code{save-window-excursion}: | |||
| 3153 | @end defun | 3153 | @end defun |
| 3154 | 3154 | ||
| 3155 | @defmac save-window-excursion forms@dots{} | 3155 | @defmac save-window-excursion forms@dots{} |
| 3156 | This special form records the window configuration, executes @var{forms} | 3156 | This macro records the window configuration of the selected frame, |
| 3157 | in sequence, then restores the earlier window configuration. The window | 3157 | executes @var{forms} in sequence, then restores the earlier window |
| 3158 | configuration includes, for each window, the value of point and the | 3158 | configuration. The return value is the value of the final form in |
| 3159 | portion of the buffer that is visible. It also includes the choice of | 3159 | @var{forms}. |
| 3160 | selected window. However, it does not include the value of point in | 3160 | |
| 3161 | the current buffer; use @code{save-excursion} also, if you wish to | 3161 | Most Lisp code should not use this macro; @code{save-selected-window} |
| 3162 | preserve that. | 3162 | is typically sufficient. In particular, this macro cannot reliably |
| 3163 | 3163 | prevent the code in @var{forms} from opening new windows, because new | |
| 3164 | Don't use this construct when @code{save-selected-window} is sufficient. | 3164 | windows might be opened in other frames (@pxref{Choosing Window}), and |
| 3165 | 3165 | @code{save-window-excursion} only saves and restores the window | |
| 3166 | Exit from @code{save-window-excursion} always triggers execution of | 3166 | configuration on the current frame. |
| 3167 | @code{window-size-change-functions}. (It doesn't know how to tell | 3167 | |
| 3168 | whether the restored configuration actually differs from the one in | 3168 | Do not use this macro in @code{window-size-change-functions}; exiting |
| 3169 | effect at the end of the @var{forms}.) | 3169 | the macro triggers execution of @code{window-size-change-functions}, |
| 3170 | 3170 | leading to an endless loop. | |
| 3171 | The return value is the value of the final form in @var{forms}. | ||
| 3172 | For example: | ||
| 3173 | |||
| 3174 | @example | ||
| 3175 | @group | ||
| 3176 | (split-window) | ||
| 3177 | @result{} #<window 25 on control.texi> | ||
| 3178 | @end group | ||
| 3179 | @group | ||
| 3180 | (setq w (selected-window)) | ||
| 3181 | @result{} #<window 19 on control.texi> | ||
| 3182 | @end group | ||
| 3183 | @group | ||
| 3184 | (save-window-excursion | ||
| 3185 | (delete-other-windows w) | ||
| 3186 | (switch-to-buffer "foo") | ||
| 3187 | 'do-something) | ||
| 3188 | @result{} do-something | ||
| 3189 | ;; @r{The screen is now split again.} | ||
| 3190 | @end group | ||
| 3191 | @end example | ||
| 3192 | @end defmac | 3171 | @end defmac |
| 3193 | 3172 | ||
| 3194 | @defun window-configuration-p object | 3173 | @defun window-configuration-p object |
| @@ -3424,11 +3403,11 @@ Creating or deleting windows counts as a size change, and therefore | |||
| 3424 | causes these functions to be called. Changing the frame size also | 3403 | causes these functions to be called. Changing the frame size also |
| 3425 | counts, because it changes the sizes of the existing windows. | 3404 | counts, because it changes the sizes of the existing windows. |
| 3426 | 3405 | ||
| 3427 | It is not a good idea to use @code{save-window-excursion} (@pxref{Window | 3406 | You may use @code{save-selected-window} in these functions |
| 3428 | Configurations}) in these functions, because that always counts as a | 3407 | (@pxref{Selecting Windows}). However, do not use |
| 3429 | size change, and it would cause these functions to be called over and | 3408 | @code{save-window-excursion} (@pxref{Window Configurations}); exiting |
| 3430 | over. In most cases, @code{save-selected-window} (@pxref{Selecting | 3409 | that macro counts as a size change, which would cause these functions |
| 3431 | Windows}) is what you need here. | 3410 | to be called over and over. |
| 3432 | @end defvar | 3411 | @end defvar |
| 3433 | 3412 | ||
| 3434 | @defvar window-configuration-change-hook | 3413 | @defvar window-configuration-change-hook |