all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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.