1 ;;; gnus-group.el --- group mode commands for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
36 (defvar gnus-group-archive-directory
37 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
38 "*The address of the (ding) archives.")
40 (defvar gnus-group-recent-archive-directory
41 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
42 "*The address of the most recent (ding) articles.")
44 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
45 (defvar gnus-no-groups-message "No news is horrible news"
46 "*Message displayed by Gnus when no groups are available.")
48 (defvar gnus-keep-same-level nil
49 "*Non-nil means that the next newsgroup after the current will be on the same level.
50 When you type, for instance, `n' after reading the last article in the
51 current newsgroup, you will go to the next newsgroup. If this variable
52 is nil, the next newsgroup will be the next from the group
54 If this variable is non-nil, Gnus will either put you in the
55 next newsgroup with the same level, or, if no such newsgroup is
56 available, the next newsgroup with the lowest possible level higher
57 than the current level.
58 If this variable is `best', Gnus will make the next newsgroup the one
59 with the best level.")
61 (defvar gnus-group-goto-unread t
62 "*If non-nil, movement commands will go to the next unread and subscribed group.")
64 (defvar gnus-goto-next-group-when-activating t
65 "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group.")
67 (defvar gnus-permanently-visible-groups nil
68 "*Regexp to match groups that should always be listed in the group buffer.
69 This means that they will still be listed when there are no unread
70 articles in the groups.")
72 (defvar gnus-list-groups-with-ticked-articles t
73 "*If non-nil, list groups that have only ticked articles.
74 If nil, only list groups that have unread articles.")
76 (defvar gnus-group-default-list-level gnus-level-subscribed
77 "*Default listing level.
78 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
80 (defvar gnus-group-use-permanent-levels nil
81 "*If non-nil, once you set a level, Gnus will use this level.")
83 (defvar gnus-group-list-inactive-groups t
84 "*If non-nil, inactive groups will be listed.")
86 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
87 "*Function used for sorting the group buffer.
88 This function will be called with group info entries as the arguments
89 for the groups to be sorted. Pre-made functions include
90 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread',
91 `gnus-group-sort-by-level', `gnus-group-sort-by-score',
92 `gnus-group-sort-by-method', and `gnus-group-sort-by-rank'.
94 This variable can also be a list of sorting functions. In that case,
95 the most significant sort function should be the last function in the
98 (defvar gnus-group-line-format "%M\%S\%p\%P\%5y: %(%g%)%l\n"
99 "*Format of group lines.
100 It works along the same lines as a normal formatting string,
101 with some simple extensions.
103 %M Only marked articles (character, \"*\" or \" \")
104 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
105 %L Level of subscribedness (integer)
106 %N Number of unread articles (integer)
107 %I Number of dormant articles (integer)
108 %i Number of ticked and dormant (integer)
109 %T Number of ticked articles (integer)
110 %R Number of read articles (integer)
111 %t Total number of articles (integer)
112 %y Number of unread, unticked articles (integer)
113 %G Group name (string)
114 %g Qualified group name (string)
115 %D Group description (string)
116 %s Select method (string)
117 %o Moderated group (char, \"m\")
118 %p Process mark (char)
119 %O Moderated group (string, \"(m)\" or \"\")
120 %P Topic indentation (string)
121 %l Whether there are GroupLens predictions for this group (string)
122 %n Select from where (string)
123 %z A string that look like `<%s:%n>' if a foreign select method is used
124 %u User defined specifier. The next character in the format string should
125 be a letter. Gnus will call the function gnus-user-format-function-X,
126 where X is the letter following %u. The function will be passed the
127 current header as argument. The function should return a string, which
128 will be inserted into the buffer just like information from any other
131 Text between %( and %) will be highlighted with `gnus-mouse-face' when
132 the mouse point move inside the area. There can only be one such area.
134 Note that this format specification is not always respected. For
135 reasons of efficiency, when listing killed groups, this specification
136 is ignored altogether. If the spec is changed considerably, your
137 output may end up looking strange when listing both alive and killed
140 If you use %o or %O, reading the active file will be slower and quite
141 a bit of extra memory will be used. %D will also worsen performance.
142 Also note that if you change the format specification to include any
143 of these specs, you must probably re-start Gnus to see them go into
146 (defvar gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
147 "*The format specification for the group mode line.
148 It works along the same lines as a normal formatting string,
149 with some simple extensions:
151 %S The native news server.
152 %M The native select method.
153 %: \":\" if %S isn't \"\".")
155 (defvar gnus-group-mode-hook nil
156 "*A hook for Gnus group mode.")
158 (defvar gnus-group-catchup-group-hook nil
159 "*A hook run when catching up a group from the group buffer.")
161 (defvar gnus-group-update-group-hook nil
162 "*A hook called when updating group lines.")
164 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
165 "*A function that is called to generate the group buffer.
166 The function is called with three arguments: The first is a number;
167 all group with a level less or equal to that number should be listed,
168 if the second is non-nil, empty groups should also be displayed. If
169 the third is non-nil, it is a number. No groups with a level lower
170 than this number should be displayed.
172 The only current function implemented is `gnus-group-prepare-flat'.")
174 (defvar gnus-group-prepare-hook nil
175 "*A hook called after the group buffer has been generated.
176 If you want to modify the group buffer, you can use this hook.")
178 (defvar gnus-suspend-gnus-hook nil
179 "*A hook called when suspending (not exiting) Gnus.")
181 (defvar gnus-exit-gnus-hook nil
182 "*A hook called when exiting Gnus.")
184 (defvar gnus-after-exiting-gnus-hook nil
185 "*A hook called after exiting Gnus.")
187 (defvar gnus-group-update-hook '(gnus-group-highlight-line)
188 "*A hook called when a group line is changed.
189 The hook will not be called if `gnus-visual' is nil.
191 The default function `gnus-group-highlight-line' will
192 highlight the line according to the `gnus-group-highlight'
195 ;;; Internal variables
197 (defvar gnus-group-indentation-function nil)
198 (defvar gnus-goto-missing-group-function nil)
199 (defvar gnus-group-goto-next-group-function nil
200 "Function to override finding the next group after listing groups.")
202 (defvar gnus-group-edit-buffer nil)
204 (defvar gnus-group-line-format-alist
205 `((?M gnus-tmp-marked-mark ?c)
206 (?S gnus-tmp-subscribed ?c)
207 (?L gnus-tmp-level ?d)
208 (?N (cond ((eq number t) "*" )
212 (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
213 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
215 (?R gnus-tmp-number-of-read ?s)
216 (?t gnus-tmp-number-total ?d)
217 (?y gnus-tmp-number-of-unread ?s)
218 (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
219 (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
220 (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
221 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
222 (?g gnus-tmp-group ?s)
223 (?G gnus-tmp-qualified-group ?s)
224 (?c (gnus-short-group-name gnus-tmp-group) ?s)
225 (?D gnus-tmp-newsgroup-description ?s)
226 (?o gnus-tmp-moderated ?c)
227 (?O gnus-tmp-moderated-string ?s)
228 (?p gnus-tmp-process-marked ?c)
229 (?s gnus-tmp-news-server ?s)
230 (?n gnus-tmp-news-method ?s)
231 (?P gnus-group-indentation ?s)
232 (?l gnus-tmp-grouplens ?s)
233 (?z gnus-tmp-news-method-string ?s)
234 (?u gnus-tmp-user-defined ?s)))
236 (defvar gnus-group-mode-line-format-alist
237 `((?S gnus-tmp-news-server ?s)
238 (?M gnus-tmp-news-method ?s)
239 (?u gnus-tmp-user-defined ?s)
240 (?: gnus-tmp-colon ?s)))
242 (defvar gnus-topic-topology nil
243 "The complete topic hierarchy.")
245 (defvar gnus-topic-alist nil
246 "The complete topic-group alist.")
248 (defvar gnus-group-marked nil)
250 (defvar gnus-group-list-mode nil)
256 (defvar gnus-group-mode-map nil)
257 (put 'gnus-group-mode 'mode-class 'special)
259 (unless gnus-group-mode-map
260 (setq gnus-group-mode-map (make-keymap))
261 (suppress-keymap gnus-group-mode-map)
263 (gnus-define-keys gnus-group-mode-map
264 " " gnus-group-read-group
265 "=" gnus-group-select-group
266 "\r" gnus-group-select-group
267 "\M-\r" gnus-group-quick-select-group
268 "j" gnus-group-jump-to-group
269 "n" gnus-group-next-unread-group
270 "p" gnus-group-prev-unread-group
271 "\177" gnus-group-prev-unread-group
272 [delete] gnus-group-prev-unread-group
273 "N" gnus-group-next-group
274 "P" gnus-group-prev-group
275 "\M-n" gnus-group-next-unread-group-same-level
276 "\M-p" gnus-group-prev-unread-group-same-level
277 "," gnus-group-best-unread-group
278 "." gnus-group-first-unread-group
279 "u" gnus-group-unsubscribe-current-group
280 "U" gnus-group-unsubscribe-group
281 "c" gnus-group-catchup-current
282 "C" gnus-group-catchup-current-all
283 "l" gnus-group-list-groups
284 "L" gnus-group-list-all-groups
286 "g" gnus-group-get-new-news
287 "\M-g" gnus-group-get-new-news-this-group
288 "R" gnus-group-restart
289 "r" gnus-group-read-init-file
290 "B" gnus-group-browse-foreign-server
291 "b" gnus-group-check-bogus-groups
292 "F" gnus-find-new-newsgroups
293 "\C-c\C-d" gnus-group-describe-group
294 "\M-d" gnus-group-describe-all-groups
295 "\C-c\C-a" gnus-group-apropos
296 "\C-c\M-\C-a" gnus-group-description-apropos
297 "a" gnus-group-post-news
298 "\ek" gnus-group-edit-local-kill
299 "\eK" gnus-group-edit-global-kill
300 "\C-k" gnus-group-kill-group
301 "\C-y" gnus-group-yank-group
302 "\C-w" gnus-group-kill-region
303 "\C-x\C-t" gnus-group-transpose-groups
304 "\C-c\C-l" gnus-group-list-killed
305 "\C-c\C-x" gnus-group-expire-articles
306 "\C-c\M-\C-x" gnus-group-expire-all-groups
308 "s" gnus-group-save-newsrc
309 "z" gnus-group-suspend
310 ; "Z" gnus-group-clear-dribble
313 "?" gnus-group-describe-briefly
314 "\C-c\C-i" gnus-info-find-node
315 "\M-e" gnus-group-edit-group-method
316 "^" gnus-group-enter-server-mode
317 gnus-mouse-2 gnus-mouse-pick-group
318 "<" beginning-of-buffer
321 "\C-c\C-s" gnus-group-sort-groups
323 "\C-c\M-g" gnus-activate-all-groups
324 "\M-&" gnus-group-universal-argument
325 "#" gnus-group-mark-group
326 "\M-#" gnus-group-unmark-group)
328 (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
329 "m" gnus-group-mark-group
330 "u" gnus-group-unmark-group
331 "w" gnus-group-mark-region
332 "m" gnus-group-mark-buffer
333 "r" gnus-group-mark-regexp
334 "U" gnus-group-unmark-all-groups)
336 (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
337 "d" gnus-group-make-directory-group
338 "h" gnus-group-make-help-group
339 "a" gnus-group-make-archive-group
340 "k" gnus-group-make-kiboze-group
341 "m" gnus-group-make-group
342 "E" gnus-group-edit-group
343 "e" gnus-group-edit-group-method
344 "p" gnus-group-edit-group-parameters
345 "v" gnus-group-add-to-virtual
346 "V" gnus-group-make-empty-virtual
347 "D" gnus-group-enter-directory
348 "f" gnus-group-make-doc-group
349 "r" gnus-group-rename-group
350 "\177" gnus-group-delete-group
351 [delete] gnus-group-delete-group)
353 (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
354 "b" gnus-group-brew-soup
355 "w" gnus-soup-save-areas
356 "s" gnus-soup-send-replies
357 "p" gnus-soup-pack-packet
358 "r" nnsoup-pack-replies)
360 (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
361 "s" gnus-group-sort-groups
362 "a" gnus-group-sort-groups-by-alphabet
363 "u" gnus-group-sort-groups-by-unread
364 "l" gnus-group-sort-groups-by-level
365 "v" gnus-group-sort-groups-by-score
366 "r" gnus-group-sort-groups-by-rank
367 "m" gnus-group-sort-groups-by-method)
369 (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
370 "k" gnus-group-list-killed
371 "z" gnus-group-list-zombies
372 "s" gnus-group-list-groups
373 "u" gnus-group-list-all-groups
374 "A" gnus-group-list-active
375 "a" gnus-group-apropos
376 "d" gnus-group-description-apropos
377 "m" gnus-group-list-matching
378 "M" gnus-group-list-all-matching
379 "l" gnus-group-list-level)
381 (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
382 "f" gnus-score-flush-cache)
384 (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
385 "f" gnus-group-fetch-faq)
387 (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
388 "l" gnus-group-set-current-level
389 "t" gnus-group-unsubscribe-current-group
390 "s" gnus-group-unsubscribe-group
391 "k" gnus-group-kill-group
392 "y" gnus-group-yank-group
393 "w" gnus-group-kill-region
394 "\C-k" gnus-group-kill-level
395 "z" gnus-group-kill-all-zombies))
397 (defun gnus-group-mode ()
398 "Major mode for reading news.
400 All normal editing commands are switched off.
401 \\<gnus-group-mode-map>
402 The group buffer lists (some of) the groups available. For instance,
403 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
404 lists all zombie groups.
406 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
407 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
409 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
411 The following commands are available:
413 \\{gnus-group-mode-map}"
415 (when (and menu-bar-mode
416 (gnus-visual-p 'group-menu 'menu))
417 (gnus-group-make-menu-bar))
418 (kill-all-local-variables)
419 (gnus-simplify-mode-line)
420 (setq major-mode 'gnus-group-mode)
421 (setq mode-name "Group")
422 (gnus-group-set-mode-line)
423 (setq mode-line-process nil)
424 (use-local-map gnus-group-mode-map)
425 (buffer-disable-undo (current-buffer))
426 (setq truncate-lines t)
427 (setq buffer-read-only t)
428 (gnus-update-format-specifications nil 'group 'group-mode)
429 (gnus-update-group-mark-positions)
430 (gnus-make-local-hook 'post-command-hook)
431 (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
432 (run-hooks 'gnus-group-mode-hook))
434 (defun gnus-update-group-mark-positions ()
436 (let ((gnus-process-mark 128)
437 (gnus-group-marked '("dummy.group"))
438 (gnus-active-hashtb (make-vector 10 0)))
439 (gnus-set-active "dummy.group" '(0 . 0))
440 (gnus-set-work-buffer)
441 (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
442 (goto-char (point-min))
443 (setq gnus-group-mark-positions
444 (list (cons 'process (and (search-forward "\200" nil t)
447 (defun gnus-clear-inboxes-moved ()
448 (setq nnmail-moved-inboxes nil))
450 (defun gnus-mouse-pick-group (e)
451 "Enter the group under the mouse pointer."
454 (gnus-group-read-group nil))
456 ;; Look at LEVEL and find out what the level is really supposed to be.
457 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
458 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
459 (defun gnus-group-default-level (&optional level number-or-nil)
461 (gnus-group-use-permanent-levels
462 (or (setq gnus-group-use-permanent-levels
463 (or level (if (numberp gnus-group-use-permanent-levels)
464 gnus-group-use-permanent-levels
465 (or gnus-group-default-list-level
466 gnus-level-subscribed))))
467 gnus-group-default-list-level gnus-level-subscribed))
471 (or level gnus-group-default-list-level gnus-level-subscribed))))
473 (defun gnus-group-setup-buffer ()
474 (switch-to-buffer gnus-group-buffer)
475 (unless (eq major-mode 'gnus-group-mode)
476 (gnus-add-current-to-buffer-list)
479 (gnus-carpal-setup-buffer 'group))))
481 (defun gnus-group-list-groups (&optional level unread lowest)
482 "List newsgroups with level LEVEL or lower that have unread articles.
483 Default is all subscribed groups.
484 If argument UNREAD is non-nil, groups with no unread articles are also
486 (interactive (list (if current-prefix-arg
487 (prefix-numeric-value current-prefix-arg)
489 (gnus-group-default-level nil t)
490 gnus-group-default-list-level
491 gnus-level-subscribed))))
493 (setq level (car gnus-group-list-mode)
494 unread (cdr gnus-group-list-mode)))
495 (setq level (gnus-group-default-level level))
496 (gnus-group-setup-buffer) ;May call from out of group buffer
497 (gnus-update-format-specifications)
498 (let ((case-fold-search nil)
499 (props (text-properties-at (gnus-point-at-bol)))
500 (group (gnus-group-group-name)))
501 (set-buffer gnus-group-buffer)
502 (funcall gnus-group-prepare-function level unread lowest)
503 (if (zerop (buffer-size))
504 (gnus-message 5 gnus-no-groups-message)
505 (goto-char (point-max))
506 (when (or (not gnus-group-goto-next-group-function)
507 (not (funcall gnus-group-goto-next-group-function
510 ;; Go to the first group with unread articles.
511 (gnus-group-search-forward t)
512 ;; Find the right group to put point on. If the current group
513 ;; has disappeared in the new listing, try to find the next
514 ;; one. If no next one can be found, just leave point at the
515 ;; first newsgroup in the buffer.
516 (if (not (gnus-goto-char
518 (point-min) (point-max)
519 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
520 (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
524 (point-min) (point-max) 'gnus-group
526 (caar newsrc) gnus-active-hashtb)))))
527 (setq newsrc (cdr newsrc)))
528 (or newsrc (progn (goto-char (point-max))
529 (forward-line -1)))))))
530 ;; Adjust cursor point.
531 (gnus-group-position-point))))
533 (defun gnus-group-list-level (level &optional all)
534 "List groups on LEVEL.
535 If ALL (the prefix), also list groups that have no unread articles."
536 (interactive "nList groups on level: \nP")
537 (gnus-group-list-groups level all level))
539 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
540 "List all newsgroups with unread articles of level LEVEL or lower.
541 If ALL is non-nil, list groups that have no unread articles.
542 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
543 If REGEXP, only list groups matching REGEXP."
544 (set-buffer gnus-group-buffer)
545 (let ((buffer-read-only nil)
546 (newsrc (cdr gnus-newsrc-alist))
547 (lowest (or lowest 1))
548 info clevel unread group params)
550 (if (< lowest gnus-level-zombie)
551 ;; List living groups.
553 (setq info (car newsrc)
554 group (gnus-info-group info)
555 params (gnus-info-params info)
557 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
558 (and unread ; This group might be bogus
560 (string-match regexp group))
561 (<= (setq clevel (gnus-info-level info)) level)
563 (or all ; We list all groups?
564 (if (eq unread t) ; Unactivated?
565 gnus-group-list-inactive-groups ; We list unactivated
566 (> unread 0)) ; We list groups with unread articles
567 (and gnus-list-groups-with-ticked-articles
568 (cdr (assq 'tick (gnus-info-marks info))))
569 ; And groups with tickeds
570 ;; Check for permanent visibility.
571 (and gnus-permanently-visible-groups
572 (string-match gnus-permanently-visible-groups
574 (memq 'visible params)
575 (cdr (assq 'visible params)))
576 (gnus-group-insert-group-line
577 group (gnus-info-level info)
578 (gnus-info-marks info) unread (gnus-info-method info)))))
581 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
582 (gnus-group-prepare-flat-list-dead
583 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
586 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
587 (gnus-group-prepare-flat-list-dead
588 (setq gnus-killed-list (sort gnus-killed-list 'string<))
589 gnus-level-killed ?K regexp))
591 (gnus-group-set-mode-line)
592 (setq gnus-group-list-mode (cons level all))
593 (run-hooks 'gnus-group-prepare-hook)))
595 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
596 ;; List zombies and killed lists somewhat faster, which was
597 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
598 ;; this by ignoring the group format specification altogether.
601 ;; This loop is used when listing groups that match some
604 (setq group (pop groups))
605 (when (string-match regexp group)
606 (gnus-add-text-properties
607 (point) (prog1 (1+ (point))
608 (insert " " mark " *: " group "\n"))
609 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
611 'gnus-level level))))
612 ;; This loop is used when listing all groups.
614 (gnus-add-text-properties
615 (point) (prog1 (1+ (point))
616 (insert " " mark " *: "
617 (setq group (pop groups)) "\n"))
618 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
620 'gnus-level level))))))
622 (defun gnus-group-update-group-line ()
623 "Update the current line in the group buffer."
624 (let* ((buffer-read-only nil)
625 (group (gnus-group-group-name))
626 (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
627 gnus-group-indentation)
630 (not (gnus-ephemeral-group-p group))
632 (concat "(gnus-group-set-info '"
633 (prin1-to-string (nth 2 entry)) ")")))
634 (setq gnus-group-indentation (gnus-group-group-indentation))
636 (gnus-group-insert-group-line-info group)
638 (gnus-group-position-point))))
640 (defun gnus-group-insert-group-line-info (group)
641 "Insert GROUP on the current line."
642 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
646 ;; (Un)subscribed group.
647 (setq info (nth 2 entry))
648 (gnus-group-insert-group-line
649 group (gnus-info-level info) (gnus-info-marks info)
650 (or (car entry) t) (gnus-info-method info)))
651 ;; This group is dead.
652 (gnus-group-insert-group-line
654 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
656 (if (setq active (gnus-active group))
657 (- (1+ (cdr active)) (car active)) 0)
660 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
661 gnus-tmp-marked number
663 "Insert a group line in the group buffer."
664 (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
665 (gnus-tmp-number-total
667 (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
669 (gnus-tmp-number-of-unread
670 (if (numberp number) (int-to-string (max 0 number))
672 (gnus-tmp-number-of-read
674 (int-to-string (max 0 (- gnus-tmp-number-total number)))
677 (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
678 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
679 ((= gnus-tmp-level gnus-level-zombie) ?Z)
681 (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
682 (gnus-tmp-newsgroup-description
683 (if gnus-description-hashtb
684 (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
687 (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
688 (gnus-tmp-moderated-string
689 (if (eq gnus-tmp-moderated ?m) "(m)" ""))
691 (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
692 (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
693 (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
694 (gnus-tmp-news-method-string
696 (format "(%s:%s)" (car gnus-tmp-method)
697 (cadr gnus-tmp-method)) ""))
698 (gnus-tmp-marked-mark
699 (if (and (numberp number)
701 (cdr (assq 'tick gnus-tmp-marked)))
703 (gnus-tmp-process-marked
704 (if (member gnus-tmp-group gnus-group-marked)
705 gnus-process-mark ? ))
707 (or (and gnus-use-grouplens
708 (bbb-grouplens-group-p gnus-tmp-group))
710 (buffer-read-only nil)
711 header gnus-tmp-header) ; passed as parameter to user-funcs.
713 (gnus-add-text-properties
717 (eval gnus-group-line-format-spec))
718 `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
719 gnus-unread ,(if (numberp number)
720 (string-to-int gnus-tmp-number-of-unread)
722 gnus-marked ,gnus-tmp-marked-mark
723 gnus-indentation ,gnus-group-indentation
724 gnus-level ,gnus-tmp-level))
725 (when (inline (gnus-visual-p 'group-highlight 'highlight))
727 (run-hooks 'gnus-group-update-hook)
729 ;; Allow XEmacs to remove front-sticky text properties.
730 (gnus-group-remove-excess-properties)))
732 (defun gnus-group-update-group (group &optional visible-only)
733 "Update all lines where GROUP appear.
734 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
737 (set-buffer gnus-group-buffer)
738 ;; The buffer may be narrowed.
741 (let ((ident (gnus-intern-safe group gnus-active-hashtb))
743 found buffer-read-only)
744 ;; Enter the current status into the dribble buffer.
745 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
746 (if (and entry (not (gnus-ephemeral-group-p group)))
748 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
750 ;; Find all group instances. If topics are in use, each group
751 ;; may be listed in more than once.
752 (while (setq loc (text-property-any
753 loc (point-max) 'gnus-group ident))
756 (let ((gnus-group-indentation (gnus-group-group-indentation)))
758 (gnus-group-insert-group-line-info group)
761 (run-hooks 'gnus-group-update-group-hook)))
763 (unless (or found visible-only)
764 ;; No such line in the buffer, find out where it's supposed to
765 ;; go, and insert it there (or at the end of the buffer).
766 (if gnus-goto-missing-group-function
767 (funcall gnus-goto-missing-group-function group)
768 (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
769 (while (and entry (car entry)
773 (point-min) (point-max)
774 'gnus-group (gnus-intern-safe
775 (caar entry) gnus-active-hashtb)))))
776 (setq entry (cdr entry)))
777 (or entry (goto-char (point-max)))))
778 ;; Finally insert the line.
779 (let ((gnus-group-indentation (gnus-group-group-indentation)))
780 (gnus-group-insert-group-line-info group)
783 (run-hooks 'gnus-group-update-group-hook))))
784 (gnus-group-set-mode-line)))))
786 (defun gnus-group-set-mode-line ()
787 "Update the mode line in the group buffer."
788 (when (memq 'group gnus-updated-mode-lines)
789 ;; Yes, we want to keep this mode line updated.
791 (set-buffer gnus-group-buffer)
792 (let* ((gformat (or gnus-group-mode-line-format-spec
793 (setq gnus-group-mode-line-format-spec
795 gnus-group-mode-line-format
796 gnus-group-mode-line-format-alist))))
797 (gnus-tmp-news-server (cadr gnus-select-method))
798 (gnus-tmp-news-method (car gnus-select-method))
799 (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
801 gnus-tmp-header ;Dummy binding for user-defined formats
802 ;; Get the resulting string.
804 (and gnus-dribble-buffer
805 (buffer-name gnus-dribble-buffer)
806 (buffer-modified-p gnus-dribble-buffer)
808 (set-buffer gnus-dribble-buffer)
809 (not (zerop (buffer-size))))))
810 (mode-string (eval gformat)))
811 ;; Say whether the dribble buffer has been modified.
812 (setq mode-line-modified
813 (if modified "---*- " "----- "))
814 ;; If the line is too long, we chop it off.
815 (when (> (length mode-string) max-len)
816 (setq mode-string (substring mode-string 0 (- max-len 4))))
818 (setq mode-line-buffer-identification
819 (gnus-mode-line-buffer-identification
821 (set-buffer-modified-p modified))))))
823 (defun gnus-group-group-name ()
824 "Get the name of the newsgroup on the current line."
825 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
826 (and group (symbol-name group))))
828 (defun gnus-group-group-level ()
829 "Get the level of the newsgroup on the current line."
830 (get-text-property (gnus-point-at-bol) 'gnus-level))
832 (defun gnus-group-group-indentation ()
833 "Get the indentation of the newsgroup on the current line."
834 (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
835 (and gnus-group-indentation-function
836 (funcall gnus-group-indentation-function))
839 (defun gnus-group-group-unread ()
840 "Get the number of unread articles of the newsgroup on the current line."
841 (get-text-property (gnus-point-at-bol) 'gnus-unread))
843 (defun gnus-group-search-forward (&optional backward all level first-too)
844 "Find the next newsgroup with unread articles.
845 If BACKWARD is non-nil, find the previous newsgroup instead.
846 If ALL is non-nil, just find any newsgroup.
847 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
849 If FIRST-TOO, the current line is also eligible as a target."
850 (let ((way (if backward -1 1))
851 (low gnus-level-killed)
854 (if (and backward (progn (beginning-of-line)) (bobp))
856 (or first-too (forward-line way))
864 (get-text-property (point) 'gnus-unread)))
865 (and (numberp unread) (> unread 0)))
866 (setq lev (get-text-property (point)
868 (<= lev gnus-level-subscribed)))
870 (and (setq lev (get-text-property (point)
879 (zerop (forward-line way)))))
881 (progn (gnus-group-position-point) t)
882 (goto-char (or pos beg))
885 ;;; Gnus group mode commands
889 (defun gnus-group-mark-group (n &optional unmark no-advance)
890 "Mark the current group."
892 (let ((buffer-read-only nil)
896 (when (setq group (gnus-group-group-name))
900 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
905 (setq gnus-group-marked (delete group gnus-group-marked)))
907 (setq gnus-group-marked
908 (cons group (delete group gnus-group-marked)))))
909 (or no-advance (gnus-group-next-group 1))
911 (gnus-summary-position-point)
914 (defun gnus-group-unmark-group (n)
915 "Remove the mark from the current group."
917 (gnus-group-mark-group n 'unmark)
918 (gnus-group-position-point))
920 (defun gnus-group-unmark-all-groups ()
923 (let ((groups gnus-group-marked))
926 (gnus-group-remove-mark (pop groups)))))
927 (gnus-group-position-point))
929 (defun gnus-group-mark-region (unmark beg end)
930 "Mark all groups between point and mark.
931 If UNMARK, remove the mark instead."
933 (let ((num (count-lines beg end)))
936 (- num (gnus-group-mark-group num unmark)))))
938 (defun gnus-group-mark-buffer (&optional unmark)
939 "Mark all groups in the buffer.
940 If UNMARK, remove the mark instead."
942 (gnus-group-mark-region unmark (point-min) (point-max)))
944 (defun gnus-group-mark-regexp (regexp)
945 "Mark all groups that match some regexp."
946 (interactive "sMark (regexp): ")
947 (let ((alist (cdr gnus-newsrc-alist))
950 (when (string-match regexp (setq group (gnus-info-group (pop alist))))
951 (gnus-group-set-mark group))))
952 (gnus-group-position-point))
954 (defun gnus-group-remove-mark (group)
955 "Remove the process mark from GROUP and move point there.
956 Return nil if the group isn't displayed."
957 (if (gnus-group-goto-group group)
959 (gnus-group-mark-group 1 'unmark t)
961 (setq gnus-group-marked
962 (delete group gnus-group-marked))
965 (defun gnus-group-set-mark (group)
966 "Set the process mark on GROUP."
967 (if (gnus-group-goto-group group)
969 (gnus-group-mark-group 1 nil t))
970 (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
972 (defun gnus-group-universal-argument (arg &optional groups func)
973 "Perform any command on all groups accoring to the process/prefix convention."
975 (let ((groups (or groups (gnus-group-process-prefix arg)))
977 (if (eq (setq func (or func
980 (substitute-command-keys
981 "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
983 (gnus-error 1 "Undefined key")
985 (gnus-group-remove-mark (setq group (pop groups)))
986 (command-execute func))))
987 (gnus-group-position-point))
989 (defun gnus-group-process-prefix (n)
990 "Return a list of groups to work on.
991 Take into consideration N (the prefix) and the list of marked groups."
994 (setq n (prefix-numeric-value n))
995 ;; There is a prefix, so we return a list of the N next
997 (let ((way (if (< n 0) -1 1))
1002 (setq group (gnus-group-group-name)))
1003 (setq groups (cons group groups))
1005 (gnus-group-next-group way)))
1007 ((and (boundp 'transient-mark-mode)
1009 (boundp 'mark-active)
1011 ;; Work on the region between point and mark.
1012 (let ((max (max (point) (mark)))
1015 (goto-char (min (point) (mark)))
1018 (push (gnus-group-group-name) groups)
1019 (zerop (gnus-group-next-group 1))
1021 (nreverse groups))))
1023 ;; No prefix, but a list of marked articles.
1024 (reverse gnus-group-marked))
1026 ;; Neither marked articles or a prefix, so we return the
1028 (let ((group (gnus-group-group-name)))
1029 (and group (list group))))))
1031 ;; Selecting groups.
1033 (defun gnus-group-read-group (&optional all no-article group)
1034 "Read news in this newsgroup.
1035 If the prefix argument ALL is non-nil, already read articles become
1036 readable. IF ALL is a number, fetch this number of articles. If the
1037 optional argument NO-ARTICLE is non-nil, no article will be
1038 auto-selected upon group entry. If GROUP is non-nil, fetch that
1041 (let ((group (or group (gnus-group-group-name)))
1042 number active marked entry)
1043 (or group (error "No group on current line"))
1044 (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash
1045 group gnus-newsrc-hashtb)))))
1046 ;; This group might be a dead group. In that case we have to get
1047 ;; the number of unread articles from `gnus-active-hashtb'.
1049 (cond ((numberp all) all)
1051 ((setq active (gnus-active group))
1052 (- (1+ (cdr active)) (car active)))))
1053 (gnus-summary-read-group
1054 group (or all (and (numberp number)
1055 (zerop (+ number (length (cdr (assq 'tick marked)))
1056 (length (cdr (assq 'dormant marked)))))))
1059 (defun gnus-group-select-group (&optional all)
1060 "Select this newsgroup.
1061 No article is selected automatically.
1062 If ALL is non-nil, already read articles become readable.
1063 If ALL is a number, fetch this number of articles."
1065 (gnus-group-read-group all t))
1067 (defun gnus-group-quick-select-group (&optional all)
1068 "Select the current group \"quickly\".
1069 This means that no highlighting or scoring will be performed."
1072 gnus-score-find-score-files-function
1073 gnus-apply-kill-hook
1074 gnus-summary-expunge-below)
1075 (gnus-group-read-group all t)))
1077 (defun gnus-group-visible-select-group (&optional all)
1078 "Select the current group without hiding any articles."
1080 (let ((gnus-inhibit-limiting t))
1081 (gnus-group-read-group all t)))
1084 (defun gnus-fetch-group (group)
1085 "Start Gnus if necessary and enter GROUP.
1086 Returns whether the fetching was successful or not."
1087 (interactive "sGroup name: ")
1088 (or (get-buffer gnus-group-buffer)
1090 (gnus-group-read-group nil nil group))
1092 ;; Enter a group that is not in the group buffer. Non-nil is returned
1093 ;; if selection was successful.
1094 (defun gnus-group-read-ephemeral-group
1095 (group method &optional activate quit-config)
1096 (let ((group (if (gnus-group-foreign-p group) group
1097 (gnus-group-prefixed-name group method))))
1100 `(t nil (,group ,gnus-level-default-subscribed nil nil ,method
1101 ((quit-config . ,(if quit-config quit-config
1102 (cons (current-buffer) 'summary))))))
1104 (set-buffer gnus-group-buffer)
1105 (or (gnus-check-server method)
1106 (error "Unable to contact server: %s" (gnus-status-message method)))
1107 (if activate (or (gnus-request-group group)
1108 (error "Couldn't request group")))
1110 (gnus-group-read-group t t group)
1114 (defun gnus-group-jump-to-group (group)
1115 "Jump to newsgroup GROUP."
1117 (list (completing-read
1118 "Group: " gnus-active-hashtb nil
1119 (gnus-read-active-file-p)
1121 'gnus-group-history)))
1123 (when (equal group "")
1124 (error "Empty group name"))
1126 (when (string-match "[\000-\032]" group)
1127 (error "Control characters in group: %s" group))
1129 (let ((b (text-property-any
1130 (point-min) (point-max)
1131 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
1132 (unless (gnus-ephemeral-group-p group)
1134 ;; Either go to the line in the group buffer...
1136 ;; ... or insert the line.
1138 t ;; Don't activate group.
1140 (gnus-activate-group group)
1141 (error "%s error: %s" group (gnus-status-message group)))
1143 (gnus-group-update-group group)
1144 (goto-char (text-property-any
1145 (point-min) (point-max)
1146 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))
1147 ;; Adjust cursor point.
1148 (gnus-group-position-point)))
1150 (defun gnus-group-goto-group (group)
1151 "Goto to newsgroup GROUP."
1153 ;; It's quite likely that we are on the right line, so
1154 ;; we check the current line first.
1156 (if (eq (get-text-property (point) 'gnus-group)
1157 (gnus-intern-safe group gnus-active-hashtb))
1159 ;; Search through the entire buffer.
1160 (let ((b (text-property-any
1161 (point-min) (point-max)
1162 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
1166 (defun gnus-group-next-group (n &optional silent)
1167 "Go to next N'th newsgroup.
1168 If N is negative, search backward instead.
1169 Returns the difference between N and the number of skips actually
1172 (gnus-group-next-unread-group n t nil silent))
1174 (defun gnus-group-next-unread-group (n &optional all level silent)
1175 "Go to next N'th unread newsgroup.
1176 If N is negative, search backward instead.
1177 If ALL is non-nil, choose any newsgroup, unread or not.
1178 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1179 such group can be found, the next group with a level higher than
1181 Returns the difference between N and the number of skips actually
1184 (let ((backward (< n 0))
1187 (gnus-group-search-forward
1188 backward (or (not gnus-group-goto-unread) all) level))
1192 (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1193 (if level " on this level or higher" "")))
1196 (defun gnus-group-prev-group (n)
1197 "Go to previous N'th newsgroup.
1198 Returns the difference between N and the number of skips actually
1201 (gnus-group-next-unread-group (- n) t))
1203 (defun gnus-group-prev-unread-group (n)
1204 "Go to previous N'th unread newsgroup.
1205 Returns the difference between N and the number of skips actually
1208 (gnus-group-next-unread-group (- n)))
1210 (defun gnus-group-next-unread-group-same-level (n)
1211 "Go to next N'th unread newsgroup on the same level.
1212 If N is negative, search backward instead.
1213 Returns the difference between N and the number of skips actually
1216 (gnus-group-next-unread-group n t (gnus-group-group-level))
1217 (gnus-group-position-point))
1219 (defun gnus-group-prev-unread-group-same-level (n)
1220 "Go to next N'th unread newsgroup on the same level.
1221 Returns the difference between N and the number of skips actually
1224 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1225 (gnus-group-position-point))
1227 (defun gnus-group-best-unread-group (&optional exclude-group)
1228 "Go to the group with the highest level.
1229 If EXCLUDE-GROUP, do not go to that group."
1231 (goto-char (point-min))
1235 (setq unread (get-text-property (point) 'gnus-unread))
1236 (if (and (numberp unread) (> unread 0))
1238 (if (and (get-text-property (point) 'gnus-level)
1239 (< (get-text-property (point) 'gnus-level) best)
1240 (or (not exclude-group)
1241 (not (equal exclude-group (gnus-group-group-name)))))
1243 (setq best (get-text-property (point) 'gnus-level))
1244 (setq best-point (point))))))
1246 (if best-point (goto-char best-point))
1247 (gnus-summary-position-point)
1248 (and best-point (gnus-group-group-name))))
1250 (defun gnus-group-first-unread-group ()
1251 "Go to the first group with unread articles."
1254 (let ((opoint (point))
1256 (goto-char (point-min))
1257 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1258 (and (numberp unread) ; Not a topic.
1259 (not (zerop unread))) ; Has unread articles.
1260 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1263 nil)) ; Not success.
1264 (gnus-group-position-point)))
1266 (defun gnus-group-enter-server-mode ()
1267 "Jump to the server buffer."
1269 (gnus-enter-server-buffer))
1271 (defun gnus-group-make-group (name &optional method address)
1272 "Add a new newsgroup.
1273 The user will be prompted for a NAME, for a select METHOD, and an
1277 (read-string "Group name: ")
1280 "Method: " (append gnus-valid-select-methods gnus-server-alist)
1281 nil t nil 'gnus-method-history)))
1284 (setq method gnus-select-method))
1285 ((assoc method gnus-valid-select-methods)
1287 (if (memq 'prompt-address
1288 (assoc method gnus-valid-select-methods))
1289 (read-string "Address: ")
1291 ((assoc method gnus-server-alist)
1294 (list method ""))))))
1296 (let* ((meth (when (and method
1297 (not (gnus-server-equal method gnus-select-method)))
1298 (if address (list (intern method) address)
1300 (nname (if method (gnus-group-prefixed-name name meth) name))
1302 (when (gnus-gethash nname gnus-newsrc-hashtb)
1303 (error "Group %s already exists" nname))
1304 ;; Subscribe to the new group.
1305 (gnus-group-change-level
1306 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1307 gnus-level-default-subscribed gnus-level-killed
1308 (and (gnus-group-group-name)
1309 (gnus-gethash (gnus-group-group-name)
1310 gnus-newsrc-hashtb))
1313 (gnus-set-active nname (cons 1 0))
1314 (or (gnus-ephemeral-group-p name)
1316 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
1318 (gnus-group-insert-group-line-info nname)
1320 (gnus-group-position-point)
1322 ;; Load the backend and try to make the backend create
1323 ;; the group as well.
1324 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
1326 gnus-valid-select-methods)
1328 (gnus-check-server meth)
1329 (and (gnus-check-backend-function 'request-create-group nname)
1330 (gnus-request-create-group nname))
1333 (defun gnus-group-delete-group (group &optional force)
1334 "Delete the current group. Only meaningful with mail groups.
1335 If FORCE (the prefix) is non-nil, all the articles in the group will
1336 be deleted. This is \"deleted\" as in \"removed forever from the face
1337 of the Earth\". There is no undo. The user will be prompted before
1338 doing the deletion."
1340 (list (gnus-group-group-name)
1341 current-prefix-arg))
1342 (or group (error "No group to rename"))
1343 (or (gnus-check-backend-function 'request-delete-group group)
1344 (error "This backend does not support group deletion"))
1346 (if (not (gnus-yes-or-no-p
1348 "Do you really want to delete %s%s? "
1349 group (if force " and all its contents" ""))))
1351 (gnus-message 6 "Deleting group %s..." group)
1352 (if (not (gnus-request-delete-group group force))
1353 (gnus-error 3 "Couldn't delete group %s" group)
1354 (gnus-message 6 "Deleting group %s...done" group)
1355 (gnus-group-goto-group group)
1356 (gnus-group-kill-group 1 t)
1357 (gnus-sethash group nil gnus-active-hashtb)
1359 (gnus-group-position-point)))
1361 (defun gnus-group-rename-group (group new-name)
1364 (gnus-group-group-name)
1366 (or (gnus-check-backend-function
1367 'request-rename-group (gnus-group-group-name))
1368 (error "This backend does not support renaming groups"))
1369 (read-string "New group name: "))))
1371 (or (gnus-check-backend-function 'request-rename-group group)
1372 (error "This backend does not support renaming groups"))
1374 (or group (error "No group to rename"))
1375 (and (string-match "^[ \t]*$" new-name)
1376 (error "Not a valid group name"))
1378 ;; We find the proper prefixed name.
1380 (if (equal (gnus-group-real-name new-name) new-name)
1384 (gnus-group-prefixed-name
1385 (gnus-group-real-name new-name)
1386 (gnus-info-method (gnus-get-info group)))))
1388 (gnus-message 6 "Renaming group %s to %s..." group new-name)
1390 (if (not (gnus-request-rename-group group new-name))
1391 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
1392 ;; We rename the group internally by killing it...
1393 (gnus-group-goto-group group)
1394 (gnus-group-kill-group)
1395 ;; ... changing its name ...
1396 (setcar (cdar gnus-list-of-killed-groups) new-name)
1397 ;; ... and then yanking it. Magic!
1398 (gnus-group-yank-group)
1399 (gnus-set-active new-name (gnus-active group))
1400 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
1402 (gnus-group-position-point)))
1404 (defun gnus-group-edit-group (group &optional part)
1405 "Edit the group on the current line."
1406 (interactive (list (gnus-group-group-name)))
1407 (let* ((part (or part 'info))
1408 (done-func `(lambda ()
1409 "Exit editing mode and update the information."
1411 (gnus-group-edit-group-done ',part ,group)))
1412 (winconf (current-window-configuration))
1414 (or group (error "No group on current line"))
1415 (or (setq info (gnus-get-info group))
1416 (error "Killed group; can't be edited"))
1417 (set-buffer (setq gnus-group-edit-buffer
1419 (format "*Gnus edit %s*" group))))
1420 (gnus-configure-windows 'edit-group)
1421 (gnus-add-current-to-buffer-list)
1423 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1424 (use-local-map (copy-keymap emacs-lisp-mode-map))
1425 (local-set-key "\C-c\C-c" done-func)
1426 (make-local-variable 'gnus-prev-winconf)
1427 (setq gnus-prev-winconf winconf)
1432 ";; Type `C-c C-c' after editing the select method.\n\n")
1434 ";; Type `C-c C-c' after editing the group parameters.\n\n")
1436 ";; Type `C-c C-c' after editing the group info.\n\n")))
1439 (cond ((eq part 'method)
1440 (or (gnus-info-method info) "native"))
1442 (gnus-info-params info))
1446 (defun gnus-group-edit-group-method (group)
1447 "Edit the select method of GROUP."
1448 (interactive (list (gnus-group-group-name)))
1449 (gnus-group-edit-group group 'method))
1451 (defun gnus-group-edit-group-parameters (group)
1452 "Edit the group parameters of GROUP."
1453 (interactive (list (gnus-group-group-name)))
1454 (gnus-group-edit-group group 'params))
1456 (defun gnus-group-edit-group-done (part group)
1457 "Get info from buffer, update variables and jump to the group buffer."
1458 (when (and gnus-group-edit-buffer
1459 (buffer-name gnus-group-edit-buffer))
1460 (set-buffer gnus-group-edit-buffer)
1461 (goto-char (point-min))
1462 (let* ((form (read (current-buffer)))
1463 (winconf gnus-prev-winconf)
1464 (method (cond ((eq part 'info) (nth 4 form))
1465 ((eq part 'method) form)
1467 (info (cond ((eq part 'info) form)
1468 ((eq part 'method) (gnus-get-info group))
1471 (if (or (not method)
1473 gnus-select-method method))
1474 (gnus-group-real-name (car info))
1475 (gnus-group-prefixed-name
1476 (gnus-group-real-name (car info)) method))
1478 (when (and new-group
1479 (not (equal new-group group)))
1480 (when (gnus-group-goto-group group)
1481 (gnus-group-kill-group 1))
1482 (gnus-activate-group new-group))
1484 (if (and info new-group)
1486 (setq info (gnus-copy-sequence info))
1487 (setcar info new-group)
1488 (unless (gnus-server-equal method "native")
1489 (unless (nthcdr 3 info)
1490 (nconc info (list nil nil)))
1491 (unless (nthcdr 4 info)
1492 (nconc info (list nil)))
1493 (gnus-info-set-method info method))
1494 (gnus-group-set-info info))
1495 (gnus-group-set-info form (or new-group group) part))
1496 (kill-buffer (current-buffer))
1497 (and winconf (set-window-configuration winconf))
1498 (set-buffer gnus-group-buffer)
1499 (gnus-group-update-group (or new-group group))
1500 (gnus-group-position-point))))
1502 (defun gnus-group-make-help-group ()
1503 "Create the Gnus documentation group."
1505 (let ((path load-path)
1506 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
1508 (and (gnus-gethash name gnus-newsrc-hashtb)
1509 (error "Documentation group already exists"))
1511 (setq dir (file-name-as-directory (expand-file-name (pop path)))
1513 (when (or (file-exists-p (setq file (concat dir "gnus-tut.txt")))
1515 (setq file (concat (file-name-directory
1516 (directory-file-name dir))
1517 "etc/gnus-tut.txt"))))
1520 (gnus-message 1 "Couldn't find doc group")
1521 (gnus-group-make-group
1522 (gnus-group-real-name name)
1523 (list 'nndoc "gnus-help"
1524 (list 'nndoc-address file)
1525 (list 'nndoc-article-type 'mbox)))))
1526 (gnus-group-position-point))
1528 (defun gnus-group-make-doc-group (file type)
1529 "Create a group that uses a single file as the source."
1531 (list (read-file-name "File name: ")
1532 (and current-prefix-arg 'ask)))
1533 (when (eq type 'ask)
1538 "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: "
1540 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
1541 ((= char ?b) 'babyl)
1542 ((= char ?d) 'digest)
1543 ((= char ?f) 'forward)
1545 (t (setq err (format "%c unknown. " char))
1548 (let* ((file (expand-file-name file))
1549 (name (gnus-generate-new-group-name
1550 (gnus-group-prefixed-name
1551 (file-name-nondirectory file) '(nndoc "")))))
1552 (gnus-group-make-group
1553 (gnus-group-real-name name)
1554 (list 'nndoc (file-name-nondirectory file)
1555 (list 'nndoc-address file)
1556 (list 'nndoc-article-type (or type 'guess))))))
1558 (defun gnus-group-make-archive-group (&optional all)
1559 "Create the (ding) Gnus archive group of the most recent articles.
1560 Given a prefix, create a full group."
1562 (let ((group (gnus-group-prefixed-name
1563 (if all "ding.archives" "ding.recent") '(nndir ""))))
1564 (when (gnus-gethash group gnus-newsrc-hashtb)
1565 (error "Archive group already exists"))
1566 (gnus-group-make-group
1567 (gnus-group-real-name group)
1568 (list 'nndir (if all "hpc" "edu")
1569 (list 'nndir-directory
1570 (if all gnus-group-archive-directory
1571 gnus-group-recent-archive-directory))))
1572 (gnus-group-add-parameter group (cons 'to-address "ding@ifi.uio.no"))))
1574 (defun gnus-group-make-directory-group (dir)
1575 "Create an nndir group.
1576 The user will be prompted for a directory. The contents of this
1577 directory will be used as a newsgroup. The directory should contain
1578 mail messages or news articles in files that have numeric names."
1580 (list (read-file-name "Create group from directory: ")))
1581 (or (file-exists-p dir) (error "No such directory"))
1582 (or (file-directory-p dir) (error "Not a directory"))
1586 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
1588 (gnus-group-prefixed-name
1589 (concat (file-name-as-directory (directory-file-name dir))
1592 (setq ext (format "<%d>" (setq i (1+ i)))))
1593 (gnus-group-make-group
1594 (gnus-group-real-name group)
1595 (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
1597 (defun gnus-group-make-kiboze-group (group address scores)
1598 "Create an nnkiboze group.
1599 The user will be prompted for a name, a regexp to match groups, and
1600 score file entries for articles to include in the group."
1603 (read-string "nnkiboze group name: ")
1604 (read-string "Source groups (regexp): ")
1605 (let ((headers (mapcar (lambda (group) (list group))
1606 '("subject" "from" "number" "date" "message-id"
1607 "references" "chars" "lines" "xref"
1608 "followup" "all" "body" "head")))
1609 scores header regexp regexps)
1610 (while (not (equal "" (setq header (completing-read
1611 "Match on header: " headers nil t))))
1613 (while (not (equal "" (setq regexp (read-string
1614 (format "Match on %s (string): "
1616 (setq regexps (cons (list regexp nil nil 'r) regexps)))
1617 (setq scores (cons (cons header regexps) scores)))
1619 (gnus-group-make-group group "nnkiboze" address)
1620 (nnheader-temp-write (gnus-score-file-name (concat "nnkiboze:" group))
1621 (let (emacs-lisp-mode-hook)
1622 (pp scores (current-buffer)))))
1624 (defun gnus-group-add-to-virtual (n vgroup)
1625 "Add the current group to a virtual group."
1627 (list current-prefix-arg
1628 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
1630 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
1631 (error "%s is not an nnvirtual group" vgroup))
1632 (let* ((groups (gnus-group-process-prefix n))
1633 (method (gnus-info-method (gnus-get-info vgroup))))
1634 (setcar (cdr method)
1636 (nth 1 method) "\\|"
1639 (gnus-group-remove-mark s)
1640 (concat "\\(^" (regexp-quote s) "$\\)"))
1642 (gnus-group-position-point))
1644 (defun gnus-group-make-empty-virtual (group)
1645 "Create a new, fresh, empty virtual group."
1646 (interactive "sCreate new, empty virtual group: ")
1647 (let* ((method (list 'nnvirtual "^$"))
1648 (pgroup (gnus-group-prefixed-name group method)))
1649 ;; Check whether it exists already.
1650 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
1651 (error "Group %s already exists." pgroup))
1652 ;; Subscribe the new group after the group on the current line.
1653 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
1654 (gnus-group-update-group pgroup)
1656 (gnus-group-position-point)))
1658 (defun gnus-group-enter-directory (dir)
1659 "Enter an ephemeral nneething group."
1660 (interactive "DDirectory to read: ")
1661 (let* ((method (list 'nneething dir))
1662 (leaf (gnus-group-prefixed-name
1663 (file-name-nondirectory (directory-file-name dir))
1665 (name (gnus-generate-new-group-name leaf)))
1666 (let ((nneething-read-only t))
1667 (or (gnus-group-read-ephemeral-group
1669 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
1671 (error "Couldn't enter %s" dir)))))
1673 ;; Group sorting commands
1674 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
1676 (defun gnus-group-sort-groups (func &optional reverse)
1677 "Sort the group buffer according to FUNC.
1678 If REVERSE, reverse the sorting order."
1679 (interactive (list gnus-group-sort-function
1680 current-prefix-arg))
1682 ((not (listp func)) func)
1684 ((= 1 (length func)) (car func))
1686 ,(gnus-make-sort-function
1687 (reverse func)))))))
1688 ;; We peel off the dummy group from the alist.
1690 (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group")
1691 (pop gnus-newsrc-alist))
1693 (setq gnus-newsrc-alist
1694 (sort gnus-newsrc-alist func))
1696 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
1697 ;; Regenerate the hash table.
1698 (gnus-make-hashtable-from-newsrc-alist)
1699 (gnus-group-list-groups))))
1701 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
1702 "Sort the group buffer alphabetically by group name.
1703 If REVERSE, sort in reverse order."
1705 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
1707 (defun gnus-group-sort-groups-by-unread (&optional reverse)
1708 "Sort the group buffer by number of unread articles.
1709 If REVERSE, sort in reverse order."
1711 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
1713 (defun gnus-group-sort-groups-by-level (&optional reverse)
1714 "Sort the group buffer by group level.
1715 If REVERSE, sort in reverse order."
1717 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
1719 (defun gnus-group-sort-groups-by-score (&optional reverse)
1720 "Sort the group buffer by group score.
1721 If REVERSE, sort in reverse order."
1723 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
1725 (defun gnus-group-sort-groups-by-rank (&optional reverse)
1726 "Sort the group buffer by group rank.
1727 If REVERSE, sort in reverse order."
1729 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
1731 (defun gnus-group-sort-groups-by-method (&optional reverse)
1732 "Sort the group buffer alphabetically by backend name.
1733 If REVERSE, sort in reverse order."
1735 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
1737 (defun gnus-group-sort-by-alphabet (info1 info2)
1738 "Sort alphabetically."
1739 (string< (gnus-info-group info1) (gnus-info-group info2)))
1741 (defun gnus-group-sort-by-unread (info1 info2)
1742 "Sort by number of unread articles."
1743 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
1744 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
1745 (< (or (and (numberp n1) n1) 0)
1746 (or (and (numberp n2) n2) 0))))
1748 (defun gnus-group-sort-by-level (info1 info2)
1750 (< (gnus-info-level info1) (gnus-info-level info2)))
1752 (defun gnus-group-sort-by-method (info1 info2)
1753 "Sort alphabetically by backend name."
1754 (string< (symbol-name (car (gnus-find-method-for-group
1755 (gnus-info-group info1) info1)))
1756 (symbol-name (car (gnus-find-method-for-group
1757 (gnus-info-group info2) info2)))))
1759 (defun gnus-group-sort-by-score (info1 info2)
1760 "Sort by group score."
1761 (< (gnus-info-score info1) (gnus-info-score info2)))
1763 (defun gnus-group-sort-by-rank (info1 info2)
1764 "Sort by level and score."
1765 (let ((level1 (gnus-info-level info1))
1766 (level2 (gnus-info-level info2)))
1767 (or (< level1 level2)
1768 (and (= level1 level2)
1769 (> (gnus-info-score info1) (gnus-info-score info2))))))
1771 ;; Group catching up.
1773 (defun gnus-group-clear-data (n)
1774 "Clear all marks and read ranges from the current group."
1776 (let ((groups (gnus-group-process-prefix n))
1778 (while (setq group (pop groups))
1779 (setq info (gnus-get-info group))
1780 (gnus-info-set-read info nil)
1781 (when (gnus-info-marks info)
1782 (gnus-info-set-marks info nil))
1783 (gnus-get-unread-articles-in-group info (gnus-active group) t)
1784 (when (gnus-group-goto-group group)
1785 (gnus-group-remove-mark group)
1786 (gnus-group-update-group-line)))))
1788 (defun gnus-group-catchup-current (&optional n all)
1789 "Mark all articles not marked as unread in current newsgroup as read.
1790 If prefix argument N is numeric, the ARG next newsgroups will be
1791 caught up. If ALL is non-nil, marked articles will also be marked as
1792 read. Cross references (Xref: header) of articles are ignored.
1793 The difference between N and actual number of newsgroups that were
1794 caught up is returned."
1796 (unless (gnus-group-group-name)
1797 (error "No group on the current line"))
1798 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
1802 "Do you really want to mark all articles as read? "
1803 "Mark all unread articles as read? "))))
1805 (let ((groups (gnus-group-process-prefix n))
1808 ;; Virtual groups have to be given special treatment.
1809 (let ((method (gnus-find-method-for-group (car groups))))
1810 (if (eq 'nnvirtual (car method))
1811 (nnvirtual-catchup-group
1812 (gnus-group-real-name (car groups)) (nth 1 method) all)))
1813 (gnus-group-remove-mark (car groups))
1814 (if (>= (gnus-group-group-level) gnus-level-zombie)
1815 (gnus-message 2 "Dead groups can't be caught up")
1817 (gnus-group-goto-group (car groups))
1818 (gnus-group-catchup (car groups) all))
1819 (gnus-group-update-group-line)
1820 (setq ret (1+ ret))))
1821 (setq groups (cdr groups)))
1822 (gnus-group-next-unread-group 1)
1825 (defun gnus-group-catchup-current-all (&optional n)
1826 "Mark all articles in current newsgroup as read.
1827 Cross references (Xref: header) of articles are ignored."
1829 (gnus-group-catchup-current n 'all))
1831 (defun gnus-group-catchup (group &optional all)
1832 "Mark all articles in GROUP as read.
1833 If ALL is non-nil, all articles are marked as read.
1834 The return value is the number of articles that were marked as read,
1835 or nil if no action could be taken."
1836 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
1838 ;; Do the updating only if the newsgroup isn't killed.
1839 (if (not (numberp (car entry)))
1840 (gnus-message 1 "Can't catch up; non-active group")
1841 ;; Do auto-expirable marks if that's required.
1842 (when (gnus-group-auto-expirable-p group)
1843 (gnus-add-marked-articles
1844 group 'expire (gnus-list-of-unread-articles group))
1846 (let ((marks (nth 3 (nth 2 entry))))
1847 (gnus-add-marked-articles
1848 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
1849 (gnus-add-marked-articles
1850 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
1852 (gnus-update-read-articles group nil)
1853 ;; Also nix out the lists of marks and dormants.
1855 (gnus-add-marked-articles group 'tick nil nil 'force)
1856 (gnus-add-marked-articles group 'dormant nil nil 'force))
1857 (run-hooks 'gnus-group-catchup-group-hook)
1860 (defun gnus-group-expire-articles (&optional n)
1861 "Expire all expirable articles in the current newsgroup."
1863 (let ((groups (gnus-group-process-prefix n))
1866 (error "No groups to expire"))
1867 (while (setq group (pop groups))
1868 (gnus-group-remove-mark group)
1869 (when (gnus-check-backend-function 'request-expire-articles group)
1870 (gnus-message 6 "Expiring articles in %s..." group)
1871 (let* ((info (gnus-get-info group))
1872 (expirable (if (gnus-group-total-expirable-p group)
1873 (cons nil (gnus-list-of-read-articles group))
1874 (assq 'expire (gnus-info-marks info))))
1875 (expiry-wait (gnus-group-get-parameter group 'expiry-wait)))
1879 (gnus-compress-sequence
1881 ;; We set the expiry variables to the groupp
1883 (let ((nnmail-expiry-wait-function nil)
1884 (nnmail-expiry-wait expiry-wait))
1885 (gnus-request-expire-articles
1886 (gnus-uncompress-sequence (cdr expirable)) group))
1887 ;; Just expire using the normal expiry values.
1888 (gnus-request-expire-articles
1889 (gnus-uncompress-sequence (cdr expirable)) group))))
1890 (gnus-close-group group))
1891 (gnus-message 6 "Expiring articles in %s...done" group)))
1892 (gnus-group-position-point))))
1894 (defun gnus-group-expire-all-groups ()
1895 "Expire all expirable articles in all newsgroups."
1898 (gnus-message 5 "Expiring...")
1899 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
1900 (cdr gnus-newsrc-alist))))
1901 (gnus-group-expire-articles nil)))
1902 (gnus-group-position-point)
1903 (gnus-message 5 "Expiring...done"))
1905 (defun gnus-group-set-current-level (n level)
1906 "Set the level of the next N groups to LEVEL."
1911 (let ((s (read-string
1912 (format "Level (default %s): "
1913 (or (gnus-group-group-level)
1914 gnus-level-default-subscribed)))))
1915 (if (string-match "^\\s-*$" s)
1916 (int-to-string (or (gnus-group-group-level)
1917 gnus-level-default-subscribed))
1919 (or (and (>= level 1) (<= level gnus-level-killed))
1920 (error "Illegal level: %d" level))
1921 (let ((groups (gnus-group-process-prefix n))
1923 (while (setq group (pop groups))
1924 (gnus-group-remove-mark group)
1925 (gnus-message 6 "Changed level of %s from %d to %d"
1926 group (or (gnus-group-group-level) gnus-level-killed)
1928 (gnus-group-change-level
1929 group level (or (gnus-group-group-level) gnus-level-killed))
1930 (gnus-group-update-group-line)))
1931 (gnus-group-position-point))
1933 (defun gnus-group-unsubscribe-current-group (&optional n)
1934 "Toggle subscription of the current group.
1935 If given numerical prefix, toggle the N next groups."
1937 (let ((groups (gnus-group-process-prefix n))
1940 (setq group (car groups)
1941 groups (cdr groups))
1942 (gnus-group-remove-mark group)
1943 (gnus-group-unsubscribe-group
1944 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
1945 gnus-level-default-unsubscribed
1946 gnus-level-default-subscribed) t)
1947 (gnus-group-update-group-line))
1948 (gnus-group-next-group 1)))
1950 (defun gnus-group-unsubscribe-group (group &optional level silent)
1951 "Toggle subscription to GROUP.
1952 Killed newsgroups are subscribed. If SILENT, don't try to update the
1955 (list (completing-read
1956 "Group: " gnus-active-hashtb nil
1957 (gnus-read-active-file-p)
1959 'gnus-group-history)))
1960 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
1962 ((string-match "^[ \t]$" group)
1963 (error "Empty group name"))
1965 ;; Toggle subscription flag.
1966 (gnus-group-change-level
1967 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
1968 gnus-level-subscribed)
1969 (1+ gnus-level-subscribed)
1970 gnus-level-default-subscribed)))
1972 (gnus-group-update-group group)))
1973 ((and (stringp group)
1974 (or (not (gnus-read-active-file-p))
1975 (gnus-active group)))
1976 ;; Add new newsgroup.
1977 (gnus-group-change-level
1979 (if level level gnus-level-default-subscribed)
1980 (or (and (member group gnus-zombie-list)
1983 (and (gnus-group-group-name)
1984 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
1986 (gnus-group-update-group group)))
1987 (t (error "No such newsgroup: %s" group)))
1988 (gnus-group-position-point)))
1990 (defun gnus-group-transpose-groups (n)
1991 "Move the current newsgroup up N places.
1992 If given a negative prefix, move down instead. The difference between
1993 N and the number of steps taken is returned."
1995 (or (gnus-group-group-name)
1996 (error "No group on current line"))
1997 (gnus-group-kill-group 1)
1999 (forward-line (- n))
2000 (gnus-group-yank-group)
2001 (gnus-group-position-point)))
2003 (defun gnus-group-kill-all-zombies ()
2004 "Kill all zombie newsgroups."
2006 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
2007 (setq gnus-zombie-list nil)
2008 (gnus-group-list-groups))
2010 (defun gnus-group-kill-region (begin end)
2011 "Kill newsgroups in current region (excluding current point).
2012 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
2027 (beginning-of-line) ;Important when LINES < 1
2028 (gnus-group-kill-group lines)))
2030 (defun gnus-group-kill-group (&optional n discard)
2031 "Kill the next N groups.
2032 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2033 However, only groups that were alive can be yanked; already killed
2034 groups or zombie groups can't be yanked.
2035 The return value is the name of the group that was killed, or a list
2038 (let ((buffer-read-only nil)
2039 (groups (gnus-group-process-prefix n))
2040 group entry level out)
2041 (if (< (length groups) 10)
2042 ;; This is faster when there are few groups.
2044 (push (setq group (pop groups)) out)
2045 (gnus-group-remove-mark group)
2046 (setq level (gnus-group-group-level))
2048 (when (and (not discard)
2049 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
2050 (push (cons (car entry) (nth 2 entry))
2051 gnus-list-of-killed-groups))
2052 (gnus-group-change-level
2053 (if entry entry group) gnus-level-killed (if entry nil level)))
2054 ;; If there are lots and lots of groups to be killed, we use
2055 ;; this thing instead.
2057 (setq groups (nreverse groups))
2059 (gnus-group-remove-mark (setq group (pop groups)))
2061 (push group gnus-killed-list)
2062 (setq gnus-newsrc-alist
2063 (delq (assoc group gnus-newsrc-alist)
2065 (when gnus-group-change-level-function
2066 (funcall gnus-group-change-level-function group 9 3))
2068 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
2069 (push (cons (car entry) (nth 2 entry))
2070 gnus-list-of-killed-groups)
2071 (setcdr (cdr entry) (cdddr entry)))
2072 ((member group gnus-zombie-list)
2073 (setq gnus-zombie-list (delete group gnus-zombie-list)))))
2074 (gnus-make-hashtable-from-newsrc-alist)))
2076 (gnus-group-position-point)
2077 (if (< (length out) 2) (car out) (nreverse out))))
2079 (defun gnus-group-yank-group (&optional arg)
2080 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
2081 inserting it before the current newsgroup. The numeric ARG specifies
2082 how many newsgroups are to be yanked. The name of the newsgroup yanked
2083 is returned, or (if several groups are yanked) a list of yanked groups
2086 (setq arg (or arg 1))
2087 (let (info group prev out)
2088 (while (>= (decf arg) 0)
2089 (if (not (setq info (pop gnus-list-of-killed-groups)))
2090 (error "No more newsgroups to yank"))
2091 (push (setq group (nth 1 info)) out)
2092 ;; Find which newsgroup to insert this one before - search
2093 ;; backward until something suitable is found. If there are no
2094 ;; other newsgroups in this buffer, just make this newsgroup the
2096 (setq prev (gnus-group-group-name))
2097 (gnus-group-change-level
2098 info (gnus-info-level (cdr info)) gnus-level-killed
2099 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
2101 (gnus-group-insert-group-line-info group))
2103 (gnus-group-position-point)
2104 (if (< (length out) 2) (car out) (nreverse out))))
2106 (defun gnus-group-kill-level (level)
2107 "Kill all groups that is on a certain LEVEL."
2108 (interactive "nKill all groups on level: ")
2110 ((= level gnus-level-zombie)
2111 (setq gnus-killed-list
2112 (nconc gnus-zombie-list gnus-killed-list))
2113 (setq gnus-zombie-list nil))
2114 ((and (< level gnus-level-zombie)
2116 (or gnus-expert-user
2119 "Do you really want to kill all groups on level %d? "
2121 (let* ((prev gnus-newsrc-alist)
2124 (if (= (gnus-info-level (car alist)) level)
2126 (push (gnus-info-group (car alist)) gnus-killed-list)
2127 (setcdr prev (cdr alist)))
2129 (setq alist (cdr alist)))
2130 (gnus-make-hashtable-from-newsrc-alist)
2131 (gnus-group-list-groups)))
2133 (error "Can't kill; illegal level: %d" level))))
2135 (defun gnus-group-list-all-groups (&optional arg)
2136 "List all newsgroups with level ARG or lower.
2137 Default is gnus-level-unsubscribed, which lists all subscribed and most
2138 unsubscribed groups."
2140 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
2142 ;; Redefine this to list ALL killed groups if prefix arg used.
2143 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
2144 (defun gnus-group-list-killed (&optional arg)
2145 "List all killed newsgroups in the group buffer.
2146 If ARG is non-nil, list ALL killed groups known to Gnus. This may
2147 entail asking the server for the groups."
2149 ;; Find all possible killed newsgroups if arg.
2151 (gnus-get-killed-groups))
2152 (if (not gnus-killed-list)
2153 (gnus-message 6 "No killed groups")
2154 (let (gnus-group-list-mode)
2155 (funcall gnus-group-prepare-function
2156 gnus-level-killed t gnus-level-killed))
2157 (goto-char (point-min)))
2158 (gnus-group-position-point))
2160 (defun gnus-group-list-zombies ()
2161 "List all zombie newsgroups in the group buffer."
2163 (if (not gnus-zombie-list)
2164 (gnus-message 6 "No zombie groups")
2165 (let (gnus-group-list-mode)
2166 (funcall gnus-group-prepare-function
2167 gnus-level-zombie t gnus-level-zombie))
2168 (goto-char (point-min)))
2169 (gnus-group-position-point))
2171 (defun gnus-group-list-active ()
2172 "List all groups that are available from the server(s)."
2174 ;; First we make sure that we have really read the active file.
2175 (unless (gnus-read-active-file-p)
2176 (let ((gnus-read-active-file t))
2177 (gnus-read-active-file)))
2178 ;; Find all groups and sort them.
2186 (setq list (cons (symbol-name sym) list))))
2190 (buffer-read-only nil))
2193 (gnus-group-insert-group-line-info (pop groups)))
2194 (goto-char (point-min))))
2196 (defun gnus-activate-all-groups (level)
2197 "Activate absolutely all groups."
2198 (interactive (list 7))
2199 (let ((gnus-activate-level level)
2200 (gnus-activate-foreign-newsgroups level))
2201 (gnus-group-get-new-news)))
2203 (defun gnus-group-get-new-news (&optional arg)
2204 "Get newly arrived articles.
2205 If ARG is a number, it specifies which levels you are interested in
2206 re-scanning. If ARG is non-nil and not a number, this will force
2207 \"hard\" re-reading of the active files from all servers."
2209 (run-hooks 'gnus-get-new-news-hook)
2210 ;; We might read in new NoCeM messages here.
2211 (when (and gnus-use-nocem
2213 (gnus-nocem-scan-groups))
2214 ;; If ARG is not a number, then we read the active file.
2215 (when (and arg (not (numberp arg)))
2216 (let ((gnus-read-active-file t))
2217 (gnus-read-active-file))
2220 (setq arg (gnus-group-default-level arg t))
2221 (if (and gnus-read-active-file (not arg))
2223 (gnus-read-active-file)
2224 (gnus-get-unread-articles arg))
2225 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
2226 (gnus-get-unread-articles arg)))
2227 (run-hooks 'gnus-after-getting-new-news-hook)
2228 (gnus-group-list-groups))
2230 (defun gnus-group-get-new-news-this-group (&optional n)
2231 "Check for newly arrived news in the current group (and the N-1 next groups).
2232 The difference between N and the number of newsgroup checked is returned.
2233 If N is negative, this group and the N-1 previous groups will be checked."
2235 (let* ((groups (gnus-group-process-prefix n))
2236 (ret (if (numberp n) (- n (length groups)) 0))
2237 (beg (unless n (point)))
2239 (while (setq group (pop groups))
2240 (gnus-group-remove-mark group)
2241 (if (gnus-activate-group group 'scan)
2243 (gnus-get-unread-articles-in-group
2244 (gnus-get-info group) (gnus-active group) t)
2245 (unless (gnus-virtual-group-p group)
2246 (gnus-close-group group))
2247 (gnus-group-update-group group))
2248 (if (eq (gnus-server-status (gnus-find-method-for-group group))
2250 (gnus-error "Server denied access")
2251 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
2252 (when beg (goto-char beg))
2253 (when gnus-goto-next-group-when-activating
2254 (gnus-group-next-unread-group 1 t))
2255 (gnus-summary-position-point)
2258 (defun gnus-group-fetch-faq (group &optional faq-dir)
2259 "Fetch the FAQ for the current group."
2262 (and (gnus-group-group-name)
2263 (gnus-group-real-name (gnus-group-group-name)))
2264 (cond (current-prefix-arg
2266 "Faq dir: " (and (listp gnus-group-faq-directory)
2267 (mapcar (lambda (file) (list file))
2268 gnus-group-faq-directory)))))))
2270 (setq faq-dir (if (listp gnus-group-faq-directory)
2271 (car gnus-group-faq-directory)
2272 gnus-group-faq-directory)))
2273 (or group (error "No group name given"))
2274 (let ((file (concat (file-name-as-directory faq-dir)
2275 (gnus-group-real-name group))))
2276 (if (not (file-exists-p file))
2277 (error "No such file: %s" file)
2280 (defun gnus-group-describe-group (force &optional group)
2281 "Display a description of the current newsgroup."
2282 (interactive (list current-prefix-arg (gnus-group-group-name)))
2283 (let* ((method (gnus-find-method-for-group group))
2284 (mname (gnus-group-prefixed-name "" method))
2287 gnus-description-hashtb)
2288 (gnus-sethash mname nil gnus-description-hashtb))
2289 (or group (error "No group name given"))
2290 (and (or (and gnus-description-hashtb
2291 ;; We check whether this group's method has been
2292 ;; queried for a description file.
2293 (gnus-gethash mname gnus-description-hashtb))
2294 (setq desc (gnus-group-get-description group))
2295 (gnus-read-descriptions-file method))
2297 (or desc (gnus-gethash group gnus-description-hashtb)
2298 "No description available")))))
2300 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2301 (defun gnus-group-describe-all-groups (&optional force)
2302 "Pop up a buffer with descriptions of all newsgroups."
2304 (and force (setq gnus-description-hashtb nil))
2305 (if (not (or gnus-description-hashtb
2306 (gnus-read-all-descriptions-files)))
2307 (error "Couldn't request descriptions file"))
2308 (let ((buffer-read-only nil)
2314 (insert (format " *: %-20s %s\n" (symbol-name group)
2315 (symbol-value group)))
2316 (gnus-add-text-properties
2317 b (1+ b) (list 'gnus-group group
2318 'gnus-unread t 'gnus-marked nil
2319 'gnus-level (1+ gnus-level-subscribed))))
2320 gnus-description-hashtb)
2321 (goto-char (point-min))
2322 (gnus-group-position-point)))
2324 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2325 (defun gnus-group-apropos (regexp &optional search-description)
2326 "List all newsgroups that have names that match a regexp."
2327 (interactive "sGnus apropos (regexp): ")
2329 (obuf (current-buffer))
2331 ;; Go through all newsgroups that are known to Gnus.
2334 (and (symbol-name group)
2335 (string-match regexp (symbol-name group))
2336 (setq groups (cons (symbol-name group) groups))))
2338 ;; Also go through all descriptions that are known to Gnus.
2339 (when search-description
2342 (and (string-match regexp (symbol-value group))
2343 (gnus-active (symbol-name group))
2344 (setq groups (cons (symbol-name group) groups))))
2345 gnus-description-hashtb))
2347 (gnus-message 3 "No groups matched \"%s\"." regexp)
2348 ;; Print out all the groups.
2350 (pop-to-buffer "*Gnus Help*")
2351 (buffer-disable-undo (current-buffer))
2353 (setq groups (sort groups 'string<))
2355 ;; Groups may be entered twice into the list of groups.
2356 (if (not (string= (car groups) prev))
2358 (insert (setq prev (car groups)) "\n")
2359 (if (and gnus-description-hashtb
2360 (setq des (gnus-gethash (car groups)
2361 gnus-description-hashtb)))
2362 (insert " " des "\n"))))
2363 (setq groups (cdr groups)))
2364 (goto-char (point-min))))
2365 (pop-to-buffer obuf)))
2367 (defun gnus-group-description-apropos (regexp)
2368 "List all newsgroups that have names or descriptions that match a regexp."
2369 (interactive "sGnus description apropos (regexp): ")
2370 (if (not (or gnus-description-hashtb
2371 (gnus-read-all-descriptions-files)))
2372 (error "Couldn't request descriptions file"))
2373 (gnus-group-apropos regexp t))
2375 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2376 (defun gnus-group-list-matching (level regexp &optional all lowest)
2377 "List all groups with unread articles that match REGEXP.
2378 If the prefix LEVEL is non-nil, it should be a number that says which
2379 level to cut off listing groups.
2380 If ALL, also list groups with no unread articles.
2381 If LOWEST, don't list groups with level lower than LOWEST.
2383 This command may read the active file."
2384 (interactive "P\nsList newsgroups matching: ")
2385 ;; First make sure active file has been read.
2387 (> (prefix-numeric-value level) gnus-level-killed))
2388 (gnus-get-killed-groups))
2389 (gnus-group-prepare-flat (or level gnus-level-subscribed)
2390 all (or lowest 1) regexp)
2391 (goto-char (point-min))
2392 (gnus-group-position-point))
2394 (defun gnus-group-list-all-matching (level regexp &optional lowest)
2395 "List all groups that match REGEXP.
2396 If the prefix LEVEL is non-nil, it should be a number that says which
2397 level to cut off listing groups.
2398 If LOWEST, don't list groups with level lower than LOWEST."
2399 (interactive "P\nsList newsgroups matching: ")
2400 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
2402 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
2403 (defun gnus-group-save-newsrc (&optional force)
2404 "Save the Gnus startup files.
2405 If FORCE, force saving whether it is necessary or not."
2407 (gnus-save-newsrc-file force))
2409 (defun gnus-group-restart (&optional arg)
2410 "Force Gnus to read the .newsrc file."
2412 (when (gnus-yes-or-no-p
2413 (format "Are you sure you want to read %s? "
2414 gnus-current-startup-file))
2415 (gnus-save-newsrc-file)
2416 (gnus-setup-news 'force)
2417 (gnus-group-list-groups arg)))
2419 (defun gnus-group-read-init-file ()
2420 "Read the Gnus elisp init file."
2422 (gnus-read-init-file))
2424 (defun gnus-group-check-bogus-groups (&optional silent)
2425 "Check bogus newsgroups.
2426 If given a prefix, don't ask for confirmation before removing a bogus
2429 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
2430 (gnus-group-list-groups))
2432 (defun gnus-group-edit-global-kill (&optional article group)
2433 "Edit the global kill file.
2434 If GROUP, edit that local kill file instead."
2436 (setq gnus-current-kill-article article)
2437 (gnus-kill-file-edit-file group)
2440 (substitute-command-keys
2441 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
2442 (if group "local" "global")))))
2444 (defun gnus-group-edit-local-kill (article group)
2445 "Edit a local kill file."
2446 (interactive (list nil (gnus-group-group-name)))
2447 (gnus-group-edit-global-kill article group))
2449 (defun gnus-group-force-update ()
2450 "Update `.newsrc' file."
2452 (gnus-save-newsrc-file))
2454 (defun gnus-group-suspend ()
2455 "Suspend the current Gnus session.
2456 In fact, cleanup buffers except for group mode buffer.
2457 The hook gnus-suspend-gnus-hook is called before actually suspending."
2459 (run-hooks 'gnus-suspend-gnus-hook)
2460 ;; Kill Gnus buffers except for group mode buffer.
2461 (let* ((group-buf (get-buffer gnus-group-buffer))
2462 ;; Do this on a separate list in case the user does a ^G before we finish
2464 (delete group-buf (delete gnus-dribble-buffer
2465 (append gnus-buffer-list nil)))))
2466 (while gnus-buffer-list
2467 (gnus-kill-buffer (pop gnus-buffer-list)))
2468 (gnus-kill-gnus-frames)
2470 (setq gnus-buffer-list (list group-buf))
2471 (bury-buffer group-buf)
2472 (delete-windows-on group-buf t))))
2474 (defun gnus-group-clear-dribble ()
2475 "Clear all information from the dribble buffer."
2477 (gnus-dribble-clear)
2478 (gnus-message 7 "Cleared dribble buffer"))
2480 (defun gnus-group-exit ()
2481 "Quit reading news after updating .newsrc.eld and .newsrc.
2482 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2485 (or noninteractive ;For gnus-batch-kill
2486 (not gnus-interactive-exit) ;Without confirmation
2488 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
2489 (run-hooks 'gnus-exit-gnus-hook)
2490 ;; Offer to save data from non-quitted summary buffers.
2491 (gnus-offer-save-summaries)
2492 ;; Save the newsrc file(s).
2493 (gnus-save-newsrc-file)
2495 (gnus-close-backends)
2496 ;; Reset everything.
2498 ;; Allow the user to do things after cleaning up.
2499 (run-hooks 'gnus-after-exiting-gnus-hook)))
2501 (defun gnus-group-quit ()
2502 "Quit reading news without updating .newsrc.eld or .newsrc.
2503 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2505 (when (or noninteractive ;For gnus-batch-kill
2506 (zerop (buffer-size))
2507 (not (gnus-server-opened gnus-select-method))
2509 (not gnus-current-startup-file)
2511 (format "Quit reading news without saving %s? "
2512 (file-name-nondirectory gnus-current-startup-file))))
2513 (run-hooks 'gnus-exit-gnus-hook)
2514 (gnus-configure-windows 'group t)
2516 (gnus-close-backends)
2518 ;; Allow the user to do things after cleaning up.
2519 (run-hooks 'gnus-after-exiting-gnus-hook)))
2521 (defun gnus-group-describe-briefly ()
2522 "Give a one line description of the group mode commands."
2524 (gnus-message 7 (substitute-command-keys "\\<gnus-group-mode-map>\\[gnus-group-read-group]:Select \\[gnus-group-next-unread-group]:Forward \\[gnus-group-prev-unread-group]:Backward \\[gnus-group-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-group-describe-briefly]:This help")))
2526 (defun gnus-group-browse-foreign-server (method)
2527 "Browse a foreign news server.
2528 If called interactively, this function will ask for a select method
2529 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
2530 If not, METHOD should be a list where the first element is the method
2531 and the second element is the address."
2533 (list (let ((how (completing-read
2535 (append gnus-valid-select-methods gnus-server-alist)
2536 nil t (cons "nntp" 0) 'gnus-method-history)))
2537 ;; We either got a backend name or a virtual server name.
2538 ;; If the first, we also need an address.
2539 (if (assoc how gnus-valid-select-methods)
2541 ;; Suggested by mapjph@bath.ac.uk.
2544 (mapcar (lambda (server) (list server))
2545 gnus-secondary-servers)))
2546 ;; We got a server name, so we find the method.
2547 (gnus-server-to-method how)))))
2548 (gnus-browse-foreign-server method))
2550 (defun gnus-group-set-info (info &optional method-only-group part)
2551 (let* ((entry (gnus-gethash
2552 (or method-only-group (gnus-info-group info))
2553 gnus-newsrc-hashtb))
2555 (info (if method-only-group (nth 2 entry) info))
2557 (when method-only-group
2559 (error "Trying to change non-existent group %s" method-only-group))
2560 ;; We have received parts of the actual group info - either the
2561 ;; select method or the group parameters. We first check
2562 ;; whether we have to extend the info, and if so, do that.
2563 (let ((len (length info))
2564 (total (if (eq part 'method) 5 6)))
2566 (setcdr (nthcdr (1- len) info)
2567 (make-list (- total len) nil)))
2568 ;; Then we enter the new info.
2569 (setcar (nthcdr (1- total) info) part-info)))
2571 ;; This is a new group, so we just create it.
2573 (set-buffer gnus-group-buffer)
2574 (setq method (gnus-info-method info))
2575 (when (gnus-server-equal method "native")
2578 (set-buffer gnus-group-buffer)
2580 ;; It's a foreign group...
2581 (gnus-group-make-group
2582 (gnus-group-real-name (gnus-info-group info))
2583 (if (stringp method) method
2584 (prin1-to-string (car method)))
2586 (nth 1 (gnus-info-method info))))
2587 ;; It's a native group.
2588 (gnus-group-make-group (gnus-info-group info))))
2589 (gnus-message 6 "Note: New group created")
2591 (gnus-gethash (gnus-group-prefixed-name
2592 (gnus-group-real-name (gnus-info-group info))
2593 (or (gnus-info-method info) gnus-select-method))
2594 gnus-newsrc-hashtb))))
2595 ;; Whether it was a new group or not, we now have the entry, so we
2596 ;; can do the update.
2599 (setcar (nthcdr 2 entry) info)
2600 (when (and (not (eq (car entry) t))
2601 (gnus-active (gnus-info-group info)))
2602 (setcar entry (length (gnus-list-of-unread-articles (car info))))))
2603 (error "No such group: %s" (gnus-info-group info)))))
2605 (defun gnus-group-set-method-info (group select-method)
2606 (gnus-group-set-info select-method group 'method))
2608 (defun gnus-group-set-params-info (group params)
2609 (gnus-group-set-info params group 'params))
2611 (provide 'gnus-group)
2613 ;;; gnus-group.el ends here