review.el 52.8 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
Linus Tolke's avatar
Linus Tolke committed
2
3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
5
;;;;;
6
;;;;; This file is part of the LysKOM Emacs LISP client.
Linus Tolke's avatar
Linus Tolke committed
7
8
9
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
10
;;;;; the Free Software Foundation; either version 2, or (at your option) 
Linus Tolke's avatar
Linus Tolke committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
Per Cederqvist's avatar
.    
Per Cederqvist committed
26
27
28
29
30
31
32
33
34
35
36
37
38
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: review.el
;;;;
;;;; This file contains functions to review articles in different ways.
;;;; Both the review commands themselves, the functions called by them
;;;; and the underlying functions are here.
;;;;
;;;; Most, if not all, of these functions are written by Linus Tolke.
;;;;


39
40
41
42
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

43
44
45
(eval-when-compile
  (require 'lyskom-command "command"))

David Byers's avatar
David Byers committed
46
47
48
49
(put 'lyskom-cant-review-error 'error-conditions '(error lyskom-error lyskom-review-error))
(put 'lyskom-cant-review-error 'error-message "Can't review")
(put 'lyskom-review-error 'error-condiions '(error lyskom-error))
(put 'lyskom-review-error 'error-message "Review error")
50

51

David Byers's avatar
David Byers committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; ======================================================================
;;; State-saving variables
;;;

(defvar lyskom-last-review-by nil)
(defvar lyskom-last-review-to nil)
(defvar lyskom-last-review-num nil)
(defvar lyskom-last-review-pmark nil)
(defvar lyskom-last-review-cmark nil)
(defvar lyskom-last-review-saved-result-list nil)
(defvar lyskom-last-review-saved-by-list nil)
(defvar lyskom-last-review-saved-to-list nil)
(defvar lyskom-last-review-saved-result-size 0)
(defvar lyskom-last-review-saved-smallest nil)
(defvar lyskom-last-review-saved-largest nil)
(defvar lyskom-have-review nil)


70
71
72
73
74
(defun lyskom-remove-zeroes (a)
  "Returns a copy of list where all zeroes are removed."
  (delq 0 (copy-sequence a)))


David Byers's avatar
David Byers committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;;; ================================================================
;;; Temoporary change of mark-as-read

(defun kom-toggle-mark-as-read-prefix ()
  "Read one key sequence and run one command with state of
kom-review-marks-texts-as-read toggled."
  (interactive)
  (let* ((kom-review-marks-texts-as-read (not kom-review-marks-texts-as-read))
         (sequence (read-key-sequence
                    (format "%s: " 
                            (lyskom-get-string
                             (if kom-review-marks-texts-as-read 
                                 'review-marking-as-read
                               'review-not-marking-as-read)))))
         (command (lookup-key (current-local-map) sequence)))
    (when (commandp command)
      (call-interactively command))))


Per Cederqvist's avatar
.    
Per Cederqvist committed
94
95
96
;;; ================================================================
;;;              ]terse av, till - Review by X to Conference Y.

David Byers's avatar
David Byers committed
97
;;; Author: David Byers
98

Per Cederqvist's avatar
.    
Per Cederqvist committed
99

100
(def-kom-command kom-review-all ()
101
102
103
104
105
  "Review all articles written by a particular author to a particular
conference. This can also be accomplished by using `kom-review-by-to'
and specifying zero texts.

See `kom-review-uses-cache', `kom-review-priority' and
106
`kom-review-marks-texts-as-read' for information on settings that affect
107
all review-related functions."
108
109
110
111
  (interactive)
  (lyskom-tell-internat 'kom-tell-review)
  (lyskom-review-by-to 0))

Per Cederqvist's avatar
.    
Per Cederqvist committed
112

113
(def-kom-command kom-review-more (count)
114
115
116
117
118
  "Review more articles using the same critera as the last review
performed with `kom-review-by-to'. The review will be resumed where
the previous review finished.

See `kom-review-uses-cache', `kom-review-priority' and
119
`kom-review-marks-texts-as-read' for information on settings that affect
120
all review-related functions."
Ulrik Haugen's avatar
Ulrik Haugen committed
121
  (interactive "P")
David Byers's avatar
David Byers committed
122
123
  (if (not lyskom-have-review)
      (lyskom-format-insert 'no-review-done)
124
125
126
127
    (let* ((count (or count
		      (lyskom-read-number
		       (lyskom-get-string 'review-how-many-more)
		       (abs lyskom-last-review-num))))
David Byers's avatar
David Byers committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
           (info (progn (if (and (listp count)
                                 (integerp (car count))
                                 (null (cdr count)))
                            (setq count (car count)))
                        (cond ((zerop count) 
                               (setq count nil)
                               (lyskom-get-string 'review-rest))
                              ((> count 0)
                               (lyskom-format (lyskom-get-string 'review-more)
                                              count)))))
           (by lyskom-last-review-by)
           (to lyskom-last-review-to))

      (lyskom-format-insert 'review-more-info-by-to
                            info
                            (if (zerop by)
                                (lyskom-get-string 'anybody)
                              by)
                            (if (zerop to)
                                (lyskom-get-string 'all-confs)
                              to))
    
      (condition-case arg
          (let ((list (lyskom-get-texts-by-to by to count t)))
            (setq lyskom-last-review-num 
                  (if (< lyskom-last-review-num 0)
                      (- count)
                    count))
            (if list
157
158
159
160
161
162
163
                (lyskom-review-enter-read-info
                 (lyskom-create-read-info
                  'REVIEW
                  nil
                  (lyskom-review-get-priority)
                  (lyskom-create-text-list list)
                  nil t) t)
David Byers's avatar
David Byers committed
164
165
166
167
168
              (lyskom-insert-string 'no-such-text)))
        (lyskom-review-error (if arg
                                 nil
                               (lyskom-insert-string 'no-such-text)))))))

169

David Byers's avatar
David Byers committed
170

171
(def-kom-command kom-review-first (&optional count)
172
173
174
175
176
177
178
179
  "Review the first N articles written by a particular author to some
conference. With no author specified, review texts by all authors.
With zero texts specified, review all text. With no conference
specified, review texts to all conferences. With a negative number of
texts, review the last N texts instead of the first (you can use
`kom-review-by-to' instead.

See `kom-review-uses-cache', `kom-review-priority' and
180
`kom-review-marks-texts-as-read' for information on settings that affect
181
all review-related functions."
182
  (interactive "P")
183
184
185
186
187
  (lyskom-tell-internat 'kom-tell-review)
  (lyskom-review-by-to (- (or count
                           (lyskom-read-number
                            (lyskom-get-string 'review-how-many) 1)))))

188

David Kågedal's avatar
David Kågedal committed
189
(def-kom-command kom-review-by-to (&optional count)
190
191
192
193
194
195
196
197
  "Review the last N articles written by a particular author to some
conference. With no author specified, review texts by all authors.
With zero texts specified, review all text. With no conference
specified, review texts to all conferences. With a negative number of
texts, review the last N texts instead of the first (you can use
`kom-review-first' instead.

See `kom-review-uses-cache', `kom-review-priority' and
198
`kom-review-marks-texts-as-read' for information on settings that affect
199
all review-related functions."
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  (interactive "P")
  (lyskom-review-by-to (or count
                           (lyskom-read-number
                            (lyskom-get-string 'review-how-many) 1))))
  


(defun lyskom-review-by-to (count)
  "Common function for kom-review-by-to and kom-review-first"
  (let* ((info (progn (if (and (listp count)
                               (integerp (car count))
                               (null (cdr count)))
                          (setq count (car count)))
                      (cond ((zerop count) 
                             (setq count nil)
215
                             (lyskom-get-string 'everything))
216
217
218
219
220
221
222
                            ((> count 0)
                             (lyskom-format 'latest-n count))
                            ((< count 0)
                             (lyskom-format 'first-n
                                            (- count))))))
         (by (lyskom-read-conf-no 
              (lyskom-format 'review-info (lyskom-format 'info-by-whom info))
223
              '(pers) t nil t))
224
225
226
         (to (lyskom-read-conf-no 
              (lyskom-format 'review-info
                             (lyskom-format 'info-to-conf info))
227
              '(all) 
228
              t
229
              ;; If person is not given we must give
230
231
              ;; conf  -- Not anymore!
              ;; (not (zerop by))
David Byers's avatar
David Byers committed
232
233
              (if (or (null lyskom-current-conf)
                      (zerop lyskom-current-conf))
234
                  ""
235
236
237
                (cons (conf-stat->name
                         (blocking-do 'get-conf-stat
                                      lyskom-current-conf)) 0))
238
              t)))
David Kågedal's avatar
David Kågedal committed
239
240

    (if (not (zerop to))
241
        (cache-del-conf-stat to))
David Kågedal's avatar
David Kågedal committed
242
    (if (not (zerop by)) 
243
        (cache-del-pers-stat by))
244

David Byers's avatar
David Byers committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    (lyskom-format-insert 'review-info-by-to
                          info
                          (if (zerop by)
                              (lyskom-get-string 'anybody)
                            by)
                          (if (zerop to)
                              (lyskom-get-string 'all-confs)
                            to))

    (setq lyskom-last-review-by by)
    (setq lyskom-last-review-to to)
    (setq lyskom-last-review-num count)
    (setq lyskom-last-review-pmark nil)
    (setq lyskom-last-review-cmark nil)
    (setq lyskom-last-review-saved-result-list nil)
    (setq lyskom-last-review-saved-by-list nil)
    (setq lyskom-last-review-saved-to-list nil)
    (setq lyskom-last-review-saved-result-size 0)
    (setq lyskom-last-review-saved-smallest nil)
    (setq lyskom-last-review-saved-largest nil)
    (setq lyskom-have-review t)
David Kågedal's avatar
David Kågedal committed
266

267
268
269
    (condition-case arg
        (let ((list (lyskom-get-texts-by-to by to count)))
          (if list
270
271
272
273
274
275
276
              (lyskom-review-enter-read-info
               (lyskom-create-read-info
                'REVIEW
                nil
                (lyskom-review-get-priority)
                (lyskom-create-text-list list)
                nil t) t)
277
278
279
280
            (lyskom-insert-string 'no-such-text)))
      (lyskom-review-error (if arg
                               nil 
                             (lyskom-insert-string 'no-such-text))))))
281

David Kågedal's avatar
David Kågedal committed
282

283
284
285
286
287
288
289
290
291
292
;;; ================================================================
;;; lyskom-get-texts-by-to
;;; Author: David Byers
;;;
;;; Call lyskom-get-texts-by, lyskom-get-texts-to or 
;;; lyskom-get-texts-by-and-to to get NUM texts by person 
;;; BY to conference TO.
;;;


David Byers's avatar
David Byers committed
293
294
(defun lyskom-get-texts-by-to (by to num &optional again)
  "Get NUM texts written by person number BY in conference number TO
295
Args: BY TO NUM"
296
  (cond ((and (zerop by) 
David Byers's avatar
David Byers committed
297
298
299
              (zerop to)) (lyskom-get-texts-globally num again))
        ((zerop to) (lyskom-get-texts-by by num again))
        ((zerop by) (lyskom-get-texts-to to num again))
David Byers's avatar
David Byers committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
        ((and (eq by lyskom-pers-no)
              (not (eq to by))
              (let ((conf (blocking-do 'get-conf-stat to)))
                (and (conf-type->letterbox (conf-stat->conf-type conf))
                     (null (map->text-nos 
                            (blocking-do 'get-map
                                         (conf-stat->conf-no conf)
                                         (conf-stat->first-local-no conf)
                                         1))))))
         (lyskom-get-texts-by-generic 
          by num 
          (function 
           (lambda (x to)
             (let ((found nil))
               (lyskom-traverse misc (text-stat->misc-info-list x)
                 (setq found 
                       (or found
317
318
                           (and (memq (misc-info->type misc)
					lyskom-recpt-types-list)
David Byers's avatar
David Byers committed
319
320
321
322
323
                                (eq (misc-info->recipient-no misc) to)))))
               found)))
          (list to)
          again))
         (t (lyskom-get-texts-by-and-to by to num again))))
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359


;;; ============================================================
;;; lyskom-check-review-access
;;; Author: David Byers
;;;
;;; Check that we can access the conference map. If we can't some
;;; review functions are just not much fun
;;;

(defun lyskom-check-review-access (conf pers)
  "Check that we can review texts to CONF by PERS.
CONF is a conf-stat or t if we know we can access that conference.
PERS is a pers-stat or t if we know we can access that person.
This function signals an error if review is impossible"
  (cond ((null conf) 
         (lyskom-format-insert 'review-conf-gone)
         (signal 'lyskom-cant-review-error t))
        ((null pers)
         (lyskom-format-insert 'review-pers-gone)
         (signal 'lyskom-cant-review-error t))
        ((lyskom-conf-stat-p conf)
         (cond ((= 0 (conf-stat->no-of-texts conf))
                (lyskom-format-insert 'review-cant-read-empty)
                (signal 'lyskom-cant-review-error t))
               ((null (map->text-nos 
                       (blocking-do 'get-map
                                    (conf-stat->conf-no conf)
                                    (conf-stat->first-local-no conf)
                                    1)))
                (if (conf-type->letterbox
                     (conf-stat->conf-type conf))
                    (lyskom-format-insert 'review-cant-read-letterbox)
                  (lyskom-format-insert 'review-cant-read-conf))
                (signal 'lyskom-cant-review-error t))))))

360
361


362
363
364
365
366
;;; ============================================================
;;; lyskom-get-texts-globally
;;; Author: Per Cederquist, David Byers
;;;

David Byers's avatar
David Byers committed
367
368
369
370
371
372
373
374
375
376
377
(defun lyskom-get-texts-globally (num &optional again)
  "Get the last NUM texts created in LysKOM. If AGAIN is non-nil, keep
going from where we were before."
  (cond ((and again (null num))
         (setq num lyskom-last-review-num))
        ((and again (< lyskom-last-review-num 0)) 
         (setq num (- num)))
        ((null num) 
         (lyskom-format-insert 'cant-review-everything)
         (signal 'lyskom-cant-review-error t)))

378
  (let ((result nil)
David Byers's avatar
David Byers committed
379
380
381
        (textno (cond (again lyskom-last-review-cmark)
                      ((< num 0) 1)
                      (t (lyskom-maxint))))
382
383
384
385
386
        (op (if (< num 0)
                'find-next-text-no
              'find-previous-text-no)))

    (while (and (not (eq textno 0))
David Byers's avatar
David Byers committed
387
                (not (null textno))
388
389
                (< (length result) (abs num)))
      (setq textno (blocking-do op textno))
David Byers's avatar
David Byers committed
390
391
392
      (if textno
          (setq result (cons textno result))))
    (setq lyskom-last-review-cmark textno)
393
394
395
396
    (if (< num 0)
        (nreverse result)
      result)))

397

398
399
400
401
402
403
404
405
406
407
408
409
;;; ================================================================
;;; lyskom-get-letters-to
;;; Author: David Byers
;;; 
;;; Get letters by self that have a specified letterbox as
;;; recipient. Do this by linearly searching selfs letterbox
;;; map and look as every single doggone text-stat. What a drag.
;;;
;;; +++ FIXME: This is just get-texts-by right now. Need to filter stuff.
;;;

(defun lyskom-get-letters-to (persno recipient num &optional again pstart)
David Byers's avatar
David Byers committed
410
411
412
  "Get NUM texts written by PERSNO. Args: persno num

Cannot be called from a callback."
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
  (let ((persstat (blocking-do 'get-pers-stat persno)))
    (lyskom-check-review-access t persstat)

    (cond ((and again (null num)) (setq num lyskom-last-review-num))
          ((and again (< lyskom-last-review-num 0)) (setq num (- num))))

    (let* ((plow (or pstart (pers-stat->first-created-text persstat)))
           (phigh (1- (+ plow (pers-stat->no-of-created-texts persstat))))
           (result (if again
                       lyskom-last-review-saved-result-list
                     nil))
           (increment (if num (abs num)))
           (mark (cond (again lyskom-last-review-pmark)
                        ((and num (< num 0)) plow)
                        (t phigh)))
           (collector nil)
           (found nil)
           (start nil)
           (data nil))
    

      (if (null num)
          (setq num (1+ phigh)
                mark phigh
                increment (1+ phigh)))

      (while (and (<= mark phigh)
                  (>= mark plow)
                  (> (abs num) (length result)))

        (setq increment (min lyskom-fetch-map-nos increment))
        (setq start (if (< num 0)
                        mark
                      (- mark (1- increment))))
        (if (< start 0)
            (progn
              (setq increment (- increment start))
              (setq start 0)))
      
        (setq data (lyskom-remove-zeroes
                    (listify-vector
                     (map->text-nos
                      (blocking-do 'get-created-texts
                                   persno
                                   start
                                   increment)))))

        (setq collector (make-collector))
        (mapcar
         (function
          (lambda (x)
            (initiate-get-text-stat 
             'main 
             (function
              (lambda (x collector pers-no)
                (if (and x
                         (lyskom-is-recipient x pers-no))
                    (collector-push (text-stat->text-no x) collector))))
             x
             collector
             recipient)))
         data)

        (lyskom-wait-queue 'main)
        (setq found (nreverse (collector->value collector)))

        (if (> num 0)
            (setq result (nconc found result)
                  mark (- mark increment))
          (setq result (nconc result found)
                mark (+ mark increment)))
        (if (null found)
            (setq increment (min lyskom-fetch-map-nos (* increment 2)))
          (setq increment (- (abs num) (length result)))))

      (setq lyskom-last-review-pmark mark)

      (if (> num 0)
          (progn
            (setq lyskom-last-review-saved-result-list 
                  (nfirst (- (length result) num) result))
494
            (nthcdr (max 0 (- (length result) num)) result))
495
496
497
498
499
500
501
502
503
504
        (progn
          (setq lyskom-last-review-saved-result-list
                (nthcdr (- num) result))
          (nfirst (- num)  result))))))






505
506
;;; ================================================================
;;; lyskom-get-texts-by-and-to
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
;;; Author: David Byers
;;;
;;; Note: We can't assume that the conference's map of texts is
;;; sorted. If we could, it would be possible to simplify this
;;; function considerably without making it slower. 
;;;
;;; Problem: Construct part of the intersection between the user's
;;; created texts (the by-list) and the texts in a conference (the
;;; to-list) without bogging down the client, server or network and
;;; do it quickly!
;;;
;;; Idea: Construct the intersection incrementally without doing more
;;; work comparing things than we would if we had the full maps to
;;; start with.
;;;
;;; Solution: Get one segment of the by-list (call the nth segment
;;; by_n) and to-list (call the nth segment to_n) at a time until we
;;; are done or until both are exhausted. 
;;;
;;; In each iteration do the following: Calculate the intersection
;;; between to_n with each of the previous by_i leaving r_n:
;;;         r_n = \prod_{i=1}^{n-1} by_i \cap to_n
;;; where \prod denotes list concatenation. Next calculate the
;;; intersection of by_n with each to_i 0<i<n in turn, concatenating
;;; the result to the corresponding r_i:
;;;         r_i \larrow r_i * (by_n \cap to_i) ; 0<i<n
;;; At this point, the concatenation of all r_n, \prod r_n, is the
;;; result of the intersection between the segments of the by-list and
Joel Rosdahl's avatar
Joel Rosdahl committed
535
;;; to-list we have retrieved so far.
536
537
538
539
540
541
542
543
544
545
546
;;;
;;; If the total size of the result equals or exceeds the size we
;;; requested, finish the loop and return the results.
;;;
;;;
;;; Althogh the solution may seem a bit complicated, it's really not
;;; that bad once you think about how it's done. The good thing about
;;; it is that it does as little work as possible comparing elements.
;;; The bad part is that it constructs a little too many new cons
;;; cells, although reversing most of the lists does help.
;;;
547
;;; The following optimisations have been implemented:
548
;;;
549
550
551
552
553
554
555
556
557
558
559
560
561
;;; - Exploit the fact that the user's map is sorted by aborting the
;;; search if we have the full conference map and the lowest number we
;;; have from the user's map is lower than the lowest number in the
;;; conference map. Highest numbers apply when we are searching from
;;; the front.

;;; +++ FIXME: For users that have written very little in high-traffic
;;; conferences, and where the request cannot be fulfilled (if num is
;;; too high) this function ends up scanning the entire conference
;;; map. At some point it is probably faster to get all the text-stats
;;; in the user's map (when we've retrieved the map we know how many
;;; there are) and look at the recipients rather than calculate the
;;; intersection. 
562
;;;
563

David Byers's avatar
David Byers committed
564
565
(defun lyskom-get-texts-by-and-to (persno confno num 
                                          &optional again pstart cstart)
566
  "Get NUM texts written by person PERSNO with conference CONFNO as a
David Byers's avatar
David Byers committed
567
568
recipient. If optional AGAIN is non-nil, continue from where we were.
Args: persno confno num &optional again pstart cstart"
569
570
  (blocking-do-multiple ((persstat (get-pers-stat persno))
                         (confstat (get-conf-stat confno)))
571
572
573
574
575
576
577
578
579
    (cond

     ;;
     ;; Special case: reviewing to a letterbox or conference we're not
     ;; a member of and have no access to.
     ;;

     ((and (eq lyskom-pers-no persno)
           confstat
580
581
           (or (conf-type->letterbox (conf-stat->conf-type confstat))
               (and (conf-type->rd_prot (conf-stat->conf-type confstat))
582
583
                    (null (map->text-nos 
                           (blocking-do 'get-map
David Byers's avatar
David Byers committed
584
585
                                        (conf-stat->conf-no confstat)
                                        (conf-stat->first-local-no confstat)
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
                                        1)))))
           (not (eq persno confno)))
      (lyskom-get-letters-to persno confno num again pstart))

     ;;
     ;; General case
     ;;

     (t
      (lyskom-check-review-access confstat persstat)
      (cond ((and again (null num)) (setq num lyskom-last-review-num))
            ((and again (< lyskom-last-review-num 0) (setq num (- num)))))
      (let* ((result-list (if again
                              lyskom-last-review-saved-result-list
                            nil))
             (by-list (if again
                          lyskom-last-review-saved-by-list
                        nil))
             (to-list (if again 
                          lyskom-last-review-saved-to-list 
                        nil))
             (result-size (if again
                              lyskom-last-review-saved-result-size
                            0))
             (by nil)
             (to nil)
             (increment lyskom-fetch-map-nos)
             (plow (or pstart (pers-stat->first-created-text persstat)))
             (phigh (1- (+ plow (pers-stat->no-of-created-texts persstat))))
             (pmark (cond (again lyskom-last-review-pmark)
                          ((and num (< num 0)) plow)
                          (t phigh)))
             (clow (or cstart (conf-stat->first-local-no confstat)))
             (chigh (1- (+ clow (conf-stat->no-of-texts confstat))))
             (cmark (cond (again lyskom-last-review-cmark)
                          ((and num (< num 0)) clow)
                          (t chigh)))
             (smallest (if again lyskom-last-review-saved-smallest nil))
             (largest (if again lyskom-last-review-saved-largest nil))
             (abort-loop nil))

        (if (null num)
            (setq num (1+ phigh)))

        (while (and (or (and (<= pmark phigh)
                             (>= pmark plow))
                        (and (<= cmark chigh)
                             (>= cmark clow)))
                    (> (abs num) result-size)
                    (not abort-loop))

          (setq by (and (<= pmark phigh)
                        (>= pmark plow)
                        (lyskom-remove-zeroes
                         (listify-vector
                          (map->text-nos
                           (blocking-do 'get-created-texts
                                        (pers-stat->pers-no persstat)
                                        (if (< num 0)
                                            pmark
                                          (max 0 (- pmark (1- increment))))
                                        increment)))))
                to (and (<= cmark chigh)
                        (>= cmark clow)
                        (lyskom-remove-zeroes
                         (listify-vector
                          (map->text-nos
                           (blocking-do 'get-map
                                        (conf-stat->conf-no confstat)
                                        (if (< num 0)
                                            cmark
                                          (max 0 (- cmark (1- increment))))
                                        increment))))))

          (if (> num 0)
              (if (and smallest by
                       (> smallest (car by)))
                  (setq abort-loop t))
            (if (and largest by
                     (< largest (car (nthcdr (1- (length by)) by))))
                (setq abort-loop t)))

          ;;
          ;;    Add intersection between new TO and old BYs
          ;;    to the results list.
          ;;

          (setq result-list
                (cons (apply 'nconc
                             (mapcar 
                              (function
                               (lambda (x)
                                 (lyskom-intersection to x)))
                              by-list))
                      result-list))

          ;;
          ;;    Add new BY and TO to the by-list and to-list
          ;;

          (setq by-list (cons by by-list)
                to-list (cons to to-list))
688
      
689

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
          ;;
          ;;    Add intersections between new BY and all TOs
          ;;

          (setq result-list
                (mapcar2 (function
                          (lambda (x y)
                            (lyskom-intersection y
                                                 (nconc x by))))
                         result-list
                         to-list))

          (setq result-size (apply '+ (mapcar 'length result-list)))

          ;;
          ;;    Adjust the marks
          ;;

          (if (> num 0)
              (setq pmark (- pmark increment)
                    cmark (- cmark increment))
            (setq pmark (+ pmark increment)
                  cmark (+ cmark increment)))


          ;;
          ;;  If we have exhausted the conference, calculate smallest and
          ;;  largest
          ;;

          (if (and (null smallest)
                   (null largest)
                   (or (> cmark chigh)
                       (< cmark clow)))
              (setq smallest 
                    (apply 'min
                           (mapcar (function (lambda (x)
                                               (if x
                                                   (apply 'min x)
                                                 (lyskom-maxint))))
                                   to-list))
                    largest
                    (apply 'max
                           (mapcar (function (lambda (x)
                                               (if x
                                                   (apply 'max x)
                                                 -1)))
                                   to-list))))


          ;;
          ;;    This is the end of the while loop
          ;;

          )

        (setq lyskom-last-review-pmark pmark)
        (setq lyskom-last-review-cmark cmark)
        (setq lyskom-last-review-saved-by-list by-list)
        (setq lyskom-last-review-saved-to-list to-list)
        (setq lyskom-last-review-saved-smallest smallest)
        (setq lyskom-last-review-saved-largest largest)

753
        ;;
754
        ;;  Extract results
755
        ;;
756

757
        (setq result-list
758
759
760
              (apply 'nconc (if (< num 0)
                                (nreverse result-list)
                              result-list)))
761

762
        ;;
763
        ;;  Save discarded results and return retained results
764
        ;;
765

766
        (if (> num 0)
767
768
769
770
771
772
773
774
            (progn
              (setq lyskom-last-review-saved-result-list
                    (nfirst (- (length result-list) num) result-list))
              (setq lyskom-last-review-saved-result-size
                    (length  lyskom-last-review-saved-result-list))
              (setq lyskom-last-review-saved-result-list
                    (cons lyskom-last-review-saved-result-list
                          (make-list (- (length by-list) 1) nil)))
775
              (nthcdr (max 0 (- (length result-list) num)) result-list))
776

David Byers's avatar
David Byers committed
777
778
779
780
781
782
783
784
          (progn
            (setq lyskom-last-review-saved-result-list 
                  (nthcdr (- num) result-list))
            (setq lyskom-last-review-saved-result-size
                  (length lyskom-last-review-saved-result-list))
            (setq lyskom-last-review-saved-result-list
                  (cons lyskom-last-review-saved-result-list
                        (make-list (- (length by-list) 1) nil)))
785
            (nfirst (- num) result-list))))))))
David Byers's avatar
David Byers committed
786

787

788
789

;;; ===============================================================
790
;;; lyskom-get-texts-by, lyskom-get-texts-to
791
792
;;; Author: David Byers
;;;
793
794
795
796
797
798
799
;;; These functions get data in chunks, starting with the number of
;;; texts requested. If they come up empty (which is common when
;;; scanning from the beginning of a map), the increment is
;;; exponentially increased up to a maximum of 150. 
;;;
;;; lyskom-get-texts-by is also careful to filter out those texts that
;;; are not readable, hence the added complexity in that function.
800
801
;;;

David Byers's avatar
David Byers committed
802
(defun lyskom-get-texts-by (persno num &optional again pstart)
803
  "Get NUM texts written by PERSNO. Args: persno num"
David Byers's avatar
David Byers committed
804
  (let* ((persstat (blocking-do 'get-pers-stat persno)))
805
    (lyskom-check-review-access t persstat)
David Byers's avatar
David Byers committed
806
807
808
809
    (lyskom-get-texts-by-generic persno num nil nil again pstart)))

(defun lyskom-get-texts-by-generic (persno num pred args 
                                           &optional again pstart)
David Byers's avatar
David Byers committed
810
811
812
  "Get NUM texts written by PERSNO. Args: persno num

Cannot be called from a callback."
David Byers's avatar
David Byers committed
813
814
  (let* ((persstat (blocking-do 'get-pers-stat persno))
         (user-area (pers-stat->user-area persstat)))
815

David Byers's avatar
David Byers committed
816
817
818
819
    (cond ((and again (null num)) (setq num lyskom-last-review-num))
          ((and again (< lyskom-last-review-num 0)) (setq num (- num))))

    (let* ((plow (or pstart (pers-stat->first-created-text persstat)))
820
           (phigh (1- (+ plow (pers-stat->no-of-created-texts persstat))))
David Byers's avatar
David Byers committed
821
822
823
           (result (if again
                       lyskom-last-review-saved-result-list
                     nil))
824
           (increment (if num (abs num)))
David Byers's avatar
David Byers committed
825
826
827
           (mark (cond (again lyskom-last-review-pmark)
                        ((and num (< num 0)) plow)
                        (t phigh)))
828
           (collector nil)
829
           (found nil)
830
           (start nil)
831
832
833
834
835
836
837
838
839
840
841
           (data nil))
    

      (if (null num)
          (setq num (1+ phigh)
                mark phigh
                increment (1+ phigh)))

      (while (and (<= mark phigh)
                  (>= mark plow)
                  (> (abs num) (length result)))
842
843
844
845
846
847
848
849
850

        (setq increment (min lyskom-fetch-map-nos increment))
        (setq start (if (< num 0)
                        mark
                      (- mark (1- increment))))
        (if (< start 0)
            (progn
              (setq increment (- increment start))
              (setq start 0)))
851
      
David Byers's avatar
David Byers committed
852
853
854
855
856
857
858
859
        (setq data (delq user-area
                         (lyskom-remove-zeroes
                          (listify-vector
                           (map->text-nos
                            (blocking-do 'get-created-texts
                                         persno
                                         start
                                         increment))))))
860

861
862
863
864
865
866
        (setq collector (make-collector))
        (mapcar
         (function
          (lambda (x)
            (initiate-get-text-stat 'main 
                                    (function
David Byers's avatar
David Byers committed
867
868
869
870
871
872
                                     (lambda (x collector pred args)
                                       (when (and x
                                                  (or (null pred)
                                                      (apply pred
                                                             x
                                                             args)))
873
874
875
                                           (collector-push 
                                            (text-stat->text-no x)
                                            collector))))
David Byers's avatar
David Byers committed
876
                                    x collector pred args)))
877
878
         data)

879
        (lyskom-wait-queue 'main)
880
        (setq found (nreverse (collector->value collector)))
881

882
883
        (if (> num 0)
            (setq result (nconc found result)
884
                  mark (- mark increment))
885
886
887
          (setq result (nconc result found)
                mark (+ mark increment)))
        (if (null found)
888
889
            (setq increment (min lyskom-fetch-map-nos (* increment 2)))
          (setq increment (- (abs num) (length result)))))
890

David Byers's avatar
David Byers committed
891
892
      (setq lyskom-last-review-pmark mark)

893
      (if (> num 0)
David Byers's avatar
David Byers committed
894
895
896
          (progn
            (setq lyskom-last-review-saved-result-list 
                  (nfirst (- (length result) num) result))
897
            (nthcdr (max 0 (- (length result) num)) result))
David Byers's avatar
David Byers committed
898
899
900
901
        (progn
          (setq lyskom-last-review-saved-result-list
                (nthcdr (- num) result))
          (nfirst (- num)  result))))))
902

David Byers's avatar
David Byers committed
903
(defun lyskom-get-texts-to (confno num &optional again cstart)
904
  "From CONFNO get NUM texts."
905
906
907
908
  (let ((confstat (blocking-do 'get-conf-stat confno)))

    (lyskom-check-review-access confstat t)

David Byers's avatar
David Byers committed
909
910
911
912
    (cond ((and again (null num)) (setq num lyskom-last-review-num))
          ((and again (< lyskom-last-review-num 0)) (setq num (- num))))

    (let* ((clow (or cstart (conf-stat->first-local-no confstat)))
913
           (chigh (1- (+ clow (conf-stat->no-of-texts confstat))))
David Byers's avatar
David Byers committed
914
915
916
           (result (if again 
                       lyskom-last-review-saved-result-list
                     nil))
917
           (start nil)
918
           (increment (and num (abs num)))
David Byers's avatar
David Byers committed
919
920
921
           (mark (cond (again lyskom-last-review-cmark)
                       ((and num (< num 0)) clow)
                       (t chigh))))
922
923
924
925
926
927
928
929
930

      (if (null num)
          (setq num (1+ chigh)
                increment (1+ chigh)
                mark chigh))

      (while (and (<= mark chigh)
                  (>= mark clow)
                  (> (abs num) (length result)))
931
932
933
934
935
936
937
938
939
940

        (setq increment (min lyskom-fetch-map-nos increment))
        (setq start (if (< num 0)
                        mark
                      (- mark (1- increment))))
        (if (< start 0)
            (progn
              (setq increment (- increment start))
              (setq start 0)))

941
942
943
944
945
        (let ((found (lyskom-remove-zeroes
                      (listify-vector
                       (map->text-nos
                        (blocking-do 'get-map
                                     confno
946
                                     start
947
948
949
950
951
952
953
954
955
956
                                     increment))))))
          (if (> num 0)
              (setq result (nconc found result)
                    mark (- mark increment)
                    increment (- (abs num) (length result)))
            (setq result (nconc result found)
                  mark (+ mark increment)))
          (if (null found)
              (setq increment (min lyskom-fetch-map-nos (* increment 2)))
            (setq increment (- (abs num) (length result))))))
957

David Byers's avatar
David Byers committed
958
959
      (setq lyskom-last-review-cmark mark)

960
      (if (> num 0)
David Byers's avatar
David Byers committed
961
962
963
          (progn
            (setq lyskom-last-review-saved-result-list 
                  (nfirst (- (length result) num) result))
964
            (nthcdr (max 0 (- (length result) num)) result))
David Byers's avatar
David Byers committed
965
966
967
968
        (progn
          (setq lyskom-last-review-saved-result-list
                (nthcdr (- num) result))
          (nfirst (- num)  result))))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
969
970


David Byers's avatar
David Byers committed
971
972


David Byers's avatar
David Byers committed
973
974
975
976
977
;;; ============================================================
;;;                 Återse baklänges
;;;

(def-kom-command kom-review-backward ()
978
979
980
981
982
  "Toggles the reviewing order. If you are currently reviewing texts
oldest to newest, review newest to oldest instead. When reviewing
newest to oldest, change to oldest to newest.

See `kom-review-uses-cache', `kom-review-priority' and
983
`kom-review-marks-texts-as-read' for information on settings that affect
984
all review-related functions."
Per Cederqvist's avatar
.    
Per Cederqvist committed
985
986
987
  (interactive)
  (cond
   ((and (not (read-list-isempty lyskom-reading-list))
988
	 (memq (read-info->type (read-list->first lyskom-reading-list))
989
		 '(REVIEW REVIEW-MARK)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
990
991
992
993
    (let* ((info (read-list->first lyskom-reading-list))
	   (list (read-info->text-list info))
	   (texts (cdr list))
	   (forward (read-info->forward info)))
David Byers's avatar
David Byers committed
994
      (set-text-list->texts list (nreverse texts))
Per Cederqvist's avatar
.    
Per Cederqvist committed
995
      (set-read-info->forward info (not forward))
996
997
998
999
      (lyskom-format-insert 'you-review 
			    (lyskom-get-string (if (not forward)
						   'forward
						 'backward)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1000
   (t
David Byers's avatar
David Byers committed
1001
    (lyskom-insert-string 'illegal-command))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1002
1003
1004
1005
1006
1007
1008
1009


;;; ================================================================
;;;                   ]terse tr{det - review tree

;;; Author: Linus Tolke


David Kågedal's avatar
David Kågedal committed
1010
(def-kom-command kom-review-tree (&optional text-no)
1011
1012
1013
1014
1015
1016
1017
1018
1019
  "Recursively review all comments to the selected text.
This command will descend recursively in the comment tree, as when
reading texts normally. Unlike when reading normally, filters are
not applied and circular structures are not dealt with gracefully.

This command accepts text number prefix arguments \(see
`lyskom-read-text-no-prefix-arg').

See `kom-review-uses-cache', `kom-review-priority' and
1020
`kom-review-marks-texts-as-read' for information on settings that affect
1021
all review-related functions."
1022
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-tree-q)))
David Kågedal's avatar
David Kågedal committed
1023
1024
  (lyskom-tell-internat 'kom-tell-review)
  (if text-no
1025
1026
1027
1028
1029
1030
1031
1032
1033
      (progn
        (unless kom-review-uses-cache
          (cache-del-text-stat text-no))
        
        (let ((ts (blocking-do 'get-text-stat text-no)))
          (lyskom-follow-comments ts
                                  nil 'review
                                  (lyskom-review-get-priority)
                                  t)))
David Kågedal's avatar
David Kågedal committed
1034
1035
1036
    (lyskom-insert-string 'read-text-first)))


1037
(def-kom-command kom-find-root (text-no)
1038
1039
1040
1041
1042
1043
1044
1045
  "Finds the root text of the tree containing the selected text.
When there is more than one root, all will be included in a review
operation.

This command accepts text number prefix arguments \(see
`lyskom-read-text-no-prefix-arg').

See `kom-review-uses-cache', `kom-review-priority' and
1046
`kom-review-marks-texts-as-read' for information on settings that affect
1047
all review-related functions."
1048
  (interactive (list (lyskom-read-text-no-prefix-arg 'find-root-q)))
David Kågedal's avatar
David Kågedal committed
1049
1050
  (lyskom-tell-internat 'kom-tell-review)
  (cond
1051
   (text-no
1052
1053
    (unless kom-review-uses-cache
      (cache-del-text-stat text-no))
1054
    (let* ((ts (blocking-do 'get-text-stat text-no))
David Byers's avatar
David Byers committed
1055
1056
1057
	   (r (lyskom-find-root ts t)))
      (cond ((> (length r) 1)
             (lyskom-format-insert-before-prompt
1058
1059
1060
1061
1062
1063
1064
1065
              (lyskom-get-string 'more-than-one-root) ts)
             (lyskom-review-enter-read-info
              (lyskom-create-read-info
               'REVIEW
               nil
               (lyskom-review-get-priority)
               (lyskom-create-text-list r)
               nil t) t))
1066
1067
1068
            (r (unless kom-review-uses-cache
                 (cache-del-text-stat (car r)))
               (lyskom-view-text (car r)))
David Byers's avatar
David Byers committed
1069
            (t (signal 'lyskom-internal-error "Could not find root")))
David Kågedal's avatar
David Kågedal committed
1070
1071
1072
      )
    )
   (t
1073
    (lyskom-insert-string 'confusion-what-to-find-root))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1074
1075


1076
(def-kom-command kom-find-root-review (text-no)
1077
1078
1079
1080
1081
1082
1083
1084
1085
  "Finds the root of the comment tree containing the selected texts
and then recursively reviews all its comments. For texts with a single
root, this is equivalent to doing `kom-find-root' followed by
`kom-review-tree'.

This command accepts text number prefix arguments \(see
`lyskom-read-text-no-prefix-arg').

See `kom-review-uses-cache', `kom-review-priority' and
1086
`kom-review-marks-texts-as-read' for information on settings that affect
1087
all review-related functions."
1088
  (interactive (list (lyskom-read-text-no-prefix-arg 'find-root-review-q)))
1089
  (lyskom-tell-internat 'kom-tell-review)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1090
  (cond
1091
   (text-no
1092
1093
    (unless kom-review-uses-cache
      (cache-del-text-stat text-no))
1094
    (let* ((ts (blocking-do 'get-text-stat text-no))
David Byers's avatar
David Byers committed
1095
1096
1097
1098
1099
1100
1101
           (start (lyskom-find-root ts t)))
      (cond ((> (length start) 1)
             (lyskom-format-insert-before-prompt
              (lyskom-get-string 'more-than-one-root-review) ts)
             (lyskom-review-tree (car start)))
            (start (lyskom-review-tree (car start)))
            (t (signal 'lyskom-internal-error "Could not find root")))))
1102
   (t (lyskom-insert-string 'confusion-what-to-find-root-review))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1103
1104


David Byers's avatar
X    
David Byers committed
1105
(defun lyskom-find-root (text-stat &optional all)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1106
  "Finds the root text of the tree containing the text TEXT-STAT.
David Byers's avatar
X    
David Byers committed
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
Args: TEXT-STAT &optional ALL
If ALL is set, return a list of all root texts."  
  (cond (text-stat
         (let ((queue (list text-stat))
               (head nil)
               (misclist nil)
               (tmp nil)
               (result nil))
           (while queue
             (setq head (car queue))
             (setq queue (cdr queue))
             (setq tmp nil)
             
             ;;
             ;; For each parent, add it to the queue
             ;;
               
             (setq misclist (text-stat->misc-info-list head))
             (while misclist
               (cond ((eq (misc-info->type (car misclist)) 'COMM-TO)
1127
1128
                      (unless kom-review-uses-cache
                        (cache-del-text-stat (misc-info->comm-to (car misclist))))
David Byers's avatar
X    
David Byers committed
1129
1130
1131
1132
1133
1134
                      (setq tmp
                            (cons
                             (blocking-do 'get-text-stat
                                          (misc-info->comm-to (car misclist)))
                             tmp)))
                     ((eq (misc-info->type (car misclist)) 'FOOTN-TO)
1135
1136
                      (unless kom-review-uses-cache
                        (cache-del-text-stat (misc-info->footn-to (car misclist))))
David Byers's avatar
X    
David Byers committed
1137
1138
1139
1140
1141
1142
                      (setq tmp 
                            (cons
                             (blocking-do 'get-text-stat
                                          (misc-info->footn-to (car misclist)))
                             tmp)))) 
               (setq misclist (cdr misclist)))
1143
1144
1145
1146
1147
1148
1149

	     ;;
	     ;; Remove unreadable texts
	     ;;

	     (setq tmp (delq nil tmp))

David Byers's avatar
X    
David Byers committed
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
             ;;
             ;; If no parents were found, this is is a top-level text
             ;;

             (when (null tmp)
               (setq result (cons head result))
               (if (not all) (setq queue nil)))
             (setq queue (nconc tmp queue)))
           (if all (mapcar 'text-stat->text-no result)
             (text-stat->text-no (car result)))))
        (t nil)))


Per Cederqvist's avatar
.    
Per Cederqvist committed
1163
1164
1165
1166
1167


(defun lyskom-review-tree (text)
  "Takes a TEXT as an arg, shows the text and the tree of all comments.
Does a lyskom-end-of-command.
Linus Tolke's avatar
Linus Tolke committed
1168
Text is a text-no."
Per Cederqvist's avatar
.    
Per Cederqvist committed
1169
1170
  (cond
   ((integerp text)
1171
1172
    (unless kom-review-uses-cache
      (cache-del-text-stat text))
1173
    (lyskom-view-text text nil t nil (lyskom-review-get-priority) t))
Linus Tolke's avatar
Linus Tolke committed
1174
1175
1176
1177
   (t
    (signal 'lyskom-internal-error
	    (list 'lyskom-review-tree
		  "Called with incorrect argument."
David Kågedal's avatar
David Kågedal committed
1178
		  text)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1179
1180
1181
1182
1183
1184
1185
1186


;;; ================================================================
;;;                     ]terse n{sta -  review next

;;; Author: Linus Tolke


David Byers's avatar
David Byers committed
1187
(def-kom-command kom-review-next ()
1188
1189
1190
1191
1192
1193
  "Resumes an interupted review by moving all suspended review entries
to the front. This command may be less-than-useful depending on how
review priorities are set, and the setting of
`kom-higher-priority-breaks'.

See `kom-review-uses-cache', `kom-review-priority' and
1194
`kom-review-marks-texts-as-read' for information on settings that affect
1195
all review-related functions."
Per Cederqvist's avatar
.    
Per Cederqvist committed
1196
  (interactive)
1197
  (lyskom-tell-internat 'kom-tell-review)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
  (let ((len (read-list-length lyskom-reading-list))
	(finished nil))
    (while (and (not finished)
		(> len 1))
      (let ((type (read-info->type (read-list->first lyskom-reading-list))))
	(if (and (not (eq type 'REVIEW))
		 (not (eq type 'REVIEW-TREE))
		 (not (eq type 'REVIEW-MARK)))
	    (read-list-rotate lyskom-reading-list)
	  (setq finished t)))
David Byers's avatar
David Byers committed
1208
      (setq len (1- len)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1209
1210
1211
1212
1213
1214
1215
1216


;;; ================================================================
;;;                    ]terse stacken - Review stack

;;; Author: Linus


David Byers's avatar
David Byers committed
1217
(def-kom-command kom-review-stack ()
1218
1219
1220
1221
  "Displays a list of suspended review commands, and possibly regular
read commands that have been suspended by reviewing.

See `kom-review-uses-cache', `kom-review-priority' and
1222
`kom-review-marks-texts-as-read' for information on settings that affect
1223
all review-related functions."
Per Cederqvist's avatar
.    
Per Cederqvist committed
1224
  (interactive)
David Byers's avatar
David Byers committed
1225
1226
1227
1228
  (if (read-list->all-entries lyskom-reading-list)
      (mapcar
       (function
        (lambda (info)
David Byers's avatar
David Byers committed
1229
          (let ((un (text-list->length (read-info->text-list info)))
David Byers's avatar
David Byers committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
                (type (read-info->type info))
                (cto (read-info->comm-to info))
                (conf (read-info->conf-stat info)))
            (cond
             ((eq type 'COMM-IN)
              (lyskom-format-insert 'view-many-comments cto un))
             ((eq type 'CONF)
              (lyskom-format-insert 'view-texts-in-conf un conf))
             ((eq type 'REVIEW)
              (lyskom-format-insert 'review-n-texts un))
             ((eq type 'REVIEW-TREE)
              (lyskom-format-insert 'review-many-comments cto un))
             ((eq type 'REVIEW-MARK)
              (lyskom-format-insert 'review-marked un))))))
       (read-list->all-entries lyskom-reading-list))
    (cond (lyskom-current-conf 
           (lyskom-format-insert 'you-have-no-unreads lyskom-current-conf))
David Byers's avatar
David Byers committed
1247
          (t (lyskom-insert 'not-reading-anywhere)))))
David Byers's avatar
David Byers committed
1248

Per Cederqvist's avatar
.    
Per Cederqvist committed
1249
1250
1251
1252
1253
1254
1255
1256


;;; ================================================================
;;;                      ]terse hoppa - review clear

;;; Author: Linus Tolke


David Byers's avatar
David Byers committed
1257
(def-kom-command kom-review-clear ()
1258
1259
1260
  "Cancel all active and suspended review commands.

See `kom-review-uses-cache', `kom-review-priority' and
1261
`kom-review-marks-texts-as-read' for information on settings that affect
1262
all review-related functions."
Per Cederqvist's avatar
.    
Per Cederqvist committed
1263
  (interactive)
David Byers's avatar
David Byers committed
1264
1265
  (let ((found nil))
    (if (not (read-list-isempty lyskom-reading-list))
1266
1267
        (while (memq (read-info->type (read-list->first lyskom-reading-list))
                       lyskom-review-types-list)
David Byers's avatar
David Byers committed
1268
1269
1270
          (set-read-list-del-first lyskom-reading-list)
          (setq found t)))
    (if (not (read-list-isempty lyskom-to-do-list))
1271
1272
        (while (memq (read-info->type (read-list->first lyskom-to-do-list))
                       lyskom-review-types-list)
David Byers's avatar
David Byers committed
1273
1274
1275
1276
          (set-read-list-del-first lyskom-to-do-list)
          (setq found t)))

    (unless found (lyskom-insert 'not-reviewing))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
1277
1278
1279
1280
1281
1282
1283
1284


;;; ================================================================
;;;          ]terse det kommenterade - View commented text

;;; Author: Inge Wallin


1285
(def-kom-command kom-review-comments (text-no)
1286
1287
1288
1289
1290
1291
1292
1293
  "Review all comments to the selected text text. This command only
reviews one level of comments. To see the entire comment tree, use
`kom-review-tree' instead.

This command accepts text number prefix arguments \(see
`lyskom-read-text-no-prefix-arg').

See `kom-review-uses-cache', `kom-review-priority' and
1294
`kom-review-marks-texts-as-read' for information on settings that affect
1295
all review-related functions."
David Byers's avatar
David Byers committed
1296
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-comments-q)))
1297
  (lyskom-tell-internat 'kom-tell-review)
1298
  (cond (text-no
1299
1300
         (unless kom-review-uses-cache
           (cache-del-text-stat text-no))
1301
1302
         (lyskom-review-comments
          (blocking-do 'get-text-stat text-no)))
1303
        (t (lyskom-insert-string 'read-text-first))))
1304
1305
1306
1307
1308


(defun lyskom-review-comments (text-stat)
  "Handles the return from the initiate-get-text-stat, displays and builds list."
  (let* ((misc-info-list (and text-stat
Per Cederqvist's avatar
.    
Per Cederqvist committed
1309
1310
1311
			      (text-stat->misc-info-list text-stat)))
	 (misc-infos (and misc-info-list
			  (append (lyskom-misc-infos-from-list 
David Kågedal's avatar
David Kågedal committed
1312
				   'FOOTN-IN misc-info-list)
Per Cederqvist's avatar
.    
Per Cederqvist committed
1313
				  (lyskom-misc-infos-from-list 
David Kågedal's avatar
David Kågedal committed
1314
				   'COMM-IN misc-info-list))))
1315
	 (all-text-nos (and misc-infos
Per Cederqvist's avatar
.    
Per Cederqvist committed
1316
1317
1318
1319
1320
1321
1322
			(mapcar
			 (function
			  (lambda (misc-info)
			    (if (equal (misc-info->type misc-info)
				       'COMM-IN)
				(misc-info->comm-in misc-info)
			      (misc-info->footn-in misc-info))))
1323
1324
1325
1326
			 misc-infos)))
         text-nos)
    ;; Only try to review texts that we can read.
    (while all-text-nos
1327
1328
      (unless kom-review-uses-cache
        (cache-del-text-stat (car all-text-nos)))
1329
1330
1331
      (if (blocking-do 'get-text-stat (car all-text-nos))
          (setq text-nos (cons (car all-text-nos) text-nos)))
      (setq all-text-nos (cdr all-text-nos)))
Joel Rosdahl's avatar
Joel Rosdahl committed
1332
    (setq text-nos (nreverse text-nos))
1333

Per Cederqvist's avatar
.    
Per Cederqvist committed
1334
1335
1336
1337
    (if text-nos
	(progn
	  (lyskom-format-insert 'review-text-no (car text-nos))
	  (if (cdr text-nos)
1338
1339
1340
1341
1342
              (lyskom-review-enter-read-info
               (lyskom-create-read-info
                'REVIEW nil (lyskom-review-get-priority)
                (lyskom-create-text-list (cdr text-nos))
                lyskom-current-text) t))
1343
1344
1345
          ;; Don't check the no-cache thing here since we already
          ;; did earlier. We may end up slightly out of sync with
          ;; the server, but not so anyone will really notice.
1346
	  (lyskom-view-text (car text-nos)))
1347
      (lyskom-insert-string 'no-such-text))))
1348
1349
1350
1351
1352
1353
1354
1355


;;; ================================================================
;;;          ]terse igen - kom-review-last-normally-read
;;;
;;; Author: Linus Tolke


David Byers's avatar
David Byers committed
1356
(def-kom-command kom-review-last-normally-read (no)
1357
1358
1359
1360
1361
  "Reviews the N texts most recently read using normal commands.
After reviewing a number of texts, this will show the N texts
read prior to that.

See `kom-review-uses-cache', `kom-review-priority' and
1362
`kom-review-marks-texts-as-read' for information on settings that affect
1363
all review-related functions."
1364
1365
1366
  (interactive 
   (list 
    (lyskom-read-number (lyskom-get-string 'read-normally-read) 1)))
1367
  (lyskom-tell-internat 'kom-tell-review)
1368
  (let* ((text-nos (nreverse (nfirst no lyskom-normally-read-texts))))
1369
1370
1371
1372
    (if text-nos
	(progn
	  (lyskom-format-insert 'review-text-no (car text-nos))
	  (if (cdr text-nos)
1373
1374
1375
1376
1377
	      (lyskom-review-enter-read-info
               (lyskom-create-read-info
                'REVIEW nil (lyskom-review-get-priority)
                (lyskom-create-text-list (cdr text-nos))
                lyskom-current-text) t))
1378
1379
          (unless kom-review-uses-cache
            (cache-del-text-stat (car text-nos)))
1380
	  (lyskom-view-text (car text-nos)))
David Byers's avatar
David Byers committed
1381
      (lyskom-format-insert 'no-such-text))))
David Kågedal's avatar
David Kågedal committed
1382
1383


1384
1385
1386
1387
1388
;;; ============================================================
;;;        Återse omodifierat - Review a non-converted text

;;; Author: Linus Tolke
;;; Modified by: Johan Sundström
David Kågedal's avatar
David Kågedal committed
1389

1390
(def-kom-command kom-review-noconversion (text-no)
1391
1392
1393
1394
1395
1396
  "Displays the selected text without any conversions or filtering
\(i.e. no conversion of HTML, no automatic line breaks, all header
lines etc).

This command accepts text number prefix arguments \(see
`lyskom-read-text-no-prefix-arg')."
1397
  (interactive (list (lyskom-read-text-no-prefix-arg 'review-noconversion-q)))
1398
1399
1400
1401
  (if text-no
      (let ((lyskom-format-special nil)
            (kom-smileys nil)
            (kom-autowrap nil))
1402
1403
          (unless kom-review-uses-cache
            (cache-del-text-stat text-no))
David Byers's avatar