diff options
| author | Stefan Monnier | 2010-01-04 13:18:38 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-01-04 13:18:38 -0500 |
| commit | c57008f6ef0b368e7beb820d83ab8be09c48736b (patch) | |
| tree | 2c09192eee806ade83c84a7d4ab45bedd87147ec /doc/lispref | |
| parent | e3eb1dae0dbedaa4623e248be0e3db8c9495df02 (diff) | |
| download | emacs-c57008f6ef0b368e7beb820d83ab8be09c48736b.tar.gz emacs-c57008f6ef0b368e7beb820d83ab8be09c48736b.zip | |
Avoid dubious uses of save-excursions.
* doc/lispref/positions.texi (Excursions): Recommend the use of
save-current-buffer if applicable.
* doc/lispref/text.texi (Clickable Text): Fix the example code which used
save-excursion in a naive way which sometimes preserves point and
sometimes not.
* doc/lispref/variables.texi (Creating Buffer-Local):
* doc/lispref/os.texi (Session Management):
* doc/lispref/display.texi (GIF Images):
* doc/lispref/control.texi (Cleanups): Use (save|with)-current-buffer.
* doc/misc/gnus.texi (Posting Styles): Use with-current-buffer.
* doc/misc/calc.texi (Defining Simple Commands): Prefer save-current-buffer.
Diffstat (limited to 'doc/lispref')
| -rw-r--r-- | doc/lispref/ChangeLog | 15 | ||||
| -rw-r--r-- | doc/lispref/control.texi | 7 | ||||
| -rw-r--r-- | doc/lispref/display.texi | 3 | ||||
| -rw-r--r-- | doc/lispref/os.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/positions.texi | 12 | ||||
| -rw-r--r-- | doc/lispref/text.texi | 13 | ||||
| -rw-r--r-- | doc/lispref/variables.texi | 3 |
7 files changed, 33 insertions, 22 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index e7467c20d25..6dfc203f638 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2010-01-04 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | Avoid dubious uses of save-excursions. | ||
| 4 | * positions.texi (Excursions): Recommend the use of | ||
| 5 | save-current-buffer if applicable. | ||
| 6 | * text.texi (Clickable Text): Fix the example code which used | ||
| 7 | save-excursion in a naive way which sometimes preserves point and | ||
| 8 | sometimes not. | ||
| 9 | * variables.texi (Creating Buffer-Local): | ||
| 10 | * os.texi (Session Management): | ||
| 11 | * display.texi (GIF Images): | ||
| 12 | * control.texi (Cleanups): Use (save|with)-current-buffer. | ||
| 13 | |||
| 1 | 2010-01-02 Eli Zaretskii <eliz@gnu.org> | 14 | 2010-01-02 Eli Zaretskii <eliz@gnu.org> |
| 2 | 15 | ||
| 3 | * modes.texi (Example Major Modes): Fix indentation. (Bug#5195) | 16 | * modes.texi (Example Major Modes): Fix indentation. (Bug#5195) |
| @@ -8375,7 +8388,7 @@ | |||
| 8375 | ;; End: | 8388 | ;; End: |
| 8376 | 8389 | ||
| 8377 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, | 8390 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
| 8378 | 2007, 2008, 2009 Free Software Foundation, Inc. | 8391 | 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
| 8379 | 8392 | ||
| 8380 | This file is part of GNU Emacs. | 8393 | This file is part of GNU Emacs. |
| 8381 | 8394 | ||
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 41f844b4e21..6d7c01d354b 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -1255,9 +1255,8 @@ make sure to kill it before finishing: | |||
| 1255 | 1255 | ||
| 1256 | @smallexample | 1256 | @smallexample |
| 1257 | @group | 1257 | @group |
| 1258 | (save-excursion | 1258 | (let ((buffer (get-buffer-create " *temp*"))) |
| 1259 | (let ((buffer (get-buffer-create " *temp*"))) | 1259 | (with-current-buffer buffer |
| 1260 | (set-buffer buffer) | ||
| 1261 | (unwind-protect | 1260 | (unwind-protect |
| 1262 | @var{body-form} | 1261 | @var{body-form} |
| 1263 | (kill-buffer buffer)))) | 1262 | (kill-buffer buffer)))) |
| @@ -1269,7 +1268,7 @@ You might think that we could just as well write @code{(kill-buffer | |||
| 1269 | (current-buffer))} and dispense with the variable @code{buffer}. | 1268 | (current-buffer))} and dispense with the variable @code{buffer}. |
| 1270 | However, the way shown above is safer, if @var{body-form} happens to | 1269 | However, the way shown above is safer, if @var{body-form} happens to |
| 1271 | get an error after switching to a different buffer! (Alternatively, | 1270 | get an error after switching to a different buffer! (Alternatively, |
| 1272 | you could write another @code{save-excursion} around @var{body-form}, | 1271 | you could write a @code{save-current-buffer} around @var{body-form}, |
| 1273 | to ensure that the temporary buffer becomes current again in time to | 1272 | to ensure that the temporary buffer becomes current again in time to |
| 1274 | kill it.) | 1273 | kill it.) |
| 1275 | 1274 | ||
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 8feb8ea8c81..512d7d53019 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -4394,8 +4394,7 @@ every 0.1 seconds. | |||
| 4394 | (when (= idx max) | 4394 | (when (= idx max) |
| 4395 | (setq idx 0)) | 4395 | (setq idx 0)) |
| 4396 | (let ((img (create-image file nil :image idx))) | 4396 | (let ((img (create-image file nil :image idx))) |
| 4397 | (save-excursion | 4397 | (with-current-buffer buffer |
| 4398 | (set-buffer buffer) | ||
| 4399 | (goto-char (point-min)) | 4398 | (goto-char (point-min)) |
| 4400 | (unless first-time (delete-char 1)) | 4399 | (unless first-time (delete-char 1)) |
| 4401 | (insert-image img)) | 4400 | (insert-image img)) |
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index ded70f4927b..8d62ab87499 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -2182,7 +2182,7 @@ Emacs is restarted by the session manager. | |||
| 2182 | 2182 | ||
| 2183 | @group | 2183 | @group |
| 2184 | (defun save-yourself-test () | 2184 | (defun save-yourself-test () |
| 2185 | (insert "(save-excursion | 2185 | (insert "(save-current-buffer |
| 2186 | (switch-to-buffer \"*scratch*\") | 2186 | (switch-to-buffer \"*scratch*\") |
| 2187 | (insert \"I am restored\"))") | 2187 | (insert \"I am restored\"))") |
| 2188 | nil) | 2188 | nil) |
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi index deded596f81..3897efc6f2b 100644 --- a/doc/lispref/positions.texi +++ b/doc/lispref/positions.texi | |||
| @@ -806,7 +806,9 @@ after the completion of the excursion. | |||
| 806 | 806 | ||
| 807 | The forms for saving and restoring the configuration of windows are | 807 | The forms for saving and restoring the configuration of windows are |
| 808 | described elsewhere (see @ref{Window Configurations}, and @pxref{Frame | 808 | described elsewhere (see @ref{Window Configurations}, and @pxref{Frame |
| 809 | Configurations}). | 809 | Configurations}). When only the identity of the current buffer needs |
| 810 | to be saved and restored, it is preferable to use | ||
| 811 | @code{save-current-buffer} instead. | ||
| 810 | 812 | ||
| 811 | @defspec save-excursion body@dots{} | 813 | @defspec save-excursion body@dots{} |
| 812 | @cindex mark excursion | 814 | @cindex mark excursion |
| @@ -817,10 +819,10 @@ buffer and the values of point and the mark in it, evaluates | |||
| 817 | point and the mark. All three saved values are restored even in case of | 819 | point and the mark. All three saved values are restored even in case of |
| 818 | an abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}). | 820 | an abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}). |
| 819 | 821 | ||
| 820 | The @code{save-excursion} special form is the standard way to switch | 822 | The @code{save-excursion} special form is the standard way to move |
| 821 | buffers or move point within one part of a program and avoid affecting | 823 | point within one part of a program and avoid affecting the rest of the |
| 822 | the rest of the program. It is used more than 4000 times in the Lisp | 824 | program. It is used more than 4000 times in the Lisp sources |
| 823 | sources of Emacs. | 825 | of Emacs. |
| 824 | 826 | ||
| 825 | @code{save-excursion} does not save the values of point and the mark for | 827 | @code{save-excursion} does not save the values of point and the mark for |
| 826 | other buffers, so changes in other buffers remain in effect after | 828 | other buffers, so changes in other buffers remain in effect after |
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 91b65017754..7c3f91c3fa8 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -3524,13 +3524,12 @@ following command: | |||
| 3524 | (defun dired-mouse-find-file-other-window (event) | 3524 | (defun dired-mouse-find-file-other-window (event) |
| 3525 | "In Dired, visit the file or directory name you click on." | 3525 | "In Dired, visit the file or directory name you click on." |
| 3526 | (interactive "e") | 3526 | (interactive "e") |
| 3527 | (let (window pos file) | 3527 | (let ((window (posn-window (event-end event))) |
| 3528 | (save-excursion | 3528 | (pos (posn-point (event-end event))) |
| 3529 | (setq window (posn-window (event-end event)) | 3529 | file) |
| 3530 | pos (posn-point (event-end event))) | 3530 | (if (not (windowp window)) |
| 3531 | (if (not (windowp window)) | 3531 | (error "No file chosen")) |
| 3532 | (error "No file chosen")) | 3532 | (with-current-buffer (window-buffer window) |
| 3533 | (set-buffer (window-buffer window)) | ||
| 3534 | (goto-char pos) | 3533 | (goto-char pos) |
| 3535 | (setq file (dired-get-file-for-visit))) | 3534 | (setq file (dired-get-file-for-visit))) |
| 3536 | (if (file-directory-p file) | 3535 | (if (file-directory-p file) |
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 4f9f9c17369..d8ab347eebf 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -1240,8 +1240,7 @@ foo | |||
| 1240 | 1240 | ||
| 1241 | @group | 1241 | @group |
| 1242 | ;; @r{In buffer @samp{b2}, the value hasn't changed.} | 1242 | ;; @r{In buffer @samp{b2}, the value hasn't changed.} |
| 1243 | (save-excursion | 1243 | (with-current-buffer "b2" |
| 1244 | (set-buffer "b2") | ||
| 1245 | foo) | 1244 | foo) |
| 1246 | @result{} 5 | 1245 | @result{} 5 |
| 1247 | @end group | 1246 | @end group |