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-list-inactive-groups t
81 "*If non-nil, inactive groups will be listed.")
83 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
84 "*Function used for sorting the group buffer.
85 This function will be called with group info entries as the arguments
86 for the groups to be sorted. Pre-made functions include
87 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread',
88 `gnus-group-sort-by-level', `gnus-group-sort-by-score',
89 `gnus-group-sort-by-method', and `gnus-group-sort-by-rank'.
91 This variable can also be a list of sorting functions. In that case,
92 the most significant sort function should be the last function in the
95 (defvar gnus-group-line-format "%M\%S\%p\%P\%5y: %(%g%)%l\n"
96 "*Format of group lines.
97 It works along the same lines as a normal formatting string,
98 with some simple extensions.
100 %M Only marked articles (character, \"*\" or \" \")
101 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
102 %L Level of subscribedness (integer)
103 %N Number of unread articles (integer)
104 %I Number of dormant articles (integer)
105 %i Number of ticked and dormant (integer)
106 %T Number of ticked articles (integer)
107 %R Number of read articles (integer)
108 %t Estimated total number of articles (integer)
109 %y Number of unread, unticked articles (integer)
110 %G Group name (string)
111 %g Qualified group name (string)
112 %D Group description (string)
113 %s Select method (string)
114 %o Moderated group (char, \"m\")
115 %p Process mark (char)
116 %O Moderated group (string, \"(m)\" or \"\")
117 %P Topic indentation (string)
118 %l Whether there are GroupLens predictions for this group (string)
119 %n Select from where (string)
120 %z A string that look like `<%s:%n>' if a foreign select method is used
121 %u User defined specifier. The next character in the format string should
122 be a letter. Gnus will call the function gnus-user-format-function-X,
123 where X is the letter following %u. The function will be passed the
124 current header as argument. The function should return a string, which
125 will be inserted into the buffer just like information from any other
128 Text between %( and %) will be highlighted with `gnus-mouse-face' when
129 the mouse point move inside the area. There can only be one such area.
131 Note that this format specification is not always respected. For
132 reasons of efficiency, when listing killed groups, this specification
133 is ignored altogether. If the spec is changed considerably, your
134 output may end up looking strange when listing both alive and killed
137 If you use %o or %O, reading the active file will be slower and quite
138 a bit of extra memory will be used. %D will also worsen performance.
139 Also note that if you change the format specification to include any
140 of these specs, you must probably re-start Gnus to see them go into
143 (defvar gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
144 "*The format specification for the group mode line.
145 It works along the same lines as a normal formatting string,
146 with some simple extensions:
148 %S The native news server.
149 %M The native select method.
150 %: \":\" if %S isn't \"\".")
152 (defvar gnus-group-mode-hook nil
153 "*A hook for Gnus group mode.")
155 (defvar gnus-group-catchup-group-hook nil
156 "*A hook run when catching up a group from the group buffer.")
158 (defvar gnus-group-update-group-hook nil
159 "*A hook called when updating group lines.")
161 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
162 "*A function that is called to generate the group buffer.
163 The function is called with three arguments: The first is a number;
164 all group with a level less or equal to that number should be listed,
165 if the second is non-nil, empty groups should also be displayed. If
166 the third is non-nil, it is a number. No groups with a level lower
167 than this number should be displayed.
169 The only current function implemented is `gnus-group-prepare-flat'.")
171 (defvar gnus-group-prepare-hook nil
172 "*A hook called after the group buffer has been generated.
173 If you want to modify the group buffer, you can use this hook.")
175 (defvar gnus-suspend-gnus-hook nil
176 "*A hook called when suspending (not exiting) Gnus.")
178 (defvar gnus-exit-gnus-hook nil
179 "*A hook called when exiting Gnus.")
181 (defvar gnus-after-exiting-gnus-hook nil
182 "*A hook called after exiting Gnus.")
184 (defvar gnus-group-update-hook '(gnus-group-highlight-line)
185 "*A hook called when a group line is changed.
186 The hook will not be called if `gnus-visual' is nil.
188 The default function `gnus-group-highlight-line' will
189 highlight the line according to the `gnus-group-highlight'
192 ;;; Internal variables
194 (defvar gnus-group-indentation-function nil)
195 (defvar gnus-goto-missing-group-function nil)
196 (defvar gnus-group-goto-next-group-function nil
197 "Function to override finding the next group after listing groups.")
199 (defvar gnus-group-edit-buffer nil)
201 (defvar gnus-group-line-format-alist
202 `((?M gnus-tmp-marked-mark ?c)
203 (?S gnus-tmp-subscribed ?c)
204 (?L gnus-tmp-level ?d)
205 (?N (cond ((eq number t) "*" )
209 (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
210 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
212 (?R gnus-tmp-number-of-read ?s)
213 (?t gnus-tmp-number-total ?d)
214 (?y gnus-tmp-number-of-unread ?s)
215 (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
216 (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
217 (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
218 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
219 (?g gnus-tmp-group ?s)
220 (?G gnus-tmp-qualified-group ?s)
221 (?c (gnus-short-group-name gnus-tmp-group) ?s)
222 (?D gnus-tmp-newsgroup-description ?s)
223 (?o gnus-tmp-moderated ?c)
224 (?O gnus-tmp-moderated-string ?s)
225 (?p gnus-tmp-process-marked ?c)
226 (?s gnus-tmp-news-server ?s)
227 (?n gnus-tmp-news-method ?s)
228 (?P gnus-group-indentation ?s)
229 (?l gnus-tmp-grouplens ?s)
230 (?z gnus-tmp-news-method-string ?s)
231 (?u gnus-tmp-user-defined ?s)))
233 (defvar gnus-group-mode-line-format-alist
234 `((?S gnus-tmp-news-server ?s)
235 (?M gnus-tmp-news-method ?s)
236 (?u gnus-tmp-user-defined ?s)
237 (?: gnus-tmp-colon ?s)))
239 (defvar gnus-topic-topology nil
240 "The complete topic hierarchy.")
242 (defvar gnus-topic-alist nil
243 "The complete topic-group alist.")
245 (defvar gnus-group-marked nil)
247 (defvar gnus-group-list-mode nil)
253 (put 'gnus-group-mode 'mode-class 'special)
256 (gnus-define-keys gnus-group-mode-map
257 " " gnus-group-read-group
258 "=" gnus-group-select-group
259 "\r" gnus-group-select-group
260 "\M-\r" gnus-group-quick-select-group
261 "j" gnus-group-jump-to-group
262 "n" gnus-group-next-unread-group
263 "p" gnus-group-prev-unread-group
264 "\177" gnus-group-prev-unread-group
265 [delete] gnus-group-prev-unread-group
266 "N" gnus-group-next-group
267 "P" gnus-group-prev-group
268 "\M-n" gnus-group-next-unread-group-same-level
269 "\M-p" gnus-group-prev-unread-group-same-level
270 "," gnus-group-best-unread-group
271 "." gnus-group-first-unread-group
272 "u" gnus-group-unsubscribe-current-group
273 "U" gnus-group-unsubscribe-group
274 "c" gnus-group-catchup-current
275 "C" gnus-group-catchup-current-all
276 "l" gnus-group-list-groups
277 "L" gnus-group-list-all-groups
279 "g" gnus-group-get-new-news
280 "\M-g" gnus-group-get-new-news-this-group
281 "R" gnus-group-restart
282 "r" gnus-group-read-init-file
283 "B" gnus-group-browse-foreign-server
284 "b" gnus-group-check-bogus-groups
285 "F" gnus-find-new-newsgroups
286 "\C-c\C-d" gnus-group-describe-group
287 "\M-d" gnus-group-describe-all-groups
288 "\C-c\C-a" gnus-group-apropos
289 "\C-c\M-\C-a" gnus-group-description-apropos
290 "a" gnus-group-post-news
291 "\ek" gnus-group-edit-local-kill
292 "\eK" gnus-group-edit-global-kill
293 "\C-k" gnus-group-kill-group
294 "\C-y" gnus-group-yank-group
295 "\C-w" gnus-group-kill-region
296 "\C-x\C-t" gnus-group-transpose-groups
297 "\C-c\C-l" gnus-group-list-killed
298 "\C-c\C-x" gnus-group-expire-articles
299 "\C-c\M-\C-x" gnus-group-expire-all-groups
301 "s" gnus-group-save-newsrc
302 "z" gnus-group-suspend
303 ; "Z" gnus-group-clear-dribble
306 "?" gnus-group-describe-briefly
307 "\C-c\C-i" gnus-info-find-node
308 "\M-e" gnus-group-edit-group-method
309 "^" gnus-group-enter-server-mode
310 gnus-mouse-2 gnus-mouse-pick-group
311 "<" beginning-of-buffer
314 "\C-c\C-s" gnus-group-sort-groups
316 "\C-c\M-g" gnus-activate-all-groups
317 "\M-&" gnus-group-universal-argument
318 "#" gnus-group-mark-group
319 "\M-#" gnus-group-unmark-group)
321 (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
322 "m" gnus-group-mark-group
323 "u" gnus-group-unmark-group
324 "w" gnus-group-mark-region
325 "m" gnus-group-mark-buffer
326 "r" gnus-group-mark-regexp
327 "U" gnus-group-unmark-all-groups)
329 (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
330 "d" gnus-group-make-directory-group
331 "h" gnus-group-make-help-group
332 "a" gnus-group-make-archive-group
333 "k" gnus-group-make-kiboze-group
334 "m" gnus-group-make-group
335 "E" gnus-group-edit-group
336 "e" gnus-group-edit-group-method
337 "p" gnus-group-edit-group-parameters
338 "v" gnus-group-add-to-virtual
339 "V" gnus-group-make-empty-virtual
340 "D" gnus-group-enter-directory
341 "f" gnus-group-make-doc-group
342 "r" gnus-group-rename-group
343 "\177" gnus-group-delete-group
344 [delete] gnus-group-delete-group)
346 (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
347 "b" gnus-group-brew-soup
348 "w" gnus-soup-save-areas
349 "s" gnus-soup-send-replies
350 "p" gnus-soup-pack-packet
351 "r" nnsoup-pack-replies)
353 (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
354 "s" gnus-group-sort-groups
355 "a" gnus-group-sort-groups-by-alphabet
356 "u" gnus-group-sort-groups-by-unread
357 "l" gnus-group-sort-groups-by-level
358 "v" gnus-group-sort-groups-by-score
359 "r" gnus-group-sort-groups-by-rank
360 "m" gnus-group-sort-groups-by-method)
362 (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
363 "k" gnus-group-list-killed
364 "z" gnus-group-list-zombies
365 "s" gnus-group-list-groups
366 "u" gnus-group-list-all-groups
367 "A" gnus-group-list-active
368 "a" gnus-group-apropos
369 "d" gnus-group-description-apropos
370 "m" gnus-group-list-matching
371 "M" gnus-group-list-all-matching
372 "l" gnus-group-list-level)
374 (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
375 "f" gnus-score-flush-cache)
377 (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
378 "f" gnus-group-fetch-faq)
380 (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
381 "l" gnus-group-set-current-level
382 "t" gnus-group-unsubscribe-current-group
383 "s" gnus-group-unsubscribe-group
384 "k" gnus-group-kill-group
385 "y" gnus-group-yank-group
386 "w" gnus-group-kill-region
387 "\C-k" gnus-group-kill-level
388 "z" gnus-group-kill-all-zombies))
390 (defun gnus-group-mode ()
391 "Major mode for reading news.
393 All normal editing commands are switched off.
394 \\<gnus-group-mode-map>
395 The group buffer lists (some of) the groups available. For instance,
396 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
397 lists all zombie groups.
399 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
400 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
402 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
404 The following commands are available:
406 \\{gnus-group-mode-map}"
408 (when (and menu-bar-mode
409 (gnus-visual-p 'group-menu 'menu))
410 (gnus-group-make-menu-bar))
411 (kill-all-local-variables)
412 (gnus-simplify-mode-line)
413 (setq major-mode 'gnus-group-mode)
414 (setq mode-name "Group")
415 (gnus-group-set-mode-line)
416 (setq mode-line-process nil)
417 (use-local-map gnus-group-mode-map)
418 (buffer-disable-undo (current-buffer))
419 (setq truncate-lines t)
420 (setq buffer-read-only t)
421 (gnus-update-format-specifications nil 'group 'group-mode)
422 (gnus-update-group-mark-positions)
423 (gnus-make-local-hook 'post-command-hook)
424 (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
425 (run-hooks 'gnus-group-mode-hook))
427 (defun gnus-update-group-mark-positions ()
429 (let ((gnus-process-mark 128)
430 (gnus-group-marked '("dummy.group"))
431 (gnus-active-hashtb (make-vector 10 0)))
432 (gnus-set-active "dummy.group" '(0 . 0))
433 (gnus-set-work-buffer)
434 (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
435 (goto-char (point-min))
436 (setq gnus-group-mark-positions
437 (list (cons 'process (and (search-forward "\200" nil t)
440 (defun gnus-clear-inboxes-moved ()
441 (setq nnmail-moved-inboxes nil))
443 (defun gnus-mouse-pick-group (e)
444 "Enter the group under the mouse pointer."
447 (gnus-group-read-group nil))
449 ;; Look at LEVEL and find out what the level is really supposed to be.
450 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
451 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
452 (defun gnus-group-default-level (&optional level number-or-nil)
454 (gnus-group-use-permanent-levels
455 (or (setq gnus-group-use-permanent-levels
456 (or level (if (numberp gnus-group-use-permanent-levels)
457 gnus-group-use-permanent-levels
458 (or gnus-group-default-list-level
459 gnus-level-subscribed))))
460 gnus-group-default-list-level gnus-level-subscribed))
464 (or level gnus-group-default-list-level gnus-level-subscribed))))
466 (defun gnus-group-setup-buffer ()
467 (switch-to-buffer gnus-group-buffer)
468 (unless (eq major-mode 'gnus-group-mode)
469 (gnus-add-current-to-buffer-list)
472 (gnus-carpal-setup-buffer 'group))))
474 (defun gnus-group-list-groups (&optional level unread lowest)
475 "List newsgroups with level LEVEL or lower that have unread articles.
476 Default is all subscribed groups.
477 If argument UNREAD is non-nil, groups with no unread articles are also
479 (interactive (list (if current-prefix-arg
480 (prefix-numeric-value current-prefix-arg)
482 (gnus-group-default-level nil t)
483 gnus-group-default-list-level
484 gnus-level-subscribed))))
486 (setq level (car gnus-group-list-mode)
487 unread (cdr gnus-group-list-mode)))
488 (setq level (gnus-group-default-level level))
489 (gnus-group-setup-buffer) ;May call from out of group buffer
490 (gnus-update-format-specifications)
491 (let ((case-fold-search nil)
492 (props (text-properties-at (gnus-point-at-bol)))
493 (group (gnus-group-group-name)))
494 (set-buffer gnus-group-buffer)
495 (funcall gnus-group-prepare-function level unread lowest)
496 (if (zerop (buffer-size))
497 (gnus-message 5 gnus-no-groups-message)
498 (goto-char (point-max))
499 (when (or (not gnus-group-goto-next-group-function)
500 (not (funcall gnus-group-goto-next-group-function
503 ;; Go to the first group with unread articles.
504 (gnus-group-search-forward t)
505 ;; Find the right group to put point on. If the current group
506 ;; has disappeared in the new listing, try to find the next
507 ;; one. If no next one can be found, just leave point at the
508 ;; first newsgroup in the buffer.
509 (if (not (gnus-goto-char
511 (point-min) (point-max)
512 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
513 (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
517 (point-min) (point-max) 'gnus-group
519 (caar newsrc) gnus-active-hashtb)))))
520 (setq newsrc (cdr newsrc)))
521 (or newsrc (progn (goto-char (point-max))
522 (forward-line -1)))))))
523 ;; Adjust cursor point.
524 (gnus-group-position-point))))
526 (defun gnus-group-list-level (level &optional all)
527 "List groups on LEVEL.
528 If ALL (the prefix), also list groups that have no unread articles."
529 (interactive "nList groups on level: \nP")
530 (gnus-group-list-groups level all level))
532 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
533 "List all newsgroups with unread articles of level LEVEL or lower.
534 If ALL is non-nil, list groups that have no unread articles.
535 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
536 If REGEXP, only list groups matching REGEXP."
537 (set-buffer gnus-group-buffer)
538 (let ((buffer-read-only nil)
539 (newsrc (cdr gnus-newsrc-alist))
540 (lowest (or lowest 1))
541 info clevel unread group params)
543 (if (< lowest gnus-level-zombie)
544 ;; List living groups.
546 (setq info (car newsrc)
547 group (gnus-info-group info)
548 params (gnus-info-params info)
550 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
551 (and unread ; This group might be bogus
553 (string-match regexp group))
554 (<= (setq clevel (gnus-info-level info)) level)
556 (or all ; We list all groups?
557 (if (eq unread t) ; Unactivated?
558 gnus-group-list-inactive-groups ; We list unactivated
559 (> unread 0)) ; We list groups with unread articles
560 (and gnus-list-groups-with-ticked-articles
561 (cdr (assq 'tick (gnus-info-marks info))))
562 ; And groups with tickeds
563 ;; Check for permanent visibility.
564 (and gnus-permanently-visible-groups
565 (string-match gnus-permanently-visible-groups
567 (memq 'visible params)
568 (cdr (assq 'visible params)))
569 (gnus-group-insert-group-line
570 group (gnus-info-level info)
571 (gnus-info-marks info) unread (gnus-info-method info)))))
574 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
575 (gnus-group-prepare-flat-list-dead
576 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
579 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
580 (gnus-group-prepare-flat-list-dead
581 (setq gnus-killed-list (sort gnus-killed-list 'string<))
582 gnus-level-killed ?K regexp))
584 (gnus-group-set-mode-line)
585 (setq gnus-group-list-mode (cons level all))
586 (run-hooks 'gnus-group-prepare-hook)))
588 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
589 ;; List zombies and killed lists somewhat faster, which was
590 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
591 ;; this by ignoring the group format specification altogether.
594 ;; This loop is used when listing groups that match some
597 (setq group (pop groups))
598 (when (string-match regexp group)
599 (gnus-add-text-properties
600 (point) (prog1 (1+ (point))
601 (insert " " mark " *: " group "\n"))
602 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
604 'gnus-level level))))
605 ;; This loop is used when listing all groups.
607 (gnus-add-text-properties
608 (point) (prog1 (1+ (point))
609 (insert " " mark " *: "
610 (setq group (pop groups)) "\n"))
611 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
613 'gnus-level level))))))
615 (defun gnus-group-update-group-line ()
616 "Update the current line in the group buffer."
617 (let* ((buffer-read-only nil)
618 (group (gnus-group-group-name))
619 (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
620 gnus-group-indentation)
623 (not (gnus-ephemeral-group-p group))
625 (concat "(gnus-group-set-info '"
626 (prin1-to-string (nth 2 entry)) ")")))
627 (setq gnus-group-indentation (gnus-group-group-indentation))
629 (gnus-group-insert-group-line-info group)
631 (gnus-group-position-point))))
633 (defun gnus-group-insert-group-line-info (group)
634 "Insert GROUP on the current line."
635 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
639 ;; (Un)subscribed group.
640 (setq info (nth 2 entry))
641 (gnus-group-insert-group-line
642 group (gnus-info-level info) (gnus-info-marks info)
643 (or (car entry) t) (gnus-info-method info)))
644 ;; This group is dead.
645 (gnus-group-insert-group-line
647 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
649 (if (setq active (gnus-active group))
650 (- (1+ (cdr active)) (car active)) 0)
653 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
654 gnus-tmp-marked number
656 "Insert a group line in the group buffer."
657 (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
658 (gnus-tmp-number-total
660 (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
662 (gnus-tmp-number-of-unread
663 (if (numberp number) (int-to-string (max 0 number))
665 (gnus-tmp-number-of-read
667 (int-to-string (max 0 (- gnus-tmp-number-total number)))
670 (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
671 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
672 ((= gnus-tmp-level gnus-level-zombie) ?Z)
674 (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
675 (gnus-tmp-newsgroup-description
676 (if gnus-description-hashtb
677 (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
680 (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
681 (gnus-tmp-moderated-string
682 (if (eq gnus-tmp-moderated ?m) "(m)" ""))
684 (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
685 (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
686 (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
687 (gnus-tmp-news-method-string
689 (format "(%s:%s)" (car gnus-tmp-method)
690 (cadr gnus-tmp-method)) ""))
691 (gnus-tmp-marked-mark
692 (if (and (numberp number)
694 (cdr (assq 'tick gnus-tmp-marked)))
696 (gnus-tmp-process-marked
697 (if (member gnus-tmp-group gnus-group-marked)
698 gnus-process-mark ? ))
700 (or (and gnus-use-grouplens
701 (bbb-grouplens-group-p gnus-tmp-group))
703 (buffer-read-only nil)
704 header gnus-tmp-header) ; passed as parameter to user-funcs.
706 (gnus-add-text-properties
710 (eval gnus-group-line-format-spec))
711 `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
712 gnus-unread ,(if (numberp number)
713 (string-to-int gnus-tmp-number-of-unread)
715 gnus-marked ,gnus-tmp-marked-mark
716 gnus-indentation ,gnus-group-indentation
717 gnus-level ,gnus-tmp-level))
718 (when (inline (gnus-visual-p 'group-highlight 'highlight))
720 (run-hooks 'gnus-group-update-hook)
722 ;; Allow XEmacs to remove front-sticky text properties.
723 (gnus-group-remove-excess-properties)))
725 (defun gnus-group-update-group (group &optional visible-only)
726 "Update all lines where GROUP appear.
727 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
730 (set-buffer gnus-group-buffer)
731 ;; The buffer may be narrowed.
734 (let ((ident (gnus-intern-safe group gnus-active-hashtb))
736 found buffer-read-only)
737 ;; Enter the current status into the dribble buffer.
738 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
739 (if (and entry (not (gnus-ephemeral-group-p group)))
741 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
743 ;; Find all group instances. If topics are in use, each group
744 ;; may be listed in more than once.
745 (while (setq loc (text-property-any
746 loc (point-max) 'gnus-group ident))
749 (let ((gnus-group-indentation (gnus-group-group-indentation)))
751 (gnus-group-insert-group-line-info group)
754 (run-hooks 'gnus-group-update-group-hook)))
756 (unless (or found visible-only)
757 ;; No such line in the buffer, find out where it's supposed to
758 ;; go, and insert it there (or at the end of the buffer).
759 (if gnus-goto-missing-group-function
760 (funcall gnus-goto-missing-group-function group)
761 (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
762 (while (and entry (car entry)
766 (point-min) (point-max)
767 'gnus-group (gnus-intern-safe
768 (caar entry) gnus-active-hashtb)))))
769 (setq entry (cdr entry)))
770 (or entry (goto-char (point-max)))))
771 ;; Finally insert the line.
772 (let ((gnus-group-indentation (gnus-group-group-indentation)))
773 (gnus-group-insert-group-line-info group)
776 (run-hooks 'gnus-group-update-group-hook))))
777 (gnus-group-set-mode-line)))))
779 (defun gnus-group-set-mode-line ()
780 "Update the mode line in the group buffer."
781 (when (memq 'group gnus-updated-mode-lines)
782 ;; Yes, we want to keep this mode line updated.
784 (set-buffer gnus-group-buffer)
785 (let* ((gformat (or gnus-group-mode-line-format-spec
786 (setq gnus-group-mode-line-format-spec
788 gnus-group-mode-line-format
789 gnus-group-mode-line-format-alist))))
790 (gnus-tmp-news-server (cadr gnus-select-method))
791 (gnus-tmp-news-method (car gnus-select-method))
792 (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
794 gnus-tmp-header ;Dummy binding for user-defined formats
795 ;; Get the resulting string.
797 (and gnus-dribble-buffer
798 (buffer-name gnus-dribble-buffer)
799 (buffer-modified-p gnus-dribble-buffer)
801 (set-buffer gnus-dribble-buffer)
802 (not (zerop (buffer-size))))))
803 (mode-string (eval gformat)))
804 ;; Say whether the dribble buffer has been modified.
805 (setq mode-line-modified
806 (if modified "---*- " "----- "))
807 ;; If the line is too long, we chop it off.
808 (when (> (length mode-string) max-len)
809 (setq mode-string (substring mode-string 0 (- max-len 4))))
811 (setq mode-line-buffer-identification
812 (gnus-mode-line-buffer-identification
814 (set-buffer-modified-p modified))))))
816 (defun gnus-group-group-name ()
817 "Get the name of the newsgroup on the current line."
818 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
819 (and group (symbol-name group))))
821 (defun gnus-group-group-level ()
822 "Get the level of the newsgroup on the current line."
823 (get-text-property (gnus-point-at-bol) 'gnus-level))
825 (defun gnus-group-group-indentation ()
826 "Get the indentation of the newsgroup on the current line."
827 (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
828 (and gnus-group-indentation-function
829 (funcall gnus-group-indentation-function))
832 (defun gnus-group-group-unread ()
833 "Get the number of unread articles of the newsgroup on the current line."
834 (get-text-property (gnus-point-at-bol) 'gnus-unread))
836 (defun gnus-group-search-forward (&optional backward all level first-too)
837 "Find the next newsgroup with unread articles.
838 If BACKWARD is non-nil, find the previous newsgroup instead.
839 If ALL is non-nil, just find any newsgroup.
840 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
842 If FIRST-TOO, the current line is also eligible as a target."
843 (let ((way (if backward -1 1))
844 (low gnus-level-killed)
847 (if (and backward (progn (beginning-of-line)) (bobp))
849 (or first-too (forward-line way))
857 (get-text-property (point) 'gnus-unread)))
858 (and (numberp unread) (> unread 0)))
859 (setq lev (get-text-property (point)
861 (<= lev gnus-level-subscribed)))
863 (and (setq lev (get-text-property (point)
872 (zerop (forward-line way)))))
874 (progn (gnus-group-position-point) t)
875 (goto-char (or pos beg))
878 ;;; Gnus group mode commands
882 (defun gnus-group-mark-group (n &optional unmark no-advance)
883 "Mark the current group."
885 (let ((buffer-read-only nil)
889 (when (setq group (gnus-group-group-name))
893 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
898 (setq gnus-group-marked (delete group gnus-group-marked)))
900 (setq gnus-group-marked
901 (cons group (delete group gnus-group-marked)))))
902 (or no-advance (gnus-group-next-group 1))
904 (gnus-summary-position-point)
907 (defun gnus-group-unmark-group (n)
908 "Remove the mark from the current group."
910 (gnus-group-mark-group n 'unmark)
911 (gnus-group-position-point))
913 (defun gnus-group-unmark-all-groups ()
916 (let ((groups gnus-group-marked))
919 (gnus-group-remove-mark (pop groups)))))
920 (gnus-group-position-point))
922 (defun gnus-group-mark-region (unmark beg end)
923 "Mark all groups between point and mark.
924 If UNMARK, remove the mark instead."
926 (let ((num (count-lines beg end)))
929 (- num (gnus-group-mark-group num unmark)))))
931 (defun gnus-group-mark-buffer (&optional unmark)
932 "Mark all groups in the buffer.
933 If UNMARK, remove the mark instead."
935 (gnus-group-mark-region unmark (point-min) (point-max)))
937 (defun gnus-group-mark-regexp (regexp)
938 "Mark all groups that match some regexp."
939 (interactive "sMark (regexp): ")
940 (let ((alist (cdr gnus-newsrc-alist))
943 (when (string-match regexp (setq group (gnus-info-group (pop alist))))
944 (gnus-group-set-mark group))))
945 (gnus-group-position-point))
947 (defun gnus-group-remove-mark (group)
948 "Remove the process mark from GROUP and move point there.
949 Return nil if the group isn't displayed."
950 (if (gnus-group-goto-group group)
952 (gnus-group-mark-group 1 'unmark t)
954 (setq gnus-group-marked
955 (delete group gnus-group-marked))
958 (defun gnus-group-set-mark (group)
959 "Set the process mark on GROUP."
960 (if (gnus-group-goto-group group)
962 (gnus-group-mark-group 1 nil t))
963 (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
965 (defun gnus-group-universal-argument (arg &optional groups func)
966 "Perform any command on all groups accoring to the process/prefix convention."
968 (let ((groups (or groups (gnus-group-process-prefix arg)))
970 (if (eq (setq func (or func
973 (substitute-command-keys
974 "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
976 (gnus-error 1 "Undefined key")
978 (gnus-group-remove-mark (setq group (pop groups)))
979 (command-execute func))))
980 (gnus-group-position-point))
982 (defun gnus-group-process-prefix (n)
983 "Return a list of groups to work on.
984 Take into consideration N (the prefix) and the list of marked groups."
987 (setq n (prefix-numeric-value n))
988 ;; There is a prefix, so we return a list of the N next
990 (let ((way (if (< n 0) -1 1))
995 (setq group (gnus-group-group-name)))
996 (setq groups (cons group groups))
998 (gnus-group-next-group way)))
1000 ((and (boundp 'transient-mark-mode)
1002 (boundp 'mark-active)
1004 ;; Work on the region between point and mark.
1005 (let ((max (max (point) (mark)))
1008 (goto-char (min (point) (mark)))
1011 (push (gnus-group-group-name) groups)
1012 (zerop (gnus-group-next-group 1))
1014 (nreverse groups))))
1016 ;; No prefix, but a list of marked articles.
1017 (reverse gnus-group-marked))
1019 ;; Neither marked articles or a prefix, so we return the
1021 (let ((group (gnus-group-group-name)))
1022 (and group (list group))))))
1024 ;; Selecting groups.
1026 (defun gnus-group-read-group (&optional all no-article group)
1027 "Read news in this newsgroup.
1028 If the prefix argument ALL is non-nil, already read articles become
1029 readable. IF ALL is a number, fetch this number of articles. If the
1030 optional argument NO-ARTICLE is non-nil, no article will be
1031 auto-selected upon group entry. If GROUP is non-nil, fetch that
1034 (let ((group (or group (gnus-group-group-name)))
1035 number active marked entry)
1036 (or group (error "No group on current line"))
1037 (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash
1038 group gnus-newsrc-hashtb)))))
1039 ;; This group might be a dead group. In that case we have to get
1040 ;; the number of unread articles from `gnus-active-hashtb'.
1042 (cond ((numberp all) all)
1044 ((setq active (gnus-active group))
1045 (- (1+ (cdr active)) (car active)))))
1046 (gnus-summary-read-group
1047 group (or all (and (numberp number)
1048 (zerop (+ number (gnus-range-length
1049 (cdr (assq 'tick marked)))
1051 (cdr (assq 'dormant marked)))))))
1054 (defun gnus-group-select-group (&optional all)
1055 "Select this newsgroup.
1056 No article is selected automatically.
1057 If ALL is non-nil, already read articles become readable.
1058 If ALL is a number, fetch this number of articles."
1060 (gnus-group-read-group all t))
1062 (defun gnus-group-quick-select-group (&optional all)
1063 "Select the current group \"quickly\".
1064 This means that no highlighting or scoring will be performed."
1067 gnus-score-find-score-files-function
1068 gnus-apply-kill-hook
1069 gnus-summary-expunge-below)
1070 (gnus-group-read-group all t)))
1072 (defun gnus-group-visible-select-group (&optional all)
1073 "Select the current group without hiding any articles."
1075 (let ((gnus-inhibit-limiting t))
1076 (gnus-group-read-group all t)))
1079 (defun gnus-fetch-group (group)
1080 "Start Gnus if necessary and enter GROUP.
1081 Returns whether the fetching was successful or not."
1082 (interactive "sGroup name: ")
1083 (or (get-buffer gnus-group-buffer)
1085 (gnus-group-read-group nil nil group))
1087 ;; Enter a group that is not in the group buffer. Non-nil is returned
1088 ;; if selection was successful.
1089 (defun gnus-group-read-ephemeral-group
1090 (group method &optional activate quit-config)
1091 (let ((group (if (gnus-group-foreign-p group) group
1092 (gnus-group-prefixed-name group method))))
1095 `(t nil (,group ,gnus-level-default-subscribed nil nil ,method
1096 ((quit-config . ,(if quit-config quit-config
1097 (cons (current-buffer) 'summary))))))
1099 (set-buffer gnus-group-buffer)
1100 (or (gnus-check-server method)
1101 (error "Unable to contact server: %s" (gnus-status-message method)))
1102 (if activate (or (gnus-request-group group)
1103 (error "Couldn't request group")))
1105 (gnus-group-read-group t t group)
1109 (defun gnus-group-jump-to-group (group)
1110 "Jump to newsgroup GROUP."
1112 (list (completing-read
1113 "Group: " gnus-active-hashtb nil
1114 (gnus-read-active-file-p)
1116 'gnus-group-history)))
1118 (when (equal group "")
1119 (error "Empty group name"))
1121 (when (string-match "[\000-\032]" group)
1122 (error "Control characters in group: %s" group))
1124 (let ((b (text-property-any
1125 (point-min) (point-max)
1126 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
1127 (unless (gnus-ephemeral-group-p group)
1129 ;; Either go to the line in the group buffer...
1131 ;; ... or insert the line.
1133 t ;; Don't activate group.
1135 (gnus-activate-group group)
1136 (error "%s error: %s" group (gnus-status-message group)))
1138 (gnus-group-update-group group)
1139 (goto-char (text-property-any
1140 (point-min) (point-max)
1141 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))
1142 ;; Adjust cursor point.
1143 (gnus-group-position-point)))
1145 (defun gnus-group-goto-group (group)
1146 "Goto to newsgroup GROUP."
1150 ;; It's quite likely that we are on the right line, so
1151 ;; we check the current line first.
1152 ((eq (get-text-property (point) 'gnus-group)
1153 (gnus-intern-safe group gnus-active-hashtb))
1155 ;; Previous and next line are also likely, so we check them as well.
1158 (eq (get-text-property (point) 'gnus-group)
1159 (gnus-intern-safe group gnus-active-hashtb)))
1164 (eq (get-text-property (point) 'gnus-group)
1165 (gnus-intern-safe group gnus-active-hashtb)))
1169 ;; Search through the entire buffer.
1172 (point-min) (point-max)
1173 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
1175 (defun gnus-group-next-group (n &optional silent)
1176 "Go to next N'th newsgroup.
1177 If N is negative, search backward instead.
1178 Returns the difference between N and the number of skips actually
1181 (gnus-group-next-unread-group n t nil silent))
1183 (defun gnus-group-next-unread-group (n &optional all level silent)
1184 "Go to next N'th unread newsgroup.
1185 If N is negative, search backward instead.
1186 If ALL is non-nil, choose any newsgroup, unread or not.
1187 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1188 such group can be found, the next group with a level higher than
1190 Returns the difference between N and the number of skips actually
1193 (let ((backward (< n 0))
1196 (gnus-group-search-forward
1197 backward (or (not gnus-group-goto-unread) all) level))
1201 (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1202 (if level " on this level or higher" "")))
1205 (defun gnus-group-prev-group (n)
1206 "Go to previous N'th newsgroup.
1207 Returns the difference between N and the number of skips actually
1210 (gnus-group-next-unread-group (- n) t))
1212 (defun gnus-group-prev-unread-group (n)
1213 "Go to previous N'th unread newsgroup.
1214 Returns the difference between N and the number of skips actually
1217 (gnus-group-next-unread-group (- n)))
1219 (defun gnus-group-next-unread-group-same-level (n)
1220 "Go to next N'th unread newsgroup on the same level.
1221 If N is negative, search backward instead.
1222 Returns the difference between N and the number of skips actually
1225 (gnus-group-next-unread-group n t (gnus-group-group-level))
1226 (gnus-group-position-point))
1228 (defun gnus-group-prev-unread-group-same-level (n)
1229 "Go to next N'th unread newsgroup on the same level.
1230 Returns the difference between N and the number of skips actually
1233 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1234 (gnus-group-position-point))
1236 (defun gnus-group-best-unread-group (&optional exclude-group)
1237 "Go to the group with the highest level.
1238 If EXCLUDE-GROUP, do not go to that group."
1240 (goto-char (point-min))
1244 (setq unread (get-text-property (point) 'gnus-unread))
1245 (if (and (numberp unread) (> unread 0))
1247 (if (and (get-text-property (point) 'gnus-level)
1248 (< (get-text-property (point) 'gnus-level) best)
1249 (or (not exclude-group)
1250 (not (equal exclude-group (gnus-group-group-name)))))
1252 (setq best (get-text-property (point) 'gnus-level))
1253 (setq best-point (point))))))
1255 (if best-point (goto-char best-point))
1256 (gnus-summary-position-point)
1257 (and best-point (gnus-group-group-name))))
1259 (defun gnus-group-first-unread-group ()
1260 "Go to the first group with unread articles."
1263 (let ((opoint (point))
1265 (goto-char (point-min))
1266 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1267 (and (numberp unread) ; Not a topic.
1268 (not (zerop unread))) ; Has unread articles.
1269 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1272 nil)) ; Not success.
1273 (gnus-group-position-point)))
1275 (defun gnus-group-enter-server-mode ()
1276 "Jump to the server buffer."
1278 (gnus-enter-server-buffer))
1280 (defun gnus-group-make-group (name &optional method address)
1281 "Add a new newsgroup.
1282 The user will be prompted for a NAME, for a select METHOD, and an
1286 (read-string "Group name: ")
1287 (gnus-read-server "From method: ")))
1289 (let* ((meth (when (and method
1290 (not (gnus-server-equal method gnus-select-method)))
1291 (if address (list (intern method) address)
1293 (nname (if method (gnus-group-prefixed-name name meth) name))
1295 (when (gnus-gethash nname gnus-newsrc-hashtb)
1296 (error "Group %s already exists" nname))
1297 ;; Subscribe to the new group.
1298 (gnus-group-change-level
1299 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1300 gnus-level-default-subscribed gnus-level-killed
1301 (and (gnus-group-group-name)
1302 (gnus-gethash (gnus-group-group-name)
1303 gnus-newsrc-hashtb))
1306 (gnus-set-active nname (cons 1 0))
1307 (or (gnus-ephemeral-group-p name)
1309 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
1311 (gnus-group-insert-group-line-info nname)
1313 (gnus-group-position-point)
1315 ;; Load the backend and try to make the backend create
1316 ;; the group as well.
1317 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
1319 gnus-valid-select-methods)
1321 (gnus-check-server meth)
1322 (and (gnus-check-backend-function 'request-create-group nname)
1323 (gnus-request-create-group nname))
1326 (defun gnus-group-delete-group (group &optional force)
1327 "Delete the current group. Only meaningful with mail groups.
1328 If FORCE (the prefix) is non-nil, all the articles in the group will
1329 be deleted. This is \"deleted\" as in \"removed forever from the face
1330 of the Earth\". There is no undo. The user will be prompted before
1331 doing the deletion."
1333 (list (gnus-group-group-name)
1334 current-prefix-arg))
1335 (or group (error "No group to rename"))
1336 (or (gnus-check-backend-function 'request-delete-group group)
1337 (error "This backend does not support group deletion"))
1339 (if (not (gnus-yes-or-no-p
1341 "Do you really want to delete %s%s? "
1342 group (if force " and all its contents" ""))))
1344 (gnus-message 6 "Deleting group %s..." group)
1345 (if (not (gnus-request-delete-group group force))
1346 (gnus-error 3 "Couldn't delete group %s" group)
1347 (gnus-message 6 "Deleting group %s...done" group)
1348 (gnus-group-goto-group group)
1349 (gnus-group-kill-group 1 t)
1350 (gnus-sethash group nil gnus-active-hashtb)
1352 (gnus-group-position-point)))
1354 (defun gnus-group-rename-group (group new-name)
1355 "Rename group from GROUP to NEW-NAME.
1356 When used interactively, GROUP is the group under point
1357 and NEW-NAME will be prompted for."
1360 (gnus-group-group-name)
1362 (unless (gnus-check-backend-function
1363 'request-rename-group (gnus-group-group-name))
1364 (error "This backend does not support renaming groups"))
1365 (read-string "New group name: " (gnus-group-group-name)))))
1367 (unless (gnus-check-backend-function 'request-rename-group group)
1368 (error "This backend does not support renaming groups"))
1370 (error "No group to rename"))
1371 (when (string-match "^[ \t]*$" new-name)
1372 (error "Not a valid group name"))
1373 (when (equal group new-name)
1374 (error "Can't rename to the same name"))
1376 ;; We find the proper prefixed name.
1378 (if (equal (gnus-group-real-name new-name) new-name)
1382 (gnus-group-prefixed-name
1383 (gnus-group-real-name new-name)
1384 (gnus-info-method (gnus-get-info group)))))
1386 (gnus-message 6 "Renaming group %s to %s..." group new-name)
1388 (if (not (gnus-request-rename-group group new-name))
1389 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
1390 ;; We rename the group internally by killing it...
1391 (gnus-group-goto-group group)
1392 (gnus-group-kill-group)
1393 ;; ... changing its name ...
1394 (setcar (cdar gnus-list-of-killed-groups) new-name)
1395 ;; ... and then yanking it. Magic!
1396 (gnus-group-yank-group)
1397 (gnus-set-active new-name (gnus-active group))
1398 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
1400 (gnus-group-position-point)))
1402 (defun gnus-group-edit-group (group &optional part)
1403 "Edit the group on the current line."
1404 (interactive (list (gnus-group-group-name)))
1405 (let ((part (or part 'info))
1408 (error "No group on current line"))
1409 (unless (setq info (gnus-get-info group))
1410 (error "Killed group; can't be edited"))
1412 ;; Find the proper form to edit.
1413 (cond ((eq part 'method)
1414 (or (gnus-info-method info) "native"))
1416 (gnus-info-params info))
1418 ;; The proper documentation.
1422 ((eq part 'method) "select method")
1423 ((eq part 'params) "group parameters")
1426 (gnus-group-edit-group-done ',part ,group form)))))
1428 (defun gnus-group-edit-group-method (group)
1429 "Edit the select method of GROUP."
1430 (interactive (list (gnus-group-group-name)))
1431 (gnus-group-edit-group group 'method))
1433 (defun gnus-group-edit-group-parameters (group)
1434 "Edit the group parameters of GROUP."
1435 (interactive (list (gnus-group-group-name)))
1436 (gnus-group-edit-group group 'params))
1438 (defun gnus-group-edit-group-done (part group form)
1440 (let* ((method (cond ((eq part 'info) (nth 4 form))
1441 ((eq part 'method) form)
1443 (info (cond ((eq part 'info) form)
1444 ((eq part 'method) (gnus-get-info group))
1447 (if (or (not method)
1449 gnus-select-method method))
1450 (gnus-group-real-name (car info))
1451 (gnus-group-prefixed-name
1452 (gnus-group-real-name (car info)) method))
1454 (when (and new-group
1455 (not (equal new-group group)))
1456 (when (gnus-group-goto-group group)
1457 (gnus-group-kill-group 1))
1458 (gnus-activate-group new-group))
1460 (if (not (and info new-group))
1461 (gnus-group-set-info form (or new-group group) part)
1462 (setq info (gnus-copy-sequence info))
1463 (setcar info new-group)
1464 (unless (gnus-server-equal method "native")
1465 (unless (nthcdr 3 info)
1466 (nconc info (list nil nil)))
1467 (unless (nthcdr 4 info)
1468 (nconc info (list nil)))
1469 (gnus-info-set-method info method))
1470 (gnus-group-set-info info))
1471 (gnus-group-update-group (or new-group group))
1472 (gnus-group-position-point)))
1474 (defun gnus-group-make-help-group ()
1475 "Create the Gnus documentation group."
1477 (let ((path load-path)
1478 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
1480 (and (gnus-gethash name gnus-newsrc-hashtb)
1481 (error "Documentation group already exists"))
1483 (setq dir (file-name-as-directory (expand-file-name (pop path)))
1485 (when (or (file-exists-p (setq file (concat dir "gnus-tut.txt")))
1487 (setq file (concat (file-name-directory
1488 (directory-file-name dir))
1489 "etc/gnus-tut.txt"))))
1492 (gnus-message 1 "Couldn't find doc group")
1493 (gnus-group-make-group
1494 (gnus-group-real-name name)
1495 (list 'nndoc "gnus-help"
1496 (list 'nndoc-address file)
1497 (list 'nndoc-article-type 'mbox)))))
1498 (gnus-group-position-point))
1500 (defun gnus-group-make-doc-group (file type)
1501 "Create a group that uses a single file as the source."
1503 (list (read-file-name "File name: ")
1504 (and current-prefix-arg 'ask)))
1505 (when (eq type 'ask)
1510 "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: "
1512 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
1513 ((= char ?b) 'babyl)
1514 ((= char ?d) 'digest)
1515 ((= char ?f) 'forward)
1517 (t (setq err (format "%c unknown. " char))
1520 (let* ((file (expand-file-name file))
1521 (name (gnus-generate-new-group-name
1522 (gnus-group-prefixed-name
1523 (file-name-nondirectory file) '(nndoc "")))))
1524 (gnus-group-make-group
1525 (gnus-group-real-name name)
1526 (list 'nndoc (file-name-nondirectory file)
1527 (list 'nndoc-address file)
1528 (list 'nndoc-article-type (or type 'guess))))))
1530 (defun gnus-group-make-archive-group (&optional all)
1531 "Create the (ding) Gnus archive group of the most recent articles.
1532 Given a prefix, create a full group."
1534 (let ((group (gnus-group-prefixed-name
1535 (if all "ding.archives" "ding.recent") '(nndir ""))))
1536 (when (gnus-gethash group gnus-newsrc-hashtb)
1537 (error "Archive group already exists"))
1538 (gnus-group-make-group
1539 (gnus-group-real-name group)
1540 (list 'nndir (if all "hpc" "edu")
1541 (list 'nndir-directory
1542 (if all gnus-group-archive-directory
1543 gnus-group-recent-archive-directory))))
1544 (gnus-group-add-parameter group (cons 'to-address "ding@ifi.uio.no"))))
1546 (defun gnus-group-make-directory-group (dir)
1547 "Create an nndir group.
1548 The user will be prompted for a directory. The contents of this
1549 directory will be used as a newsgroup. The directory should contain
1550 mail messages or news articles in files that have numeric names."
1552 (list (read-file-name "Create group from directory: ")))
1553 (or (file-exists-p dir) (error "No such directory"))
1554 (or (file-directory-p dir) (error "Not a directory"))
1558 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
1560 (gnus-group-prefixed-name
1561 (concat (file-name-as-directory (directory-file-name dir))
1564 (setq ext (format "<%d>" (setq i (1+ i)))))
1565 (gnus-group-make-group
1566 (gnus-group-real-name group)
1567 (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
1569 (defun gnus-group-make-kiboze-group (group address scores)
1570 "Create an nnkiboze group.
1571 The user will be prompted for a name, a regexp to match groups, and
1572 score file entries for articles to include in the group."
1575 (read-string "nnkiboze group name: ")
1576 (read-string "Source groups (regexp): ")
1577 (let ((headers (mapcar (lambda (group) (list group))
1578 '("subject" "from" "number" "date" "message-id"
1579 "references" "chars" "lines" "xref"
1580 "followup" "all" "body" "head")))
1581 scores header regexp regexps)
1582 (while (not (equal "" (setq header (completing-read
1583 "Match on header: " headers nil t))))
1585 (while (not (equal "" (setq regexp (read-string
1586 (format "Match on %s (string): "
1588 (setq regexps (cons (list regexp nil nil 'r) regexps)))
1589 (setq scores (cons (cons header regexps) scores)))
1591 (gnus-group-make-group group "nnkiboze" address)
1592 (nnheader-temp-write (gnus-score-file-name (concat "nnkiboze:" group))
1593 (let (emacs-lisp-mode-hook)
1594 (pp scores (current-buffer)))))
1596 (defun gnus-group-add-to-virtual (n vgroup)
1597 "Add the current group to a virtual group."
1599 (list current-prefix-arg
1600 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
1602 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
1603 (error "%s is not an nnvirtual group" vgroup))
1604 (let* ((groups (gnus-group-process-prefix n))
1605 (method (gnus-info-method (gnus-get-info vgroup))))
1606 (setcar (cdr method)
1608 (nth 1 method) "\\|"
1611 (gnus-group-remove-mark s)
1612 (concat "\\(^" (regexp-quote s) "$\\)"))
1614 (gnus-group-position-point))
1616 (defun gnus-group-make-empty-virtual (group)
1617 "Create a new, fresh, empty virtual group."
1618 (interactive "sCreate new, empty virtual group: ")
1619 (let* ((method (list 'nnvirtual "^$"))
1620 (pgroup (gnus-group-prefixed-name group method)))
1621 ;; Check whether it exists already.
1622 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
1623 (error "Group %s already exists." pgroup))
1624 ;; Subscribe the new group after the group on the current line.
1625 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
1626 (gnus-group-update-group pgroup)
1628 (gnus-group-position-point)))
1630 (defun gnus-group-enter-directory (dir)
1631 "Enter an ephemeral nneething group."
1632 (interactive "DDirectory to read: ")
1633 (let* ((method (list 'nneething dir))
1634 (leaf (gnus-group-prefixed-name
1635 (file-name-nondirectory (directory-file-name dir))
1637 (name (gnus-generate-new-group-name leaf)))
1638 (let ((nneething-read-only t))
1639 (or (gnus-group-read-ephemeral-group
1641 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
1643 (error "Couldn't enter %s" dir)))))
1645 ;; Group sorting commands
1646 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
1648 (defun gnus-group-sort-groups (func &optional reverse)
1649 "Sort the group buffer according to FUNC.
1650 If REVERSE, reverse the sorting order."
1651 (interactive (list gnus-group-sort-function
1652 current-prefix-arg))
1654 ((not (listp func)) func)
1656 ((= 1 (length func)) (car func))
1658 ,(gnus-make-sort-function
1659 (reverse func)))))))
1660 ;; We peel off the dummy group from the alist.
1662 (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group")
1663 (pop gnus-newsrc-alist))
1665 (setq gnus-newsrc-alist
1666 (sort gnus-newsrc-alist func))
1668 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
1669 ;; Regenerate the hash table.
1670 (gnus-make-hashtable-from-newsrc-alist)
1671 (gnus-group-list-groups))))
1673 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
1674 "Sort the group buffer alphabetically by group name.
1675 If REVERSE, sort in reverse order."
1677 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
1679 (defun gnus-group-sort-groups-by-unread (&optional reverse)
1680 "Sort the group buffer by number of unread articles.
1681 If REVERSE, sort in reverse order."
1683 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
1685 (defun gnus-group-sort-groups-by-level (&optional reverse)
1686 "Sort the group buffer by group level.
1687 If REVERSE, sort in reverse order."
1689 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
1691 (defun gnus-group-sort-groups-by-score (&optional reverse)
1692 "Sort the group buffer by group score.
1693 If REVERSE, sort in reverse order."
1695 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
1697 (defun gnus-group-sort-groups-by-rank (&optional reverse)
1698 "Sort the group buffer by group rank.
1699 If REVERSE, sort in reverse order."
1701 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
1703 (defun gnus-group-sort-groups-by-method (&optional reverse)
1704 "Sort the group buffer alphabetically by backend name.
1705 If REVERSE, sort in reverse order."
1707 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
1709 (defun gnus-group-sort-by-alphabet (info1 info2)
1710 "Sort alphabetically."
1711 (string< (gnus-info-group info1) (gnus-info-group info2)))
1713 (defun gnus-group-sort-by-unread (info1 info2)
1714 "Sort by number of unread articles."
1715 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
1716 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
1717 (< (or (and (numberp n1) n1) 0)
1718 (or (and (numberp n2) n2) 0))))
1720 (defun gnus-group-sort-by-level (info1 info2)
1722 (< (gnus-info-level info1) (gnus-info-level info2)))
1724 (defun gnus-group-sort-by-method (info1 info2)
1725 "Sort alphabetically by backend name."
1726 (string< (symbol-name (car (gnus-find-method-for-group
1727 (gnus-info-group info1) info1)))
1728 (symbol-name (car (gnus-find-method-for-group
1729 (gnus-info-group info2) info2)))))
1731 (defun gnus-group-sort-by-score (info1 info2)
1732 "Sort by group score."
1733 (< (gnus-info-score info1) (gnus-info-score info2)))
1735 (defun gnus-group-sort-by-rank (info1 info2)
1736 "Sort by level and score."
1737 (let ((level1 (gnus-info-level info1))
1738 (level2 (gnus-info-level info2)))
1739 (or (< level1 level2)
1740 (and (= level1 level2)
1741 (> (gnus-info-score info1) (gnus-info-score info2))))))
1743 ;; Group catching up.
1745 (defun gnus-group-clear-data (n)
1746 "Clear all marks and read ranges from the current group."
1748 (let ((groups (gnus-group-process-prefix n))
1750 (while (setq group (pop groups))
1751 (setq info (gnus-get-info group))
1752 (gnus-info-set-read info nil)
1753 (when (gnus-info-marks info)
1754 (gnus-info-set-marks info nil))
1755 (gnus-get-unread-articles-in-group info (gnus-active group) t)
1756 (when (gnus-group-goto-group group)
1757 (gnus-group-remove-mark group)
1758 (gnus-group-update-group-line)))))
1760 (defun gnus-group-catchup-current (&optional n all)
1761 "Mark all articles not marked as unread in current newsgroup as read.
1762 If prefix argument N is numeric, the ARG next newsgroups will be
1763 caught up. If ALL is non-nil, marked articles will also be marked as
1764 read. Cross references (Xref: header) of articles are ignored.
1765 The difference between N and actual number of newsgroups that were
1766 caught up is returned."
1768 (unless (gnus-group-group-name)
1769 (error "No group on the current line"))
1770 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
1774 "Do you really want to mark all articles as read? "
1775 "Mark all unread articles as read? "))))
1777 (let ((groups (gnus-group-process-prefix n))
1780 ;; Virtual groups have to be given special treatment.
1781 (let ((method (gnus-find-method-for-group (car groups))))
1782 (if (eq 'nnvirtual (car method))
1783 (nnvirtual-catchup-group
1784 (gnus-group-real-name (car groups)) (nth 1 method) all)))
1785 (gnus-group-remove-mark (car groups))
1786 (if (>= (gnus-group-group-level) gnus-level-zombie)
1787 (gnus-message 2 "Dead groups can't be caught up")
1789 (gnus-group-goto-group (car groups))
1790 (gnus-group-catchup (car groups) all))
1791 (gnus-group-update-group-line)
1792 (setq ret (1+ ret))))
1793 (setq groups (cdr groups)))
1794 (gnus-group-next-unread-group 1)
1797 (defun gnus-group-catchup-current-all (&optional n)
1798 "Mark all articles in current newsgroup as read.
1799 Cross references (Xref: header) of articles are ignored."
1801 (gnus-group-catchup-current n 'all))
1803 (defun gnus-group-catchup (group &optional all)
1804 "Mark all articles in GROUP as read.
1805 If ALL is non-nil, all articles are marked as read.
1806 The return value is the number of articles that were marked as read,
1807 or nil if no action could be taken."
1808 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
1810 ;; Do the updating only if the newsgroup isn't killed.
1811 (if (not (numberp (car entry)))
1812 (gnus-message 1 "Can't catch up; non-active group")
1813 ;; Do auto-expirable marks if that's required.
1814 (when (gnus-group-auto-expirable-p group)
1815 (gnus-add-marked-articles
1816 group 'expire (gnus-list-of-unread-articles group))
1818 (let ((marks (nth 3 (nth 2 entry))))
1819 (gnus-add-marked-articles
1820 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
1821 (gnus-add-marked-articles
1822 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
1824 (gnus-update-read-articles group nil)
1825 ;; Also nix out the lists of marks and dormants.
1827 (gnus-add-marked-articles group 'tick nil nil 'force)
1828 (gnus-add-marked-articles group 'dormant nil nil 'force))
1829 (run-hooks 'gnus-group-catchup-group-hook)
1832 (defun gnus-group-expire-articles (&optional n)
1833 "Expire all expirable articles in the current newsgroup."
1835 (let ((groups (gnus-group-process-prefix n))
1838 (error "No groups to expire"))
1839 (while (setq group (pop groups))
1840 (gnus-group-remove-mark group)
1841 (when (gnus-check-backend-function 'request-expire-articles group)
1842 (gnus-message 6 "Expiring articles in %s..." group)
1843 (let* ((info (gnus-get-info group))
1844 (expirable (if (gnus-group-total-expirable-p group)
1845 (cons nil (gnus-list-of-read-articles group))
1846 (assq 'expire (gnus-info-marks info))))
1847 (expiry-wait (gnus-group-get-parameter group 'expiry-wait)))
1851 (gnus-compress-sequence
1853 ;; We set the expiry variables to the groupp
1855 (let ((nnmail-expiry-wait-function nil)
1856 (nnmail-expiry-wait expiry-wait))
1857 (gnus-request-expire-articles
1858 (gnus-uncompress-sequence (cdr expirable)) group))
1859 ;; Just expire using the normal expiry values.
1860 (gnus-request-expire-articles
1861 (gnus-uncompress-sequence (cdr expirable)) group))))
1862 (gnus-close-group group))
1863 (gnus-message 6 "Expiring articles in %s...done" group)))
1864 (gnus-group-position-point))))
1866 (defun gnus-group-expire-all-groups ()
1867 "Expire all expirable articles in all newsgroups."
1870 (gnus-message 5 "Expiring...")
1871 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
1872 (cdr gnus-newsrc-alist))))
1873 (gnus-group-expire-articles nil)))
1874 (gnus-group-position-point)
1875 (gnus-message 5 "Expiring...done"))
1877 (defun gnus-group-set-current-level (n level)
1878 "Set the level of the next N groups to LEVEL."
1883 (let ((s (read-string
1884 (format "Level (default %s): "
1885 (or (gnus-group-group-level)
1886 gnus-level-default-subscribed)))))
1887 (if (string-match "^\\s-*$" s)
1888 (int-to-string (or (gnus-group-group-level)
1889 gnus-level-default-subscribed))
1891 (or (and (>= level 1) (<= level gnus-level-killed))
1892 (error "Illegal level: %d" level))
1893 (let ((groups (gnus-group-process-prefix n))
1895 (while (setq group (pop groups))
1896 (gnus-group-remove-mark group)
1897 (gnus-message 6 "Changed level of %s from %d to %d"
1898 group (or (gnus-group-group-level) gnus-level-killed)
1900 (gnus-group-change-level
1901 group level (or (gnus-group-group-level) gnus-level-killed))
1902 (gnus-group-update-group-line)))
1903 (gnus-group-position-point))
1905 (defun gnus-group-unsubscribe-current-group (&optional n)
1906 "Toggle subscription of the current group.
1907 If given numerical prefix, toggle the N next groups."
1909 (let ((groups (gnus-group-process-prefix n))
1912 (setq group (car groups)
1913 groups (cdr groups))
1914 (gnus-group-remove-mark group)
1915 (gnus-group-unsubscribe-group
1916 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
1917 gnus-level-default-unsubscribed
1918 gnus-level-default-subscribed) t)
1919 (gnus-group-update-group-line))
1920 (gnus-group-next-group 1)))
1922 (defun gnus-group-unsubscribe-group (group &optional level silent)
1923 "Toggle subscription to GROUP.
1924 Killed newsgroups are subscribed. If SILENT, don't try to update the
1927 (list (completing-read
1928 "Group: " gnus-active-hashtb nil
1929 (gnus-read-active-file-p)
1931 'gnus-group-history)))
1932 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
1934 ((string-match "^[ \t]$" group)
1935 (error "Empty group name"))
1937 ;; Toggle subscription flag.
1938 (gnus-group-change-level
1939 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
1940 gnus-level-subscribed)
1941 (1+ gnus-level-subscribed)
1942 gnus-level-default-subscribed)))
1944 (gnus-group-update-group group)))
1945 ((and (stringp group)
1946 (or (not (gnus-read-active-file-p))
1947 (gnus-active group)))
1948 ;; Add new newsgroup.
1949 (gnus-group-change-level
1951 (if level level gnus-level-default-subscribed)
1952 (or (and (member group gnus-zombie-list)
1955 (and (gnus-group-group-name)
1956 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
1958 (gnus-group-update-group group)))
1959 (t (error "No such newsgroup: %s" group)))
1960 (gnus-group-position-point)))
1962 (defun gnus-group-transpose-groups (n)
1963 "Move the current newsgroup up N places.
1964 If given a negative prefix, move down instead. The difference between
1965 N and the number of steps taken is returned."
1967 (or (gnus-group-group-name)
1968 (error "No group on current line"))
1969 (gnus-group-kill-group 1)
1971 (forward-line (- n))
1972 (gnus-group-yank-group)
1973 (gnus-group-position-point)))
1975 (defun gnus-group-kill-all-zombies ()
1976 "Kill all zombie newsgroups."
1978 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
1979 (setq gnus-zombie-list nil)
1980 (gnus-group-list-groups))
1982 (defun gnus-group-kill-region (begin end)
1983 "Kill newsgroups in current region (excluding current point).
1984 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
1999 (beginning-of-line) ;Important when LINES < 1
2000 (gnus-group-kill-group lines)))
2002 (defun gnus-group-kill-group (&optional n discard)
2003 "Kill the next N groups.
2004 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2005 However, only groups that were alive can be yanked; already killed
2006 groups or zombie groups can't be yanked.
2007 The return value is the name of the group that was killed, or a list
2010 (let ((buffer-read-only nil)
2011 (groups (gnus-group-process-prefix n))
2012 group entry level out)
2013 (if (< (length groups) 10)
2014 ;; This is faster when there are few groups.
2016 (push (setq group (pop groups)) out)
2017 (gnus-group-remove-mark group)
2018 (setq level (gnus-group-group-level))
2020 (when (and (not discard)
2021 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
2022 (push (cons (car entry) (nth 2 entry))
2023 gnus-list-of-killed-groups))
2024 (gnus-group-change-level
2025 (if entry entry group) gnus-level-killed (if entry nil level)))
2026 ;; If there are lots and lots of groups to be killed, we use
2027 ;; this thing instead.
2029 (setq groups (nreverse groups))
2031 (gnus-group-remove-mark (setq group (pop groups)))
2033 (push group gnus-killed-list)
2034 (setq gnus-newsrc-alist
2035 (delq (assoc group gnus-newsrc-alist)
2037 (when gnus-group-change-level-function
2038 (funcall gnus-group-change-level-function group 9 3))
2040 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
2041 (push (cons (car entry) (nth 2 entry))
2042 gnus-list-of-killed-groups)
2043 (setcdr (cdr entry) (cdddr entry)))
2044 ((member group gnus-zombie-list)
2045 (setq gnus-zombie-list (delete group gnus-zombie-list)))))
2046 (gnus-make-hashtable-from-newsrc-alist)))
2048 (gnus-group-position-point)
2049 (if (< (length out) 2) (car out) (nreverse out))))
2051 (defun gnus-group-yank-group (&optional arg)
2052 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
2053 inserting it before the current newsgroup. The numeric ARG specifies
2054 how many newsgroups are to be yanked. The name of the newsgroup yanked
2055 is returned, or (if several groups are yanked) a list of yanked groups
2058 (setq arg (or arg 1))
2059 (let (info group prev out)
2060 (while (>= (decf arg) 0)
2061 (if (not (setq info (pop gnus-list-of-killed-groups)))
2062 (error "No more newsgroups to yank"))
2063 (push (setq group (nth 1 info)) out)
2064 ;; Find which newsgroup to insert this one before - search
2065 ;; backward until something suitable is found. If there are no
2066 ;; other newsgroups in this buffer, just make this newsgroup the
2068 (setq prev (gnus-group-group-name))
2069 (gnus-group-change-level
2070 info (gnus-info-level (cdr info)) gnus-level-killed
2071 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
2073 (gnus-group-insert-group-line-info group))
2075 (gnus-group-position-point)
2076 (if (< (length out) 2) (car out) (nreverse out))))
2078 (defun gnus-group-kill-level (level)
2079 "Kill all groups that is on a certain LEVEL."
2080 (interactive "nKill all groups on level: ")
2082 ((= level gnus-level-zombie)
2083 (setq gnus-killed-list
2084 (nconc gnus-zombie-list gnus-killed-list))
2085 (setq gnus-zombie-list nil))
2086 ((and (< level gnus-level-zombie)
2088 (or gnus-expert-user
2091 "Do you really want to kill all groups on level %d? "
2093 (let* ((prev gnus-newsrc-alist)
2096 (if (= (gnus-info-level (car alist)) level)
2098 (push (gnus-info-group (car alist)) gnus-killed-list)
2099 (setcdr prev (cdr alist)))
2101 (setq alist (cdr alist)))
2102 (gnus-make-hashtable-from-newsrc-alist)
2103 (gnus-group-list-groups)))
2105 (error "Can't kill; illegal level: %d" level))))
2107 (defun gnus-group-list-all-groups (&optional arg)
2108 "List all newsgroups with level ARG or lower.
2109 Default is gnus-level-unsubscribed, which lists all subscribed and most
2110 unsubscribed groups."
2112 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
2114 ;; Redefine this to list ALL killed groups if prefix arg used.
2115 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
2116 (defun gnus-group-list-killed (&optional arg)
2117 "List all killed newsgroups in the group buffer.
2118 If ARG is non-nil, list ALL killed groups known to Gnus. This may
2119 entail asking the server for the groups."
2121 ;; Find all possible killed newsgroups if arg.
2123 (gnus-get-killed-groups))
2124 (if (not gnus-killed-list)
2125 (gnus-message 6 "No killed groups")
2126 (let (gnus-group-list-mode)
2127 (funcall gnus-group-prepare-function
2128 gnus-level-killed t gnus-level-killed))
2129 (goto-char (point-min)))
2130 (gnus-group-position-point))
2132 (defun gnus-group-list-zombies ()
2133 "List all zombie newsgroups in the group buffer."
2135 (if (not gnus-zombie-list)
2136 (gnus-message 6 "No zombie groups")
2137 (let (gnus-group-list-mode)
2138 (funcall gnus-group-prepare-function
2139 gnus-level-zombie t gnus-level-zombie))
2140 (goto-char (point-min)))
2141 (gnus-group-position-point))
2143 (defun gnus-group-list-active ()
2144 "List all groups that are available from the server(s)."
2146 ;; First we make sure that we have really read the active file.
2147 (unless (gnus-read-active-file-p)
2148 (let ((gnus-read-active-file t))
2149 (gnus-read-active-file)))
2150 ;; Find all groups and sort them.
2158 (setq list (cons (symbol-name sym) list))))
2162 (buffer-read-only nil))
2165 (gnus-group-insert-group-line-info (pop groups)))
2166 (goto-char (point-min))))
2168 (defun gnus-activate-all-groups (level)
2169 "Activate absolutely all groups."
2170 (interactive (list 7))
2171 (let ((gnus-activate-level level)
2172 (gnus-activate-foreign-newsgroups level))
2173 (gnus-group-get-new-news)))
2175 (defun gnus-group-get-new-news (&optional arg)
2176 "Get newly arrived articles.
2177 If ARG is a number, it specifies which levels you are interested in
2178 re-scanning. If ARG is non-nil and not a number, this will force
2179 \"hard\" re-reading of the active files from all servers."
2181 (run-hooks 'gnus-get-new-news-hook)
2182 ;; We might read in new NoCeM messages here.
2183 (when (and gnus-use-nocem
2185 (gnus-nocem-scan-groups))
2186 ;; If ARG is not a number, then we read the active file.
2187 (when (and arg (not (numberp arg)))
2188 (let ((gnus-read-active-file t))
2189 (gnus-read-active-file))
2192 (setq arg (gnus-group-default-level arg t))
2193 (if (and gnus-read-active-file (not arg))
2195 (gnus-read-active-file)
2196 (gnus-get-unread-articles arg))
2197 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
2198 (gnus-get-unread-articles arg)))
2199 (run-hooks 'gnus-after-getting-new-news-hook)
2200 (gnus-group-list-groups))
2202 (defun gnus-group-get-new-news-this-group (&optional n)
2203 "Check for newly arrived news in the current group (and the N-1 next groups).
2204 The difference between N and the number of newsgroup checked is returned.
2205 If N is negative, this group and the N-1 previous groups will be checked."
2207 (let* ((groups (gnus-group-process-prefix n))
2208 (ret (if (numberp n) (- n (length groups)) 0))
2209 (beg (unless n (point)))
2211 (while (setq group (pop groups))
2212 (gnus-group-remove-mark group)
2213 (if (gnus-activate-group group 'scan)
2215 (gnus-get-unread-articles-in-group
2216 (gnus-get-info group) (gnus-active group) t)
2217 (unless (gnus-virtual-group-p group)
2218 (gnus-close-group group))
2219 (gnus-group-update-group group))
2220 (if (eq (gnus-server-status (gnus-find-method-for-group group))
2222 (gnus-error "Server denied access")
2223 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
2224 (when beg (goto-char beg))
2225 (when gnus-goto-next-group-when-activating
2226 (gnus-group-next-unread-group 1 t))
2227 (gnus-summary-position-point)
2230 (defun gnus-group-fetch-faq (group &optional faq-dir)
2231 "Fetch the FAQ for the current group."
2234 (and (gnus-group-group-name)
2235 (gnus-group-real-name (gnus-group-group-name)))
2236 (cond (current-prefix-arg
2238 "Faq dir: " (and (listp gnus-group-faq-directory)
2239 (mapcar (lambda (file) (list file))
2240 gnus-group-faq-directory)))))))
2242 (setq faq-dir (if (listp gnus-group-faq-directory)
2243 (car gnus-group-faq-directory)
2244 gnus-group-faq-directory)))
2245 (or group (error "No group name given"))
2246 (let ((file (concat (file-name-as-directory faq-dir)
2247 (gnus-group-real-name group))))
2248 (if (not (file-exists-p file))
2249 (error "No such file: %s" file)
2252 (defun gnus-group-describe-group (force &optional group)
2253 "Display a description of the current newsgroup."
2254 (interactive (list current-prefix-arg (gnus-group-group-name)))
2255 (let* ((method (gnus-find-method-for-group group))
2256 (mname (gnus-group-prefixed-name "" method))
2259 gnus-description-hashtb)
2260 (gnus-sethash mname nil gnus-description-hashtb))
2261 (or group (error "No group name given"))
2262 (and (or (and gnus-description-hashtb
2263 ;; We check whether this group's method has been
2264 ;; queried for a description file.
2265 (gnus-gethash mname gnus-description-hashtb))
2266 (setq desc (gnus-group-get-description group))
2267 (gnus-read-descriptions-file method))
2269 (or desc (gnus-gethash group gnus-description-hashtb)
2270 "No description available")))))
2272 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2273 (defun gnus-group-describe-all-groups (&optional force)
2274 "Pop up a buffer with descriptions of all newsgroups."
2276 (and force (setq gnus-description-hashtb nil))
2277 (if (not (or gnus-description-hashtb
2278 (gnus-read-all-descriptions-files)))
2279 (error "Couldn't request descriptions file"))
2280 (let ((buffer-read-only nil)
2286 (insert (format " *: %-20s %s\n" (symbol-name group)
2287 (symbol-value group)))
2288 (gnus-add-text-properties
2289 b (1+ b) (list 'gnus-group group
2290 'gnus-unread t 'gnus-marked nil
2291 'gnus-level (1+ gnus-level-subscribed))))
2292 gnus-description-hashtb)
2293 (goto-char (point-min))
2294 (gnus-group-position-point)))
2296 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2297 (defun gnus-group-apropos (regexp &optional search-description)
2298 "List all newsgroups that have names that match a regexp."
2299 (interactive "sGnus apropos (regexp): ")
2301 (obuf (current-buffer))
2303 ;; Go through all newsgroups that are known to Gnus.
2306 (and (symbol-name group)
2307 (string-match regexp (symbol-name group))
2308 (setq groups (cons (symbol-name group) groups))))
2310 ;; Also go through all descriptions that are known to Gnus.
2311 (when search-description
2314 (and (string-match regexp (symbol-value group))
2315 (gnus-active (symbol-name group))
2316 (setq groups (cons (symbol-name group) groups))))
2317 gnus-description-hashtb))
2319 (gnus-message 3 "No groups matched \"%s\"." regexp)
2320 ;; Print out all the groups.
2322 (pop-to-buffer "*Gnus Help*")
2323 (buffer-disable-undo (current-buffer))
2325 (setq groups (sort groups 'string<))
2327 ;; Groups may be entered twice into the list of groups.
2328 (if (not (string= (car groups) prev))
2330 (insert (setq prev (car groups)) "\n")
2331 (if (and gnus-description-hashtb
2332 (setq des (gnus-gethash (car groups)
2333 gnus-description-hashtb)))
2334 (insert " " des "\n"))))
2335 (setq groups (cdr groups)))
2336 (goto-char (point-min))))
2337 (pop-to-buffer obuf)))
2339 (defun gnus-group-description-apropos (regexp)
2340 "List all newsgroups that have names or descriptions that match a regexp."
2341 (interactive "sGnus description apropos (regexp): ")
2342 (if (not (or gnus-description-hashtb
2343 (gnus-read-all-descriptions-files)))
2344 (error "Couldn't request descriptions file"))
2345 (gnus-group-apropos regexp t))
2347 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2348 (defun gnus-group-list-matching (level regexp &optional all lowest)
2349 "List all groups with unread articles that match REGEXP.
2350 If the prefix LEVEL is non-nil, it should be a number that says which
2351 level to cut off listing groups.
2352 If ALL, also list groups with no unread articles.
2353 If LOWEST, don't list groups with level lower than LOWEST.
2355 This command may read the active file."
2356 (interactive "P\nsList newsgroups matching: ")
2357 ;; First make sure active file has been read.
2359 (> (prefix-numeric-value level) gnus-level-killed))
2360 (gnus-get-killed-groups))
2361 (gnus-group-prepare-flat (or level gnus-level-subscribed)
2362 all (or lowest 1) regexp)
2363 (goto-char (point-min))
2364 (gnus-group-position-point))
2366 (defun gnus-group-list-all-matching (level regexp &optional lowest)
2367 "List all groups that match REGEXP.
2368 If the prefix LEVEL is non-nil, it should be a number that says which
2369 level to cut off listing groups.
2370 If LOWEST, don't list groups with level lower than LOWEST."
2371 (interactive "P\nsList newsgroups matching: ")
2372 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
2374 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
2375 (defun gnus-group-save-newsrc (&optional force)
2376 "Save the Gnus startup files.
2377 If FORCE, force saving whether it is necessary or not."
2379 (gnus-save-newsrc-file force))
2381 (defun gnus-group-restart (&optional arg)
2382 "Force Gnus to read the .newsrc file."
2384 (when (gnus-yes-or-no-p
2385 (format "Are you sure you want to read %s? "
2386 gnus-current-startup-file))
2387 (gnus-save-newsrc-file)
2388 (gnus-setup-news 'force)
2389 (gnus-group-list-groups arg)))
2391 (defun gnus-group-read-init-file ()
2392 "Read the Gnus elisp init file."
2394 (gnus-read-init-file))
2396 (defun gnus-group-check-bogus-groups (&optional silent)
2397 "Check bogus newsgroups.
2398 If given a prefix, don't ask for confirmation before removing a bogus
2401 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
2402 (gnus-group-list-groups))
2404 (defun gnus-group-edit-global-kill (&optional article group)
2405 "Edit the global kill file.
2406 If GROUP, edit that local kill file instead."
2408 (setq gnus-current-kill-article article)
2409 (gnus-kill-file-edit-file group)
2412 (substitute-command-keys
2413 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
2414 (if group "local" "global")))))
2416 (defun gnus-group-edit-local-kill (article group)
2417 "Edit a local kill file."
2418 (interactive (list nil (gnus-group-group-name)))
2419 (gnus-group-edit-global-kill article group))
2421 (defun gnus-group-force-update ()
2422 "Update `.newsrc' file."
2424 (gnus-save-newsrc-file))
2426 (defun gnus-group-suspend ()
2427 "Suspend the current Gnus session.
2428 In fact, cleanup buffers except for group mode buffer.
2429 The hook gnus-suspend-gnus-hook is called before actually suspending."
2431 (run-hooks 'gnus-suspend-gnus-hook)
2432 ;; Kill Gnus buffers except for group mode buffer.
2433 (let* ((group-buf (get-buffer gnus-group-buffer))
2434 ;; Do this on a separate list in case the user does a ^G before we finish
2436 (delete group-buf (delete gnus-dribble-buffer
2437 (append gnus-buffer-list nil)))))
2438 (while gnus-buffer-list
2439 (gnus-kill-buffer (pop gnus-buffer-list)))
2440 (gnus-kill-gnus-frames)
2442 (setq gnus-buffer-list (list group-buf))
2443 (bury-buffer group-buf)
2444 (delete-windows-on group-buf t))))
2446 (defun gnus-group-clear-dribble ()
2447 "Clear all information from the dribble buffer."
2449 (gnus-dribble-clear)
2450 (gnus-message 7 "Cleared dribble buffer"))
2452 (defun gnus-group-exit ()
2453 "Quit reading news after updating .newsrc.eld and .newsrc.
2454 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2457 (or noninteractive ;For gnus-batch-kill
2458 (not gnus-interactive-exit) ;Without confirmation
2460 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
2461 (run-hooks 'gnus-exit-gnus-hook)
2462 ;; Offer to save data from non-quitted summary buffers.
2463 (gnus-offer-save-summaries)
2464 ;; Save the newsrc file(s).
2465 (gnus-save-newsrc-file)
2467 (gnus-close-backends)
2468 ;; Reset everything.
2470 ;; Allow the user to do things after cleaning up.
2471 (run-hooks 'gnus-after-exiting-gnus-hook)))
2473 (defun gnus-group-quit ()
2474 "Quit reading news without updating .newsrc.eld or .newsrc.
2475 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2477 (when (or noninteractive ;For gnus-batch-kill
2478 (zerop (buffer-size))
2479 (not (gnus-server-opened gnus-select-method))
2481 (not gnus-current-startup-file)
2483 (format "Quit reading news without saving %s? "
2484 (file-name-nondirectory gnus-current-startup-file))))
2485 (run-hooks 'gnus-exit-gnus-hook)
2486 (gnus-configure-windows 'group t)
2488 (gnus-close-backends)
2490 (gnus-kill-buffer gnus-group-buffer)
2491 ;; Allow the user to do things after cleaning up.
2492 (run-hooks 'gnus-after-exiting-gnus-hook)))
2494 (defun gnus-group-describe-briefly ()
2495 "Give a one line description of the group mode commands."
2497 (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")))
2499 (defun gnus-group-browse-foreign-server (method)
2500 "Browse a foreign news server.
2501 If called interactively, this function will ask for a select method
2502 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
2503 If not, METHOD should be a list where the first element is the method
2504 and the second element is the address."
2506 (list (let ((how (completing-read
2508 (append gnus-valid-select-methods gnus-server-alist)
2509 nil t (cons "nntp" 0) 'gnus-method-history)))
2510 ;; We either got a backend name or a virtual server name.
2511 ;; If the first, we also need an address.
2512 (if (assoc how gnus-valid-select-methods)
2514 ;; Suggested by mapjph@bath.ac.uk.
2517 (mapcar (lambda (server) (list server))
2518 gnus-secondary-servers)))
2519 ;; We got a server name, so we find the method.
2520 (gnus-server-to-method how)))))
2521 (gnus-browse-foreign-server method))
2523 (defun gnus-group-set-info (info &optional method-only-group part)
2524 (let* ((entry (gnus-gethash
2525 (or method-only-group (gnus-info-group info))
2526 gnus-newsrc-hashtb))
2528 (info (if method-only-group (nth 2 entry) info))
2530 (when method-only-group
2532 (error "Trying to change non-existent group %s" method-only-group))
2533 ;; We have received parts of the actual group info - either the
2534 ;; select method or the group parameters. We first check
2535 ;; whether we have to extend the info, and if so, do that.
2536 (let ((len (length info))
2537 (total (if (eq part 'method) 5 6)))
2539 (setcdr (nthcdr (1- len) info)
2540 (make-list (- total len) nil)))
2541 ;; Then we enter the new info.
2542 (setcar (nthcdr (1- total) info) part-info)))
2544 ;; This is a new group, so we just create it.
2546 (set-buffer gnus-group-buffer)
2547 (setq method (gnus-info-method info))
2548 (when (gnus-server-equal method "native")
2551 (set-buffer gnus-group-buffer)
2553 ;; It's a foreign group...
2554 (gnus-group-make-group
2555 (gnus-group-real-name (gnus-info-group info))
2556 (if (stringp method) method
2557 (prin1-to-string (car method)))
2559 (nth 1 (gnus-info-method info))))
2560 ;; It's a native group.
2561 (gnus-group-make-group (gnus-info-group info))))
2562 (gnus-message 6 "Note: New group created")
2564 (gnus-gethash (gnus-group-prefixed-name
2565 (gnus-group-real-name (gnus-info-group info))
2566 (or (gnus-info-method info) gnus-select-method))
2567 gnus-newsrc-hashtb))))
2568 ;; Whether it was a new group or not, we now have the entry, so we
2569 ;; can do the update.
2572 (setcar (nthcdr 2 entry) info)
2573 (when (and (not (eq (car entry) t))
2574 (gnus-active (gnus-info-group info)))
2575 (setcar entry (length (gnus-list-of-unread-articles (car info))))))
2576 (error "No such group: %s" (gnus-info-group info)))))
2578 (defun gnus-group-set-method-info (group select-method)
2579 (gnus-group-set-info select-method group 'method))
2581 (defun gnus-group-set-params-info (group params)
2582 (gnus-group-set-info params group 'params))
2584 (defun gnus-add-marked-articles (group type articles &optional info force)
2585 ;; Add ARTICLES of TYPE to the info of GROUP.
2586 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
2587 ;; add, but replace marked articles of TYPE with ARTICLES.
2588 (let ((info (or info (gnus-get-info group)))
2589 (uncompressed '(score bookmark killed))
2592 (and (not (setq marked (nthcdr 3 info)))
2594 (setcdr (nthcdr 2 info)
2595 (list (list (cons type (gnus-compress-sequence
2597 (and (not (setq m (assq type (car marked))))
2600 (cons (cons type (gnus-compress-sequence articles t) )
2604 (setcar (nthcdr 3 info)
2605 (delq (assq type (car marked)) (car marked)))
2606 (setcdr m (gnus-compress-sequence articles t)))
2607 (setcdr m (gnus-compress-sequence
2608 (sort (nconc (gnus-uncompress-range (cdr m))
2609 (copy-sequence articles)) '<) t))))))
2611 (defun gnus-update-read-articles (group unread)
2612 "Update the list of read and ticked articles in GROUP using the
2613 UNREAD and TICKED lists.
2614 Note: UNSELECTED has to be sorted over `<'.
2615 Returns whether the updating was successful."
2616 (let* ((active (or gnus-newsgroup-active (gnus-active group)))
2617 (entry (gnus-gethash group gnus-newsrc-hashtb))
2618 (info (nth 2 entry))
2620 (unread (sort (copy-sequence unread) '<))
2622 (if (or (not info) (not active))
2623 ;; There is no info on this group if it was, in fact,
2624 ;; killed. Gnus stores no information on killed groups, so
2625 ;; there's nothing to be done.
2626 ;; One could store the information somewhere temporarily,
2627 ;; perhaps... Hmmm...
2629 ;; Remove any negative articles numbers.
2630 (while (and unread (< (car unread) 0))
2631 (setq unread (cdr unread)))
2632 ;; Remove any expired article numbers
2633 (while (and unread (< (car unread) (car active)))
2634 (setq unread (cdr unread)))
2635 ;; Compute the ranges of read articles by looking at the list of
2638 (if (/= (car unread) prev)
2639 (setq read (cons (if (= prev (1- (car unread))) prev
2640 (cons prev (1- (car unread)))) read)))
2641 (setq prev (1+ (car unread)))
2642 (setq unread (cdr unread)))
2643 (when (<= prev (cdr active))
2644 (setq read (cons (cons prev (cdr active)) read)))
2645 ;; Enter this list into the group info.
2647 info (if (> (length read) 1) (nreverse read) read))
2648 ;; Set the number of unread articles in gnus-newsrc-hashtb.
2649 (gnus-get-unread-articles-in-group info (gnus-active group))
2652 (provide 'gnus-group)
2654 ;;; gnus-group.el ends here