aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-09-02 12:47:28 +0800
committerChong Yidong2012-09-02 12:47:28 +0800
commit6a787d9a30720e20053909e71d8b7bc313d37a94 (patch)
tree258c7450b4a423bb597ae4eedc723ddb6bb2c211
parent48c948de78cfa6290ca79ab34b7a4d0cb0edfb69 (diff)
downloademacs-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/ChangeLog8
-rw-r--r--doc/lispref/control.texi14
-rw-r--r--doc/lispref/positions.texi3
-rw-r--r--doc/lispref/windows.texi61
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 @@
12012-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
12012-09-01 Paul Eggert <eggert@cs.ucla.edu> 92012-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 560as @code{let} or function calls are exited in this way, the bindings
561unbound, just as they are when these constructs exit normally 561are 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
563and position saved by @code{save-excursion} (@pxref{Excursions}), and 563and position saved by @code{save-excursion} (@pxref{Excursions}), and
564the narrowing status saved by @code{save-restriction} and the window 564the narrowing status saved by @code{save-restriction}. It also runs
565selection saved by @code{save-window-excursion} (@pxref{Window 565any cleanups established with the @code{unwind-protect} special form
566Configurations}). It also runs any cleanups established with the 566when 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}
571that it jumps to. It can equally well be called from another function 569that 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
852correspondences altered by functions such as @code{switch-to-buffer}. 852correspondences altered by functions such as @code{switch-to-buffer}.
853One way to restore these correspondences, and the selected window, is to
854use @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
858point value relocates the saved value, just as it relocates all 855point 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{}
3156This special form records the window configuration, executes @var{forms} 3156This macro records the window configuration of the selected frame,
3157in sequence, then restores the earlier window configuration. The window 3157executes @var{forms} in sequence, then restores the earlier window
3158configuration includes, for each window, the value of point and the 3158configuration. The return value is the value of the final form in
3159portion of the buffer that is visible. It also includes the choice of 3159@var{forms}.
3160selected window. However, it does not include the value of point in 3160
3161the current buffer; use @code{save-excursion} also, if you wish to 3161Most Lisp code should not use this macro; @code{save-selected-window}
3162preserve that. 3162is typically sufficient. In particular, this macro cannot reliably
3163 3163prevent the code in @var{forms} from opening new windows, because new
3164Don't use this construct when @code{save-selected-window} is sufficient. 3164windows might be opened in other frames (@pxref{Choosing Window}), and
3165 3165@code{save-window-excursion} only saves and restores the window
3166Exit from @code{save-window-excursion} always triggers execution of 3166configuration on the current frame.
3167@code{window-size-change-functions}. (It doesn't know how to tell 3167
3168whether the restored configuration actually differs from the one in 3168Do not use this macro in @code{window-size-change-functions}; exiting
3169effect at the end of the @var{forms}.) 3169the macro triggers execution of @code{window-size-change-functions},
3170 3170leading to an endless loop.
3171The return value is the value of the final form in @var{forms}.
3172For 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
3424causes these functions to be called. Changing the frame size also 3403causes these functions to be called. Changing the frame size also
3425counts, because it changes the sizes of the existing windows. 3404counts, because it changes the sizes of the existing windows.
3426 3405
3427It is not a good idea to use @code{save-window-excursion} (@pxref{Window 3406You may use @code{save-selected-window} in these functions
3428Configurations}) in these functions, because that always counts as a 3407(@pxref{Selecting Windows}). However, do not use
3429size change, and it would cause these functions to be called over and 3408@code{save-window-excursion} (@pxref{Window Configurations}); exiting
3430over. In most cases, @code{save-selected-window} (@pxref{Selecting 3409that macro counts as a size change, which would cause these functions
3431Windows}) is what you need here. 3410to 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