review.el 26.5 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991  Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 1, or (at your option) 
;;;;; 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
25
26
27
28
29
30
31
32
33
34
35
36
37
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; 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.
;;;;


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


43
44
45
46

(defun lyskom-intersection (a b)
  "Returns as a list the intersection of list A and list B.
The order of the list a is kept."
47
48
49
50
51
52
53
  (if (or a b)
      (let ((list nil))
        (while a
          (if (memq (car a) b)
              (setq list (cons (car a) list)))
          (setq a (cdr a)))
        (nreverse list))))
54
55
56
57
58
59

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


Per Cederqvist's avatar
.    
Per Cederqvist committed
60
61
62
;;; ================================================================
;;;              ]terse av, till - Review by X to Conference Y.

63
;;; Author: David Byers, David Kågedal, Linus Tolke
64

Per Cederqvist's avatar
.    
Per Cederqvist committed
65

66
67
68
69
70
71
(def-kom-command kom-review-all ()
  "Review every articles of an author written to a conference."
  (interactive)
  (lyskom-tell-internat 'kom-tell-review)
  (lyskom-review-by-to 0))

Per Cederqvist's avatar
.    
Per Cederqvist committed
72

73
74
75
76
77
78
79
80
81
82
(def-kom-command kom-review-first (&optional count)
  "Reviews all articles of author that is written to conference recipient.
If return is given instead of an author then all authors to that conference is
shown. If return is given instead of conference then all conferences for that
person is chosen.
If a negative numeric argument is given then only the last COUNT articles are 
chosen. If the argument is positive then the first -COUNT articles are chosen.
If the argument is zero the all articles are chosen.
No argument is equivalent to COUNT 1.
The defaults for this command is the conference that you are in."
83
  (interactive "P")
84
85
86
87
88
  (lyskom-tell-internat 'kom-tell-review)
  (lyskom-review-by-to (- (or count
                           (lyskom-read-number
                            (lyskom-get-string 'review-how-many) 1)))))

89

David Kågedal's avatar
David Kågedal committed
90
(def-kom-command kom-review-by-to (&optional count)
Per Cederqvist's avatar
.    
Per Cederqvist committed
91
92
93
94
95
96
97
98
99
  "Reviews all articles of author that is written to conference recipient.
If return is given instead of an author then all authors to that conference is
shown. If return is given instead of conference then all conferences for that
person is chosen.
If a positive numeric argument is given then only the last COUNT articles are 
chosen. If the argument is negative then the first -COUNT articles are chosen.
If the argument is zero the all articles are chosen.
No argument is equivalent to COUNT 1.
The defaults for this command is the conference that you are in."
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  (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)
115
                             (lyskom-get-string 'everything))
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
                            ((> 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))
              'pers 'empty nil t))
         (to (lyskom-read-conf-no 
              (lyskom-format 'review-info
                             (lyskom-format 'info-to-conf info))
              'all 
              ;; If person is not given we must give
              ;; conf
              (not (zerop by))
              (if (zerop lyskom-current-conf)
                  ""
                (conf-stat->name
                 (blocking-do 'get-conf-stat
                              lyskom-current-conf)))
              t)))
David Kågedal's avatar
David Kågedal committed
137
138

    (if (not (zerop to))
139
        (cache-del-conf-stat to))
David Kågedal's avatar
David Kågedal committed
140
    (if (not (zerop by)) 
141
        (cache-del-pers-stat by))
David Kågedal's avatar
David Kågedal committed
142
    (let* ((info-by (if (zerop by) 
143
144
145
146
147
                        (lyskom-get-string 'anybody)
                      (blocking-do 'get-conf-stat by)))
           (info-to (if (zerop to)
                        (lyskom-get-string 'all-confs)
                      (blocking-do 'get-conf-stat to))))
David Kågedal's avatar
David Kågedal committed
148
      (lyskom-format-insert 'review-info-by-to
149
150
151
                            info
                            info-by
                            info-to))
David Kågedal's avatar
David Kågedal committed
152
153
154

    (let ((list (lyskom-get-texts-by-to by to count)))
      (if list
155
156
157
158
159
160
161
          (read-list-enter-read-info (lyskom-create-read-info
                                      'REVIEW
                                      nil
                                      (lyskom-get-current-priority)
                                      (lyskom-create-text-list list)
                                      nil t)
                                     lyskom-reading-list t)
David Kågedal's avatar
David Kågedal committed
162
      	(lyskom-insert-string 'no-such-text)))))
163

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

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
;;; ================================================================
;;; 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.
;;;


(defun lyskom-get-texts-by-to (by to num)
  "Get NUM texts writteb by person number BY in conference number TO
Args: BY TO NUM"
    (cond ((and (zerop by) 
                (zerop to)) nil)
          ((zerop to) (lyskom-get-texts-by by num))
          ((zerop by) (lyskom-get-texts-to to num))
          (t (lyskom-get-texts-by-and-to by to num))))



;;; ================================================================
;;; lyskom-get-texts-by-and-to
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
;;; 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
;;; to-list we have retreived so far.
;;;
;;; 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.
;;;
;;;
;;; +++ FIXME: In some cases this function can take a long time. If
;;; the total number of texts in the conference is low, but they were
;;; written a long time ago, we'll be scanning the user's map
;;; uselessly for a long time. The same is true if the user's map is
;;; small and the conference gets lots of traffic. In some cases it
David Kågedal's avatar
David Kågedal committed
234
;;; might actually be faster to look at and filter the text-stats in
235
236
237
238
239
;;; the smaller map. The fact that the user's map _is_ sorted in
;;; ascending order might also be a source for some sort of
;;; optimization.
;;;
;;;
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

(defun lyskom-get-texts-by-and-to (persno confno num)
  "Get NUM texts written by person PERSNO with conference CONFNO as a
recipient. 
Args: persno confno num"
  (let* ((persstat (blocking-do 'get-pers-stat persno))
         (confstat (blocking-do 'get-conf-stat confno))
         (result-list nil)
         (by-list nil)
         (to-list nil)
         (result-size 0)
         (by nil)
         (to nil)
         (increment 30)
         (plow (pers-stat->first-created-text persstat))
         (phigh (1- (+ plow (pers-stat->no-of-created-texts persstat))))
256
         (pmark (if (and num (< num 0)) plow phigh))
257
258
         (clow (conf-stat->first-local-no confstat))
         (chigh (1- (+ clow (conf-stat->no-of-texts confstat))))
259
260
261
262
263
         (cmark (if (and num (< num 0)) clow chigh)))

    (if (null num)
        (setq num (1+ phigh)))
          
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

    (while (and (or (and (<= pmark phigh)
                         (>= pmark plow))
                    (and (<= cmark chigh)
                         (>= cmark clow)))
                (> (abs num) result-size))
      (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))))))
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
      ;;
      ;;    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))
313
314
      

315
316
317
318
319
320
321
322
323
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
      ;;
      ;;    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))))

    ;;
    ;;  Extract results
    ;;

    (setq result-list
          (apply 'nconc (if (< num 0)
                            (nreverse result-list)
                          result-list)))

    (if (> num 0)
        (nthcdr (- (length result-list) num) result-list)
350
      (nfirst (- num)  result-list))))
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

;;; ===============================================================
;;; lyskom-get-texts-generic
;;; Author: David Byers
;;;
;;; This function gets NUM texts from the start or end of a map.
;;; It works by fetching INCREMENT texts at a time, removing zeroes
;;; and appending to what it already has. INCREMENT starts out as the
;;; number of texts still to go, but is incremented each time no
;;; new texts are returned (when only zeroes are returned)
;;;

(defun lyskom-get-texts-generic (objnum num low high get-operation)
  "From object OBJNUM (a person or conference number) get NUM texts.
  LOW is the lowest local text number and HIGH the highest in the
  conference or person map. GET-OPERATION is the blocking-do operation
  to use to get texts (get-map or get-created-texts)."
369
370
  (if (null num)
      (setq num (1+ high)))
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  (let* ((result nil)
         (increment (abs num))
         (mark (if (< num 0) low high)))

    (while (and (<= mark high)
                (>= mark low)
                (> (abs num) (length result)))
      (let ((found (lyskom-remove-zeroes
                    (listify-vector
                     (map->text-nos
                      (blocking-do get-operation
                                   objnum
                                   (if (< num 0)
                                       mark
                                     (- mark (1- increment)))
                                   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 150 (* increment 2)))
          (setq increment (- (abs num) (length result))))))

    (if (> num 0)
        (nthcdr (- (length result) num) result)
      (nfirst (- num)  result))))


(defun lyskom-get-texts-by (persno num)
  "Get NUM texts written by PERSNO. Args: persno num"
  (let* ((persstat (blocking-do 'get-pers-stat persno))
         (plow (pers-stat->first-created-text persstat))
406
407
408
409
410
         (phigh (1- (+ plow (pers-stat->no-of-created-texts persstat))))
         (new-data t)
         (remaining num)
         (result-list nil))

411
412
413
414
    (if (null num)
        (setq num (1+ phigh)
              remaining (1+ phigh)))

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
    ;;  +++
    ;;  Get segments of the user's map until we have enough results
    ;;  FIXME: The code in lyskom-get-texts-generic should be moved to
    ;;  lyskom-get-texts-by and lyskom-get-texts-to so lyskom-get-texts-to
    ;;  could be a little more efficient. Now it will call 
    ;;  lyskom-get-texts-generic with a remaining of one way too often.
    ;;

    (while (and new-data
                (< (length result-list) (abs num)))
      (setq new-data
            (lyskom-get-texts-generic persno 
                                      remaining
                                      plow
                                      phigh
                                      'get-created-texts))
      (if new-data
          (progn
            (if (< num 0)
                (setq plow (+ plow (length new-data)))
              (setq phigh (- phigh (length new-data))))

            (mapcar
             (function
              (lambda (x) (initiate-get-text-stat 'main nil x)))
             new-data)
            (lyskom-wait-queue 'main)
            (while new-data
              (if (cache-get-text-stat (car new-data))
                  (setq result-list (cons (car new-data) result-list)))
              (setq new-data (cdr new-data)))
            (setq remaining (- num (length result-list)))
            (setq new-data t))))
    (nreverse result-list)))
449
450
451
452
453
454
455
456
457
458
459
460
461


(defun lyskom-get-texts-to (confno num)
  "From CONFNO get NUM texts."
  (let* ((confstat (blocking-do 'get-conf-stat confno))
         (clow (conf-stat->first-local-no confstat))
         (chigh (1- (+ clow (conf-stat->no-of-texts confstat)))))
    (lyskom-get-texts-generic confno num clow chigh 'get-map)))





Per Cederqvist's avatar
.    
Per Cederqvist committed
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480


(defun kom-review-backward ()
  "Toggles the reviewing order.
If reading forward then starts reading backward and the other way round."
  (interactive)
  (lyskom-start-of-command 'kom-review-backward)
  (cond
   ((and (not (read-list-isempty lyskom-reading-list))
	 (or (eq (read-info->type (read-list->first lyskom-reading-list))
		 'REVIEW)
	     (eq (read-info->type (read-list->first lyskom-reading-list))
		 'REVIEW-MARK)))
    (let* ((info (read-list->first lyskom-reading-list))
	   (list (read-info->text-list info))
	   (texts (cdr list))
	   (forward (read-info->forward info)))
      (setcdr list (nreverse (cdr list)))
      (set-read-info->forward info (not forward))
481
482
483
484
      (lyskom-format-insert 'you-review 
			    (lyskom-get-string (if (not forward)
						   'forward
						 'backward)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
   (t
    (lyskom-insert-string 'illegal-command)))
  (lyskom-end-of-command)) 


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

;;; Author: Linus Tolke


(defun kom-review-tree (&optional text-no)
  "Review all comments to this text.
Descends recursively in the comment-tree without marking the texts as read.
The tree is forgotten when a kom-go-to-next-conf command is issued.
If optional prefix argument TEXT-NO is present view tree from that text 
instead. In this case the text TEXT-NO is first shown." 
David Kågedal's avatar
David Kågedal committed
502
  (interactive (list
Per Cederqvist's avatar
.    
Per Cederqvist committed
503
504
505
506
507
508
509
510
		(cond
		 ((null current-prefix-arg)
		  lyskom-current-text)
		 ((integerp current-prefix-arg)
		  current-prefix-arg)
		 (t
		  (signal 'lyskom-internat-error '(kom-review-tree))))))
  (lyskom-start-of-command 'kom-review-tree)
David Kågedal's avatar
David Kågedal committed
511
  (unwind-protect
Per Cederqvist's avatar
.    
Per Cederqvist committed
512
      (progn
David Kågedal's avatar
David Kågedal committed
513
514
515
516
517
518
519
520
	(lyskom-tell-internat 'kom-tell-review)
	(if text-no
	    (let ((ts (blocking-do 'get-text-stat text-no)))
	      (lyskom-follow-comments ts
				      nil 'review
				      (lyskom-get-current-priority)
				      t))
	  (lyskom-insert-string 'read-text-first)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
521
522
523
    (lyskom-end-of-command)))


David Byers's avatar
David Byers committed
524
(defun kom-find-root (&optional text-no)
Per Cederqvist's avatar
.    
Per Cederqvist committed
525
526
527
  "Finds the root text of the tree containing the text in lyskom-current-text."
  (interactive)
  (lyskom-start-of-command 'kom-find-root)
David Kågedal's avatar
David Kågedal committed
528
529
530
531
532
  (unwind-protect
      (progn
	(lyskom-tell-internat 'kom-tell-review)
	(cond
	 (lyskom-current-text 
David Byers's avatar
David Byers committed
533
534
	  (let* ((ts (blocking-do 'get-text-stat (or text-no 
						     lyskom-current-text)))
David Kågedal's avatar
David Kågedal committed
535
536
537
538
539
540
541
542
543
		 (r (lyskom-find-root ts ts)))
	    (if r
		(lyskom-view-text r)
	      (signal 'lyskom-internal-error "Could not find root"))
	    )
	  )
	 (t
	  (lyskom-insert-string 'read-text-first))))
    (lyskom-end-of-command)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
544
545


David Kågedal's avatar
David Kågedal committed
546
(def-kom-command kom-find-root-review ()
Per Cederqvist's avatar
.    
Per Cederqvist committed
547
548
549
  "Finds the root text of the tree containing the text in lyskom-current-text and
reviews the whole tree in deep-first order."
  (interactive)
550
  (lyskom-tell-internat 'kom-tell-review)
Per Cederqvist's avatar
.    
Per Cederqvist committed
551
552
  (cond
   (lyskom-current-text
David Kågedal's avatar
David Kågedal committed
553
554
555
    (lyskom-review-tree
     (lyskom-find-root (blocking-do 'get-text-stat lyskom-current-text)
		       nil)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
556
   (t
David Kågedal's avatar
David Kågedal committed
557
    (lyskom-insert-string 'read-text-first))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
558
559


David Kågedal's avatar
David Kågedal committed
560
(defun lyskom-find-root (text-stat old-text-stat)
Per Cederqvist's avatar
.    
Per Cederqvist committed
561
562
563
564
565
566
567
  "Finds the root text of the tree containing the text TEXT-STAT.
Args: TEXT-STAT OLD-TEXT-STAT THENDO
If TEXT-STAT is nil and OLD-TEXT-STAT contains a text-stat
then this means that the parent of the text in OLD-TEXT-STAT is not readable
and the text in OLD-TEXT-STAT is to be used instead.
If both TEXT-STAT and OLD-TEXT-STAT is nil then this means we are not allowed
to read the text we are trying to find the root of. This just returns with a
David Kågedal's avatar
David Kågedal committed
568
message."
Per Cederqvist's avatar
.    
Per Cederqvist committed
569
570
  (let* ((ts text-stat)
	 (misclist (and ts (text-stat->misc-info-list ts)))
David Kågedal's avatar
David Kågedal committed
571
	 (res nil))
Per Cederqvist's avatar
.    
Per Cederqvist committed
572
573
    (cond
     (ts				;+++ Smartare errorhantering hit.
David Kågedal's avatar
David Kågedal committed
574
      (setq res 'noparents)
Per Cederqvist's avatar
.    
Per Cederqvist committed
575
576
577
578
579
580
581
582
583
584
      (while misclist
	(let* ((type (misc-info->type (car misclist)))
	       (comm (eq type 'COMM-TO))
	       (yes (or comm
			(eq type 'FOOTN-TO)))
	       (parent-no (if comm
			      (misc-info->comm-to (car misclist))
			    (misc-info->footn-to (car misclist)))))
	  (cond
	   (yes
David Kågedal's avatar
David Kågedal committed
585
586
587
588
589
590
	    (let* ((pts (blocking-do 'get-text-stat parent-no)))
	      (if (setq res (lyskom-find-root pts ts))
		  (setq misclist nil))))
	   (t
	    (setq misclist (cdr misclist))))))
      (if (eq res 'noparents) (text-stat->text-no ts) res))
Per Cederqvist's avatar
.    
Per Cederqvist committed
591
     (old-text-stat
David Kågedal's avatar
David Kågedal committed
592
      (text-stat->text-no old-text-stat))
Per Cederqvist's avatar
.    
Per Cederqvist committed
593
     (t
David Kågedal's avatar
David Kågedal committed
594
      nil))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
595
596
597
598
599


(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
600
Text is a text-no."
Per Cederqvist's avatar
.    
Per Cederqvist committed
601
602
  (cond
   ((integerp text)
603
    (lyskom-view-text text nil t nil (lyskom-get-current-priority) t))
Linus Tolke's avatar
Linus Tolke committed
604
605
606
607
   (t
    (signal 'lyskom-internal-error
	    (list 'lyskom-review-tree
		  "Called with incorrect argument."
David Kågedal's avatar
David Kågedal committed
608
		  text)))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
609
610
611
612
613
614
615
616
617
618
619
620
621
622


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

;;; Author: Linus Tolke


(defun kom-review-next ()
  "Resumes an interupted review by moving all review and review-tree entries in
the lyskom-reading-list to the beginning. i.e by moving all other types to the
end."
  (interactive)
  (lyskom-start-of-command 'kom-review-next)
623
  (lyskom-tell-internat 'kom-tell-review)
Per Cederqvist's avatar
.    
Per Cederqvist committed
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
  (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)))
      (setq len (1- len))))
  (lyskom-end-of-command))


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

;;; Author: Linus


(defun kom-review-stack ()
  "Displays the review-stack."
  (interactive)
  (lyskom-start-of-command 'kom-review-stack)
  (mapcar
   (function
    (lambda (info)
      (let ((un (length (cdr (read-info->text-list info))))
	    (type (read-info->type info))
	    (cto (read-info->comm-to info)))
	(cond
	 ((eq type 'REVIEW)
	  (lyskom-format-insert 'review-n-texts un))
	 ((eq type 'REVIEW-TREE)
	  ; +++ Hmmm. Pluralformer. Besv{rligt!
Linus Tolke's avatar
Linus Tolke committed
659
660
661
	  (if (= un 1)
	      (lyskom-format-insert 'review-one-comment cto)
	    (lyskom-format-insert 'review-many-comments cto un)))
Per Cederqvist's avatar
.    
Per Cederqvist committed
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
	 ((eq type 'REVIEW-MARK)
	  (lyskom-format-insert 'review-marked un))))))
   (read-list->all-entries lyskom-reading-list))
  (lyskom-end-of-command))


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

;;; Author: Linus Tolke


(defun kom-review-clear ()
  "Deletes all review-types from the lyskom-reading-list and lyskom-to-do-list."
  (interactive)
  (lyskom-start-of-command 'kom-review-clear)
  (if (not (read-list-isempty lyskom-reading-list))
      (while (or (eq (read-info->type (read-list->first lyskom-reading-list))
		     'REVIEW)
		 (eq (read-info->type (read-list->first lyskom-reading-list))
		     'REVIEW-TREE)
		 (eq (read-info->type (read-list->first lyskom-reading-list))
		     'REVIEW-MARK))
	(set-read-list-del-first lyskom-reading-list)))
  (if (not (read-list-isempty lyskom-to-do-list))
      (while (or (eq (read-info->type (read-list->first lyskom-to-do-list))
		     'REVIEW)
		 (eq (read-info->type (read-list->first lyskom-to-do-list))
		     'REVIEW-TREE)
		 (eq (read-info->type (read-list->first lyskom-to-do-list))
		     'REVIEW-MARK))
	(set-read-list-del-first lyskom-to-do-list)))
  (lyskom-end-of-command))


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

;;; Author: Inge Wallin


703
(def-kom-command kom-review-comments ()
Per Cederqvist's avatar
.    
Per Cederqvist committed
704
705
706
707
  "View the comments to this text.
If the current text has comments in (footnotes in) some texts then the first
text is shown and a REVIEW list is built to shown the other ones."
  (interactive)
708
  (lyskom-tell-internat 'kom-tell-review)
709
710
711
712
713
714
715
  (lyskom-review-comments
   (blocking-do 'get-text-stat lyskom-current-text)))


(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
716
717
718
			      (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
719
				   'FOOTN-IN misc-info-list)
Per Cederqvist's avatar
.    
Per Cederqvist committed
720
				  (lyskom-misc-infos-from-list 
David Kågedal's avatar
David Kågedal committed
721
				   'COMM-IN misc-info-list))))
Per Cederqvist's avatar
.    
Per Cederqvist committed
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
	 (text-nos (and misc-infos
			(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))))
			 misc-infos))))
    (if text-nos
	(progn
	  (lyskom-format-insert 'review-text-no (car text-nos))
	  (if (cdr text-nos)
	      (read-list-enter-read-info
	       (lyskom-create-read-info
		'REVIEW nil (lyskom-get-current-priority)
		(lyskom-create-text-list (cdr text-nos))
		lyskom-current-text)
	       lyskom-reading-list t))
741
	  (lyskom-view-text (car text-nos)))
742
      (lyskom-insert-string 'no-such-text))))
743
744
745
746
747
748
749
750
751
752
753
754
755
756


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


(defun kom-review-last-normally-read (no)
  "Reviews the NO last normally read texts."
  (interactive 
   (list 
    (lyskom-read-number (lyskom-get-string 'read-normally-read) 1)))
  (lyskom-start-of-command 'kom-review-last-normally-read)
757
  (lyskom-tell-internat 'kom-tell-review)
758
759
760
761
762
763
764
765
766
767
768
  (let* ((text-nos (reverse (nfirst no lyskom-normally-read-texts))))
    (if text-nos
	(progn
	  (lyskom-format-insert 'review-text-no (car text-nos))
	  (if (cdr text-nos)
	      (read-list-enter-read-info
	       (lyskom-create-read-info
		'REVIEW nil (lyskom-get-current-priority)
		(lyskom-create-text-list (cdr text-nos))
		lyskom-current-text)
	       lyskom-reading-list t))
769
	  (lyskom-view-text (car text-nos)))
770
      (lyskom-format-insert 'no-such-text)))
771
  (lyskom-end-of-command))
772