* Suspicious code in gnus-read-descriptions-file
@ 2005-03-22 18:51 Stefan Monnier
2005-03-22 21:53 ` Simon Josefsson
2005-03-22 23:17 ` Jesper Harder
0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2005-03-22 18:51 UTC (permalink / raw)
The code below looks very odd:
(save-excursion
(save-restriction
(set-buffer nntp-server-buffer)
(goto-char (point-min))
(when (or (search-forward "\n.\n" nil t)
(goto-char (point-max)))
(beginning-of-line)
(narrow-to-region (point-min) (point)))
doing a set-buffer between the save-restriction and the narrow-to-region
seems like a bug. How 'bout the patch below? Which turns the set-buffer
into a with-current-buffer and moves it to before the save-excursion.
Maybe the save-excursion could be dropped altogether?
Stefan
--- gnus-start.el 22 mar 2005 13:45:50 -0500 1.35
+++ gnus-start.el 22 mar 2005 13:42:26 -0500
@@ -582,8 +582,7 @@
(defun gnus-subscribe-hierarchically (newgroup)
"Subscribe new NEWGROUP and insert it in hierarchical newsgroup order."
;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
- (save-excursion
- (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
+ (with-current-buffer (nnheader-find-file-noselect gnus-current-startup-file)
(prog1
(let ((groupkey newgroup) before)
(while (and (not before) groupkey)
@@ -841,8 +840,7 @@
;; it's not needed).
;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
(bury-buffer gnus-dribble-buffer)
- (save-excursion
- (set-buffer gnus-group-buffer)
+ (with-current-buffer gnus-group-buffer
(gnus-group-set-mode-line))
(set-buffer obuf))))
@@ -853,10 +851,9 @@
(defun gnus-dribble-read-file ()
"Read the dribble file from disk."
(let ((dribble-file (gnus-dribble-file-name)))
- (save-excursion
- (set-buffer (setq gnus-dribble-buffer
+ (with-current-buffer (setq gnus-dribble-buffer
(gnus-get-buffer-create
- (file-name-nondirectory dribble-file))))
+ (file-name-nondirectory dribble-file)))
(erase-buffer)
(setq buffer-file-name dribble-file)
(auto-save-mode t)
@@ -895,17 +892,15 @@
(defun gnus-dribble-eval-file ()
(when gnus-dribble-eval-file
(setq gnus-dribble-eval-file nil)
- (save-excursion
(let ((gnus-dribble-ignore t))
- (set-buffer gnus-dribble-buffer)
+ (with-current-buffer gnus-dribble-buffer
(eval-buffer (current-buffer))))))
(defun gnus-dribble-delete-file ()
(when (file-exists-p (gnus-dribble-file-name))
(delete-file (gnus-dribble-file-name)))
(when gnus-dribble-buffer
- (save-excursion
- (set-buffer gnus-dribble-buffer)
+ (with-current-buffer gnus-dribble-buffer
(let ((auto (make-auto-save-file-name)))
(when (file-exists-p auto)
(delete-file auto))
@@ -915,14 +910,12 @@
(defun gnus-dribble-save ()
(when (and gnus-dribble-buffer
(buffer-name gnus-dribble-buffer))
- (save-excursion
- (set-buffer gnus-dribble-buffer)
+ (with-current-buffer gnus-dribble-buffer
(save-buffer))))
(defun gnus-dribble-clear ()
(when (gnus-buffer-exists-p gnus-dribble-buffer)
- (save-excursion
- (set-buffer gnus-dribble-buffer)
+ (with-current-buffer gnus-dribble-buffer
(erase-buffer)
(set-buffer-modified-p nil)
(setq buffer-saved-size (buffer-size)))))
@@ -1276,8 +1269,7 @@
(when (gnus-active group)
(gnus-group-change-level
group gnus-level-default-subscribed gnus-level-killed)))
- (save-excursion
- (set-buffer gnus-group-buffer)
+ (with-current-buffer gnus-group-buffer
;; Don't error if the group already exists. This happens when a
;; first-time user types 'F'. -- didier
(gnus-group-make-help-group t))
@@ -1820,8 +1812,7 @@
(defun gnus-parse-active ()
"Parse active info in the nntp server buffer."
- (save-excursion
- (set-buffer nntp-server-buffer)
+ (with-current-buffer nntp-server-buffer
(goto-char (point-min))
;; Parse the result we got from `gnus-request-group'.
(when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
@@ -1976,8 +1967,7 @@
(list "archive")))))
method)
(setq gnus-have-read-active-file nil)
- (save-excursion
- (set-buffer nntp-server-buffer)
+ (with-current-buffer nntp-server-buffer
(while (setq method (pop methods))
;; Only do each method once, in case the methods appear more
;; than once in this list.
@@ -2037,8 +2027,7 @@
(defun gnus-read-active-file-2 (groups method)
"Read an active file for GROUPS in METHOD using `gnus-retrieve-groups'."
(when groups
- (save-excursion
- (set-buffer nntp-server-buffer)
+ (with-current-buffer nntp-server-buffer
(gnus-check-server method)
(let ((list-type (gnus-retrieve-groups groups method)))
(cond ((not list-type)
@@ -2225,9 +2214,8 @@
;; can find there for changing the data already read -
;; i. e., reading the .newsrc file will not trash the data
;; already read (except for read articles).
- (save-excursion
(gnus-message 5 "Reading %s..." newsrc-file)
- (set-buffer (nnheader-find-file-noselect newsrc-file))
+ (with-current-buffer (nnheader-find-file-noselect newsrc-file)
(buffer-disable-undo)
(gnus-newsrc-to-gnus-format)
(kill-buffer (current-buffer))
@@ -2713,8 +2701,7 @@
(not force)
(or (not gnus-dribble-buffer)
(not (buffer-name gnus-dribble-buffer))
- (zerop (save-excursion
- (set-buffer gnus-dribble-buffer)
+ (zerop (with-current-buffer gnus-dribble-buffer
(buffer-size)))))
(gnus-message 4 "(No changes need to be saved)")
(gnus-run-hooks 'gnus-save-newsrc-hook)
@@ -2848,8 +2835,7 @@
(defun gnus-gnus-to-newsrc-format ()
;; Generate and save the .newsrc file.
- (save-excursion
- (set-buffer (create-file-buffer gnus-current-startup-file))
+ (with-current-buffer (create-file-buffer gnus-current-startup-file)
(let ((newsrc (cdr gnus-newsrc-alist))
(standard-output (current-buffer))
info ranges range method)
@@ -2915,8 +2901,7 @@
(gnus-run-hooks 'gnus-slave-mode-hook))
(defun gnus-slave-save-newsrc ()
- (save-excursion
- (set-buffer gnus-dribble-buffer)
+ (with-current-buffer gnus-dribble-buffer
(let ((slave-name
(mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
(modes (ignore-errors
@@ -2940,8 +2925,7 @@
(if (not slave-files)
() ; There are no slave files to read.
(gnus-message 7 "Reading slave newsrcs...")
- (save-excursion
- (set-buffer (gnus-get-buffer-create " *gnus slave*"))
+ (with-current-buffer (gnus-get-buffer-create " *gnus slave*")
(setq slave-files
(sort (mapcar (lambda (file)
(list (nth 5 (file-attributes file)) file))
@@ -3008,9 +2992,9 @@
(gnus-message 1 "Couldn't read newsgroups descriptions")
nil)
(t
+ (with-current-buffer nntp-server-buffer
(save-excursion
(save-restriction
- (set-buffer nntp-server-buffer)
(goto-char (point-min))
(when (or (search-forward "\n.\n" nil t)
(goto-char (point-max)))
@@ -3053,15 +3037,14 @@
(when (and str charset (featurep 'mule))
(setq str (mm-decode-coding-string str charset)))
(set group str)))
- (forward-line 1))))
+ (forward-line 1)))))
(gnus-message 5 "Reading descriptions file...done")
t))))
(defun gnus-group-get-description (group)
"Get the description of a group by sending XGTITLE to the server."
(when (gnus-request-group-description group)
- (save-excursion
- (set-buffer nntp-server-buffer)
+ (with-current-buffer nntp-server-buffer
(goto-char (point-min))
(when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
(match-string 1)))))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Suspicious code in gnus-read-descriptions-file
2005-03-22 18:51 Suspicious code in gnus-read-descriptions-file Stefan Monnier
@ 2005-03-22 21:53 ` Simon Josefsson
2005-03-22 22:28 ` David Kastrup
2005-03-22 23:17 ` Jesper Harder
1 sibling, 1 reply; 6+ messages in thread
From: Simon Josefsson @ 2005-03-22 21:53 UTC (permalink / raw)
Cc: bugs, emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> The code below looks very odd:
>
> (save-excursion
> (save-restriction
> (set-buffer nntp-server-buffer)
> (goto-char (point-min))
> (when (or (search-forward "\n.\n" nil t)
> (goto-char (point-max)))
> (beginning-of-line)
> (narrow-to-region (point-min) (point)))
>
> doing a set-buffer between the save-restriction and the narrow-to-region
> seems like a bug. How 'bout the patch below? Which turns the set-buffer
> into a with-current-buffer and moves it to before the save-excursion.
> Maybe the save-excursion could be dropped altogether?
FWIW, looks good to me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Suspicious code in gnus-read-descriptions-file
2005-03-22 21:53 ` Simon Josefsson
@ 2005-03-22 22:28 ` David Kastrup
0 siblings, 0 replies; 6+ messages in thread
From: David Kastrup @ 2005-03-22 22:28 UTC (permalink / raw)
Cc: emacs-devel, Stefan Monnier, bugs
Simon Josefsson <jas@extundo.com> writes:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> The code below looks very odd:
>>
>> (save-excursion
>> (save-restriction
>> (set-buffer nntp-server-buffer)
>> (goto-char (point-min))
>> (when (or (search-forward "\n.\n" nil t)
>> (goto-char (point-max)))
>> (beginning-of-line)
>> (narrow-to-region (point-min) (point)))
>>
>> doing a set-buffer between the save-restriction and the narrow-to-region
>> seems like a bug. How 'bout the patch below? Which turns the set-buffer
>> into a with-current-buffer and moves it to before the save-excursion.
>> Maybe the save-excursion could be dropped altogether?
You mean, the save-restriction?
> FWIW, looks good to me.
Not to me. Seems to restore the restriction in another boffer, not
nntp-server-buffer.
Even if this is for some weird reason what was intended, it should be
rearranged or well documented to stop people worrying about it.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Suspicious code in gnus-read-descriptions-file
2005-03-22 18:51 Suspicious code in gnus-read-descriptions-file Stefan Monnier
2005-03-22 21:53 ` Simon Josefsson
@ 2005-03-22 23:17 ` Jesper Harder
2005-03-23 12:53 ` Stefan
1 sibling, 1 reply; 6+ messages in thread
From: Jesper Harder @ 2005-03-22 23:17 UTC (permalink / raw)
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> (defun gnus-parse-active ()
> "Parse active info in the nntp server buffer."
> - (save-excursion
> - (set-buffer nntp-server-buffer)
> + (with-current-buffer nntp-server-buffer
> (goto-char (point-min))
Are you sure that not saving (and restoring) point in
nntp-server-buffer doesn't make a difference?
I've made the same change a lot of places in Gnus ... and if the code
in the `with-current-buffer'-form doesn't change point, it's a
no-brainer, of course.
But if point /is/ changed, I've often found it pretty hard to be
absolutely sure if saving point is actually intended and required.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Suspicious code in gnus-read-descriptions-file
2005-03-22 23:17 ` Jesper Harder
@ 2005-03-23 12:53 ` Stefan
2005-03-24 14:07 ` Jesper Harder
0 siblings, 1 reply; 6+ messages in thread
From: Stefan @ 2005-03-23 12:53 UTC (permalink / raw)
>> (defun gnus-parse-active ()
>> "Parse active info in the nntp server buffer."
>> - (save-excursion
>> - (set-buffer nntp-server-buffer)
>> + (with-current-buffer nntp-server-buffer
>> (goto-char (point-min))
> Are you sure that not saving (and restoring) point in
> nntp-server-buffer doesn't make a difference?
(save-excursion (set-buffer FOO) BAR)
saves point in the current buffer, not in FOO (unless FOO is already the
current buffer before the set-buffer call).
If you want to save point in FOO, then you need an extra save-excursion.
> But if point /is/ changed, I've often found it pretty hard to be
> absolutely sure if saving point is actually intended and required.
There's indeed the possibility that the code is usually called with
nntp-server-buffer already the current buffer and point in
nntp-server-buffer needs to be saved. In that case I'd argue that the
current code is buggy (either it should not have the set-buffer, or it
should do the save-excursion after the set-buffer).
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Suspicious code in gnus-read-descriptions-file
2005-03-23 12:53 ` Stefan
@ 2005-03-24 14:07 ` Jesper Harder
0 siblings, 0 replies; 6+ messages in thread
From: Jesper Harder @ 2005-03-24 14:07 UTC (permalink / raw)
Stefan <monnier@iro.umontreal.ca> writes:
>> But if point /is/ changed, I've often found it pretty hard to be
>> absolutely sure if saving point is actually intended and required.
>
> There's indeed the possibility that the code is usually called with
> nntp-server-buffer already the current buffer and point in
> nntp-server-buffer needs to be saved.
Yup, that's what I was thinking about. I think I've encountered a few
places like that.
It's probably not an issue in your changes ... but it's something you
should have in mind when making this type of change.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-03-24 14:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-22 18:51 Suspicious code in gnus-read-descriptions-file Stefan Monnier
2005-03-22 21:53 ` Simon Josefsson
2005-03-22 22:28 ` David Kastrup
2005-03-22 23:17 ` Jesper Harder
2005-03-23 12:53 ` Stefan
2005-03-24 14:07 ` Jesper Harder
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.