Correctly use hidden.
[gnus] / lisp / gnus-topic.el
index 03bb313..88fe35d 100644 (file)
@@ -1,5 +1,6 @@
 ;;; gnus-topic.el --- a folding minor mode for Gnus group buffers
-;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
+;;        Free Software Foundation, Inc.
 
 ;; Author: Ilja Weis <kult@uni-paderborn.de>
 ;;     Lars Magne Ingebrigtsen <larsi@gnus.org>
@@ -149,11 +150,20 @@ with some simple extensions.
       (gnus-group-topic group))))
 
 (defun gnus-topic-goto-topic (topic)
-  "Go to TOPIC."
   (when topic
     (gnus-goto-char (text-property-any (point-min) (point-max)
                                       'gnus-topic (intern topic)))))
 
+(defun gnus-topic-jump-to-topic (topic)
+  "Go to TOPIC."
+  (interactive
+   (list (completing-read "Go to topic: "
+                         (mapcar 'list (gnus-topic-list))
+                         nil t)))
+  (dolist (topic (gnus-current-topics topic))
+    (gnus-topic-fold t))
+  (gnus-topic-goto-topic topic))
+  
 (defun gnus-current-topic ()
   "Return the name of the current topic."
   (let ((result
@@ -203,16 +213,17 @@ If TOPIC, start with that topic."
                         (if (member group gnus-zombie-list)
                             gnus-level-zombie gnus-level-killed))))
       (and
-       unread                          ; nil means that the group is dead.
+       info                            ; nil means that the group is dead.
        (<= clevel level)
        (>= clevel lowest)              ; Is inside the level we want.
        (or all
-          (if (eq unread t)
+          (if (or (eq unread t)
+                  (eq unread nil))
               gnus-group-list-inactive-groups
             (> unread 0))
           (and gnus-list-groups-with-ticked-articles
                (cdr (assq 'tick (gnus-info-marks info))))
-                                       ; Has right readedness.
+          ;; Has right readedness.
           ;; Check for permanent visibility.
           (and gnus-permanently-visible-groups
                (string-match gnus-permanently-visible-groups group))
@@ -361,7 +372,8 @@ If TOPIC, start with that topic."
 
 ;;; Generating group buffers
 
-(defun gnus-group-prepare-topics (level &optional all lowest regexp list-topic topic-level)
+(defun gnus-group-prepare-topics (level &optional all lowest
+                                       regexp list-topic topic-level)
   "List all newsgroups with unread articles of level LEVEL or lower.
 Use the `gnus-group-topics' to sort the groups.
 If ALL is non-nil, list groups that have no unread articles.
@@ -416,7 +428,7 @@ articles in the topic and its subtopics."
         (entries (gnus-topic-find-groups
                   (car type) list-level
                   (or all
-                      (cdr (assq 'visible 
+                      (cdr (assq 'visible
                                  (gnus-topic-hierarchical-parameters
                                   (car type)))))
                   lowest))
@@ -493,7 +505,7 @@ articles in the topic and its subtopics."
       (let ((data (cadr (gnus-topic-find-topology topic))))
        (setcdr data
                (list (if insert 'visible 'invisible)
-                     (if hide 'hide nil)
+                     hide
                      (cadddr data))))
       (if total-remove
          (setq gnus-topic-alist
@@ -506,9 +518,9 @@ articles in the topic and its subtopics."
    (car gnus-group-list-mode) (cdr gnus-group-list-mode)
    nil nil topic level))
 
-(defun gnus-topic-fold (&optional insert)
+(defun gnus-topic-fold (&optional insert topic)
   "Remove/insert the current topic."
-  (let ((topic (gnus-group-topic-name)))
+  (let ((topic (or topic (gnus-group-topic-name))))
     (when topic
       (save-excursion
        (if (not (gnus-group-active-topic-p))
@@ -532,15 +544,16 @@ articles in the topic and its subtopics."
     (gnus-topic-update-unreads name unread)
     (beginning-of-line)
     ;; Insert the text.
-    (gnus-add-text-properties
-     (point)
-     (prog1 (1+ (point))
-       (eval gnus-topic-line-format-spec))
-     (list 'gnus-topic (intern name)
-          'gnus-topic-level level
-          'gnus-topic-unread unread
-          'gnus-active active-topic
-          'gnus-topic-visible visiblep))))
+    (if shownp
+       (gnus-add-text-properties
+        (point)
+        (prog1 (1+ (point))
+          (eval gnus-topic-line-format-spec))
+        (list 'gnus-topic (intern name)
+              'gnus-topic-level level
+              'gnus-topic-unread unread
+              'gnus-active active-topic
+              'gnus-topic-visible visiblep)))))
 
 (defun gnus-topic-update-unreads (topic unreads)
   (setq gnus-topic-unreads (delq (assoc topic gnus-topic-unreads)
@@ -583,7 +596,8 @@ articles in the topic and its subtopics."
   (let* ((topic (gnus-group-topic group))
         (groups (cdr (assoc topic gnus-topic-alist)))
         (g (cdr (member group groups)))
-        (unfound t))
+        (unfound t)
+        entry)
     ;; Try to jump to a visible group.
     (while (and g (not (gnus-group-goto-group (car g) t)))
       (pop g))
@@ -597,8 +611,20 @@ articles in the topic and its subtopics."
       (when (and unfound
                 topic
                 (not (gnus-topic-goto-missing-topic topic)))
-       (gnus-topic-insert-topic-line
-        topic t t (car (gnus-topic-find-topology topic)) nil 0)))))
+       (let* ((top (gnus-topic-find-topology topic))
+              (children (cddr top))
+              (type (cadr top))
+              (unread 0)
+              (entries (gnus-topic-find-groups
+                        (car type) (car gnus-group-list-mode)
+                        (cdr gnus-group-list-mode))))
+         (while children
+           (incf unread (gnus-topic-unread (caar (pop children)))))
+         (while (setq entry (pop entries))
+           (when (numberp (car entry))
+             (incf unread (car entry))))
+         (gnus-topic-insert-topic-line
+          topic t t (car (gnus-topic-find-topology topic)) nil unread))))))
 
 (defun gnus-topic-goto-missing-topic (topic)
   (if (gnus-topic-goto-topic topic)
@@ -607,15 +633,18 @@ articles in the topic and its subtopics."
     (let* ((top (gnus-topic-find-topology
                 (gnus-topic-parent-topic topic)))
           (tp (reverse (cddr top))))
-      (while (not (equal (caaar tp) topic))
-       (setq tp (cdr tp)))
-      (pop tp)
-      (while (and tp
-                 (not (gnus-topic-goto-topic (caaar tp))))
-       (pop tp))
-      (if tp
-         (gnus-topic-forward-topic 1)
-       (gnus-topic-goto-missing-topic (caadr top))))
+      (if (not top)
+         (gnus-topic-insert-topic-line
+          topic t t (car (gnus-topic-find-topology topic)) nil 0)
+       (while (not (equal (caaar tp) topic))
+         (setq tp (cdr tp)))
+       (pop tp)
+       (while (and tp
+                   (not (gnus-topic-goto-topic (caaar tp))))
+         (pop tp))
+       (if tp
+           (gnus-topic-forward-topic 1)
+         (gnus-topic-goto-missing-topic (caadr top)))))
     nil))
 
 (defun gnus-topic-update-topic-line (topic-name &optional reads)
@@ -931,6 +960,7 @@ articles in the topic and its subtopics."
     "c" gnus-topic-copy-group
     "h" gnus-topic-hide-topic
     "s" gnus-topic-show-topic
+    "j" gnus-topic-jump-to-topic
     "M" gnus-topic-move-matching
     "C" gnus-topic-copy-matching
     "\C-i" gnus-topic-indent
@@ -962,6 +992,7 @@ articles in the topic and its subtopics."
        ["Copy matching" gnus-topic-copy-matching t]
        ["Move matching" gnus-topic-move-matching t])
        ("Topics"
+       ["Goto" gnus-topic-jump-to-topic t]
        ["Show" gnus-topic-show-topic t]
        ["Hide" gnus-topic-hide-topic t]
        ["Delete" gnus-topic-delete t]
@@ -969,6 +1000,7 @@ articles in the topic and its subtopics."
        ["Create" gnus-topic-create-topic t]
        ["Mark" gnus-topic-mark-topic t]
        ["Indent" gnus-topic-indent t]
+       ["Sort" gnus-topic-sort-topics t]
        ["Toggle hide empty" gnus-topic-toggle-display-empty-topics t]
        ["Edit parameters" gnus-topic-edit-parameters t])
        ["List active" gnus-topic-list-active t]))))
@@ -982,7 +1014,7 @@ articles in the topic and its subtopics."
          (if (null arg) (not gnus-topic-mode)
            (> (prefix-numeric-value arg) 0)))
     ;; Infest Gnus with topics.
-     (if (not gnus-topic-mode)
+    (if (not gnus-topic-mode)
        (setq gnus-goto-missing-group-function nil)
       (when (gnus-visual-p 'topic-menu 'menu)
        (gnus-topic-make-menu-bar))
@@ -1049,9 +1081,9 @@ If performed over a topic line, toggle folding the topic."
     (save-excursion
       (gnus-message 5 "Expiring groups in %s..." topic)
       (let ((gnus-group-marked
-            (mapcar (lambda (entry) (car (nth 2 entry)))
-                    (gnus-topic-find-groups topic gnus-level-killed t))))
-       (gnus-group-expire-articles nil))
+            (mapcar (lambda (entry) (car (nth 2 entry)))
+                    (gnus-topic-find-groups topic gnus-level-killed t))))
+       (gnus-group-expire-articles nil))
       (gnus-message 5 "Expiring groups in %s...done" topic))))
 
 (defun gnus-topic-read-group (&optional all no-article group)
@@ -1099,44 +1131,60 @@ When used interactively, PARENT will be the topic under point."
   (gnus-group-list-groups)
   (gnus-topic-goto-topic topic))
 
+;; FIXME: 
+;;  1. When the marked groups are overlapped with the process 
+;;     region, the behavior of move or remove is not right.
+;;  2. Can't process on several marked groups with a same name, 
+;;     because gnus-group-marked only keeps one copy.
+
 (defun gnus-topic-move-group (n topic &optional copyp)
   "Move the next N groups to TOPIC.
 If COPYP, copy the groups instead."
   (interactive
    (list current-prefix-arg
         (completing-read "Move to topic: " gnus-topic-alist nil t)))
-  (let ((groups (gnus-group-process-prefix n))
+  (let ((use-marked (and (not n) (not (gnus-region-active-p)) 
+                        gnus-group-marked t))
+       (groups (gnus-group-process-prefix n))
        (topicl (assoc topic gnus-topic-alist))
-       (start-group (progn (forward-line 1) (gnus-group-group-name)))
        (start-topic (gnus-group-topic-name))
+       (start-group (progn (forward-line 1) (gnus-group-group-name)))
        entry)
-    (mapcar
-&nb