commands2.el 51.8 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
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: commands2.el
;;;;
;;;; This file contains the code for some high level commands.
;;;;

33
34
35
36
37
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))


Per Cederqvist's avatar
.  
Per Cederqvist committed
38
39
40
41
42
43
44
;;; ================================================================
;;;              Lista medlemsskap - List membership

;;; Author: Linus Tolke
;;; Rewritten by ceder


45
;; This functions is left in its "asynchronous way".
David Kågedal's avatar
David Kågedal committed
46
(def-kom-command kom-membership ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
47
48
  "Show memberships last visited, priority, unread and name."
  (interactive)
49
50
  (let ((buf (current-buffer))
	(buffer (get-buffer-create (concat (buffer-name (current-buffer))
Per Cederqvist's avatar
.  
Per Cederqvist committed
51
52
53
					   "-membership"))))
    (save-window-excursion
      (set-buffer buffer)
54
      (make-local-variable 'lyskom-buffer)
55
      (local-set-key [mouse-2] 'kom-mouse-2)
56
      (setq lyskom-buffer buf)
Per Cederqvist's avatar
.  
Per Cederqvist committed
57
58
59
60
61
62
63
64
      (erase-buffer)
      (insert (lyskom-get-string 'your-memberships))
      (insert (lyskom-get-string 'memberships-header)))
    (display-buffer buffer)
    (lyskom-traverse
     x lyskom-membership
     (initiate-get-conf-stat 'membership 'lyskom-memb-received-1
			     (membership->conf-no x)
David Kågedal's avatar
David Kågedal committed
65
			     x buffer))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

(defun lyskom-memb-received-1 (conf-stat membership buffer)
  "Part of kom-membership.
Get maps for the conference CONF-STAT. MEMBERSHIP is the users
membership in that conference. Call lyskom-memb-received with
the resulting MAP, CONF-STAT, MEMBERSHIP and BUFFER.
Args: CONF-STAT MEMBERSHIP BUFFER."
  (if (/= (conf-stat->conf-no conf-stat)
	  (membership->conf-no membership))
      (signal 'lyskom-internal-error '("lyskom-memb-received-1")))
  (let ((first-wanted (1+ (membership->last-text-read membership)))
	(last-existing  (+ (conf-stat->first-local-no conf-stat)
			   (conf-stat->no-of-texts conf-stat)
			   -1)))
    (if (> first-wanted last-existing)
	(lyskom-run 'membership 'lyskom-memb-received
		    nil conf-stat membership buffer)
      (initiate-get-map 'membership 'lyskom-memb-received
			(membership->conf-no membership)
			first-wanted
			(+ 1 last-existing
			   (- first-wanted))
			conf-stat membership buffer))))

(defun lyskom-memb-received (map conf-stat membership buffer)
  "Args: MAP CONF-STAT MEMBERSHIP BUFFER.
Prints membership in a conferences.
MAP may be nil if there are no new texts."
  (save-window-excursion
    (set-buffer buffer)
    (goto-char (point-max))
97
    (lyskom-format-insert 'memberships-line
David Byers's avatar
David Byers committed
98
			  (lyskom-return-date-and-time  (membership->last-time-read
99
100
101
102
103
104
						membership))
			  (membership->priority membership)
			  (if map
			      (length (lyskom-list-unread map membership))
			    0)
			  conf-stat)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
105
106
107
108
109
110
111
112
113


;;; ================================================================
;;;          Status (f|r) M|te - Status for a conference

;;; Author: ceder (with some help by Linus)
;;; much enhanced by Inge Wallin (lyskom-status-conf-2 and beyond)


David Kågedal's avatar
David Kågedal committed
114
(def-kom-command kom-status-conf (&optional conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
115
116
117
118
  "Prints conference status.
If argument CONF-NO is existing and non-nil then this conference is used. 
otherwise: the conference is read with lyskom-completing-read."
  (interactive)
David Kågedal's avatar
David Kågedal committed
119
120
121
  (let ((conf-no
	 (or conf-no
	     (lyskom-read-conf-no (lyskom-get-string 'conf-for-status)
122
				  '(all) nil nil t)))
David Kågedal's avatar
David Kågedal committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
	conf-stat)
    (cache-del-conf-stat conf-no)
    (setq conf-stat (blocking-do 'get-conf-stat conf-no))
    (if (null conf-stat)
	(lyskom-insert-string 'no-such-conf)
      (let* ((type (conf-stat->conf-type conf-stat))
	     (box (conf-type->letterbox type))
	     (ori (conf-type->original type))
	     (pro (conf-type->rd_prot type))
	     (sec (conf-type->secret type)))
	(lyskom-format-insert 'status-record
			      conf-stat
			      conf-stat
			      (cond
			       ((or box ori pro sec)
David Kågedal's avatar
David Kågedal committed
138
139
140
141
142
143
144
145
146
147
148
149
				(concat
				 "("
				 (if box (lyskom-get-string 'Mailbox) "")
				 (if (and box (or sec ori pro)) ", " "")
				 (if sec (lyskom-get-string
					  'Protected) "")
				 (if (and sec (or ori pro)) ", " "")
				 (if ori (lyskom-get-string
					  'no-comments) "")
				 (if (and ori pro) ", " "")
				 (if pro (lyskom-get-string 'closed) "")
				 ")"))
David Kågedal's avatar
David Kågedal committed
150
			       (t ""))))
David Kågedal's avatar
David Kågedal committed
151
      (let ((creator (conf-stat->creator conf-stat)))
David Kågedal's avatar
David Kågedal committed
152
153
154
155
156
157
158
159
160
161
	(lyskom-format-insert 'created-by
			      creator
			      creator
			      (if (and 
				   (lyskom-conf-stat-p creator)
				   (> (length (conf-stat->name creator))
				      (- (lyskom-window-width) 46)))
				  "\n"
				"")))
      (lyskom-format-insert 'created-at
David Byers's avatar
David Byers committed
162
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
163
164
165
166
167
168
169
170
171
172
173
			     (conf-stat->creation-time conf-stat)))
      (lyskom-format-insert 'members
			    (conf-stat->no-of-members conf-stat))
      (lyskom-format-insert 'garb-nice
			    (conf-stat->garb-nice conf-stat))
      (lyskom-format-insert 'lowest-local-no
			    (conf-stat->first-local-no conf-stat))
      (lyskom-format-insert 'highest-local-no
			    (1- (+ (conf-stat->no-of-texts conf-stat)
				   (conf-stat->first-local-no conf-stat))))
      (lyskom-format-insert 'last-text-time
David Byers's avatar
David Byers committed
174
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
175
176
177
			     (conf-stat->last-written conf-stat)))
      (lyskom-format-insert 'no-of-motd
			    (conf-stat->msg-of-day conf-stat))
David Kågedal's avatar
David Kågedal committed
178
      (let ((superconf (conf-stat->super-conf conf-stat)))
David Kågedal's avatar
David Kågedal committed
179
180
181
182
183
184
185
186
187
	(lyskom-format-insert 'superconf-is-no-name
			      superconf
			      superconf
			      (if (and 
				   (lyskom-conf-stat-p superconf)
				   (> (length (conf-stat->name superconf))
				      (- (lyskom-window-width) 46)))
				  "\n"
				"")))
David Kågedal's avatar
David Kågedal committed
188
      (let ((permitted-submitters (conf-stat->permitted-submitters conf-stat)))
David Kågedal's avatar
David Kågedal committed
189
190
	(lyskom-format-insert 'permitted-submitters-no-name
			      permitted-submitters
David Kågedal's avatar
David Kågedal committed
191
192
193
194
195
			      (if (zerop permitted-submitters)
				  (lyskom-get-string 'Everybody)
				permitted-submitters)
			      ""))
      (let ((supervisor (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
196
197
198
	(lyskom-format-insert 'supervisor-is-no-name
			      supervisor
			      supervisor
David Kågedal's avatar
David Kågedal committed
199
			      ""))
David Kågedal's avatar
David Kågedal committed
200
201
202
203
204
205
206
207
      (lyskom-format-insert 'presentation-no
			    (conf-stat->presentation conf-stat))

      (if (zerop (conf-stat->msg-of-day conf-stat))
	  nil
	(lyskom-format-insert 'conf-has-motd conf-stat)
	(lyskom-view-text (conf-stat->msg-of-day conf-stat)))

208
      ;; Show all members of CONF-STAT if the user so wishes."
David Kågedal's avatar
David Kågedal committed
209
      (lyskom-scroll)
David Kågedal's avatar
David Kågedal committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
      (if (lyskom-j-or-n-p
	   (lyskom-get-string 'show-members-list-also-q))
	  (let ((member-list (blocking-do 'get-members
					  (conf-stat->conf-no conf-stat)
					  0 lyskom-max-int)))
	    
	    (lyskom-format-insert 'conf-has-these-members
				  conf-stat)
	    (if (lyskom-j-or-n-p (lyskom-get-string 'show-membership-info-q))
		
		(progn
		  (lyskom-insert-string 'member-list-header)
		  (lyskom-traverse 
		   member (conf-no-list->conf-nos member-list)
		   (let ((membership (blocking-do
				      'query-read-texts 
				      member
				      (conf-stat->conf-no conf-stat))))
		     ;; Print a row describing the membership of MEMBER
		     ;; (described by MEMBERSHIP) in CONF-STAT.
		     (if (or (null membership))
			 (lyskom-insert-string 'secret-membership)
		       (lyskom-insert 
			(format "%17s"
				(lyskom-return-date-and-time
				 (membership->last-time-read membership))))
		       (let ((unread (- (+ (conf-stat->first-local-no
					    conf-stat)
					   (conf-stat->no-of-texts conf-stat))
					(membership->last-text-read membership)
					(length (membership->read-texts
						 membership))
					1)))
			 (lyskom-format-insert 'conf-membership-line
					       (if (zerop unread)
						   "         "
						 (format "%7d  " unread))
					       member))))))
	      
	      ;; Don't show membership info
	      (lyskom-insert "\n")
	      (lyskom-traverse
	       member (conf-no-list->conf-nos member-list)
	       (lyskom-format-insert "  %#1P\n" member))))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
254
255
256
257
258
259
260
261
262


;;; ================================================================
;;;            Status (f|r) Person - status for a person

;;; Author: ceder
;;; Heavily enhanced: Inge Wallin (lyskom-status-pers-3 and beyond)


David Kågedal's avatar
David Kågedal committed
263
(def-kom-command kom-status-person (&optional pers-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
264
265
  "Prints status for a person."
  (interactive)
David Kågedal's avatar
David Kågedal committed
266
  (let ((pers-no
267
268
         (or pers-no
             (lyskom-read-conf-no (lyskom-get-string 'pers-for-status)
269
                                  '(pers) nil "" t)))
David Kågedal's avatar
David Kågedal committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
	conf-stat
	pers-stat)
    (cache-del-conf-stat pers-no)
    (cache-del-pers-stat pers-no)
    (setq pers-stat (blocking-do 'get-pers-stat pers-no))
    (setq conf-stat (blocking-do 'get-conf-stat pers-no))

    ;; "Print status about PERS-STAT. The name is in CONF-STAT"
    (if (or (null pers-stat)
	    (null conf-stat))
	(lyskom-insert-string 'no-such-pers)
      (lyskom-format-insert 'pers-status-record
			    conf-stat
			    conf-stat)
      (lyskom-format-insert 'created-time
David Byers's avatar
David Byers committed
285
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
			     (conf-stat->creation-time conf-stat)))

      (lyskom-format-insert 'created-confs
			    (pers-stat->created-confs pers-stat))
      (lyskom-format-insert 'created-persons
			    (pers-stat->created-persons pers-stat))
      (lyskom-format-insert 'created-texts
			    (1- (+ (pers-stat->no-of-created-texts pers-stat)
				   (pers-stat->first-created-text pers-stat))))
      (lyskom-format-insert 'created-lines
			    (pers-stat->created-lines pers-stat))
      (lyskom-format-insert 'created-chars
			    (pers-stat->created-bytes pers-stat))

      (lyskom-format-insert 'no-of-sessions
			    (pers-stat->sessions pers-stat))
      (if (zerop (pers-stat->total-time-present pers-stat))
	  nil
	(lyskom-format-insert 'present-time-d-h-m-s
			      (/ (pers-stat->total-time-present pers-stat)
				 (* 24 3600))
			      (% (/ (pers-stat->total-time-present pers-stat)
				    3600) 24)
			      (% (/ (pers-stat->total-time-present pers-stat)
				    60) 60)
			      (% (pers-stat->total-time-present pers-stat)
				 60)))
      (lyskom-format-insert 'last-log-in
David Byers's avatar
David Byers committed
314
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
315
316
317
318
319
			     (pers-stat->last-login pers-stat)))
      (lyskom-format-insert 'user-name
			    (pers-stat->username pers-stat))
      (lyskom-format-insert 'read-texts
			    (pers-stat->read-texts pers-stat))
320
321
      (if (= (pers-stat->pers-no pers-stat) lyskom-pers-no)
          (lyskom-format-insert 'marked-texts
David Kågedal's avatar
David Kågedal committed
322
				(pers-stat->no-of-marks pers-stat)))
David Kågedal's avatar
David Kågedal committed
323
      (lyskom-format-insert 'time-for-last-letter
David Byers's avatar
David Byers committed
324
			    (lyskom-return-date-and-time
David Kågedal's avatar
David Kågedal committed
325
326
			     (conf-stat->last-written conf-stat)))

David Kågedal's avatar
David Kågedal committed
327
      (let ((superconf (conf-stat->super-conf conf-stat)))
David Kågedal's avatar
David Kågedal committed
328
329
330
	(lyskom-format-insert 'superconf
			      superconf
			      superconf
David Kågedal's avatar
David Kågedal committed
331
			      ""))
David Kågedal's avatar
David Kågedal committed
332
      (if (not (zerop (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
333
	  (let ((supervisor (conf-stat->supervisor conf-stat)))
David Kågedal's avatar
David Kågedal committed
334
335
336
	    (lyskom-format-insert 'supervisor
				  supervisor
				  supervisor
David Kågedal's avatar
David Kågedal committed
337
				  "")))
David Kågedal's avatar
David Kågedal committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
      (lyskom-format-insert 'member-of-confs
			    (pers-stat->no-of-confs pers-stat))
      (lyskom-format-insert 'presentation
			    (conf-stat->presentation conf-stat))

      (if (not (zerop (conf-stat->msg-of-day conf-stat)))
	  (progn
	    (lyskom-format-insert 'has-motd conf-stat)
	    (lyskom-view-text (conf-stat->msg-of-day conf-stat))))

      ;; "Show all conferences CONF-STAT is a member of if the user so wishes."
      (lyskom-scroll)
      (if (null (lyskom-j-or-n-p (lyskom-get-string
				  'show-membership-list-also-q))) 
	  nil
	(let ((membership-list 
	       (blocking-do 'get-membership
			    (conf-stat->conf-no conf-stat)))
	      (lyskom-count-var 0))

	  (if (null membership-list)
	      (lyskom-format-insert 'not-allowed-see-confs conf-stat)
	    (lyskom-format-insert 'is-member-of conf-stat)
	    (lyskom-insert-string 'membership-list-header)
	    (setq lyskom-count-var 0)
	    (lyskom-traverse
David Kågedal's avatar
David Kågedal committed
364
365
366
367
368
369
370
371
	     membership membership-list
	     (let ((cs (cache-get-conf-stat
			(membership->conf-no membership))))
	       (and cs
		    (lyskom-time-greater
		     (membership->last-time-read membership)
		     (conf-stat->last-written conf-stat))
		    (cache-del-conf-stat (membership->conf-no membership))))
372
		  
David Kågedal's avatar
David Kågedal committed
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
	     ;; "Print a row describing the membership of
	     ;; MEMBER-CONF-STAT
	     (let ((member-conf-stat
		    (blocking-do 'get-conf-stat 
				 (membership->conf-no membership))))
	       (if (or (null member-conf-stat)
		       (null membership))
		   (lyskom-insert-string 'secret-membership)
		 (lyskom-insert 
		  (format "%17s"
			  (lyskom-return-date-and-time
			   (membership->last-time-read membership))))
		 (let ((unread (- (+ (conf-stat->first-local-no
				      member-conf-stat)
				     (conf-stat->no-of-texts
				      member-conf-stat))
				  (membership->last-text-read membership)
				  (length (membership->read-texts
					   membership))
				  1)))
		   (lyskom-format-insert
		    'pers-membership-line
		    (if (zerop unread) "       " (format "%6d " unread))
		    (if (= (conf-stat->conf-no conf-stat)
			   (conf-stat->supervisor member-conf-stat))
			(lyskom-get-string 'is-supervisor-mark)
		      "  ")
		    member-conf-stat)
		   (setq lyskom-count-var (+ lyskom-count-var unread)))))))
David Kågedal's avatar
David Kågedal committed
402
403
404
405
406

	  ;; "Print the total number of unread texts for the person CONF-STAT."
	  (lyskom-format-insert 'his-total-unread 
				conf-stat
				lyskom-count-var))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
407
408
409
410
411
412
413



;;; ================================================================
;;;              Skicka meddelande - Send message

;;; Author: Inge Wallin
414
;;; Rewritten to use lyskom-read-conf-no by Linus Tolke
415
;;; Modified to use default recipient by David Byers
Per Cederqvist's avatar
.  
Per Cederqvist committed
416
417


418
(def-kom-command kom-send-message (&optional who message)
419
  "Send a message to one of the users in KOM right now."
Per Cederqvist's avatar
.  
Per Cederqvist committed
420
  (interactive)
David Kågedal's avatar
David Kågedal committed
421
422
423
424
  (let ((target (or who
		    (lyskom-read-conf-no
		     (format (lyskom-get-string 'who-to-send-message-to)
			     (lyskom-get-string 'everybody))
425
		     '(all) t
David Kågedal's avatar
David Kågedal committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
		     ;; Initial string:
		     (cond
		      ((eq kom-default-message-recipient 'everybody) nil)

		      ((and (eq kom-default-message-recipient 'group)
			    lyskom-last-group-message-recipient)
		       (cons lyskom-last-group-message-recipient 0))

		      ((or (and (eq kom-default-message-recipient 'group)
				(null lyskom-last-group-message-recipient))
			   (and (eq kom-default-message-recipient 'sender)
				lyskom-last-personal-message-sender))
		       (cons lyskom-last-personal-message-sender 0))

		      (t 
		       (if lyskom-last-personal-message-sender
			   (cons lyskom-last-personal-message-sender 0)
			 ""))) t))))
    (if (zerop target)
445
	(lyskom-insert (lyskom-get-string 'message-all-info))
David Kågedal's avatar
David Kågedal committed
446
447
      (lyskom-format-insert 'message-recipient-info target))
    (lyskom-send-message target message)))
Linus Tolke's avatar
Linus Tolke committed
448
  
449

450
(def-kom-command kom-send-alarm (&optional message)
451
452
  "Send a message to all of the users in KOM right now."
  (interactive)
453
  (lyskom-send-message 0 message))
Per Cederqvist's avatar
.  
Per Cederqvist committed
454
455


David Byers's avatar
David Byers committed
456
457
458
459
(defun lyskom-send-message (pers-no message &optional dontshow)
  "Send a message to the person with the number PERS-NO.  PERS-NO == 0
means send the message to everybody. MESSAGE is the message to
send. If DONTSHOW is non-nil, don't display the sent message."
460
461
462
463
464
465
  (let* ((string (or message
                     (lyskom-read-string (lyskom-get-string 'message-prompt))))
         (reply (blocking-do 'send-message pers-no string))
         (to-conf-stat (if (zerop pers-no)
                           nil
                         (blocking-do 'get-conf-stat pers-no))))
466
    (if reply
David Byers's avatar
David Byers committed
467
468
469
470
471
472
473
474
	(if (not dontshow)
	    (lyskom-handle-as-personal-message
	     (if to-conf-stat
		 (lyskom-format 'message-sent-to-user
				string to-conf-stat)
	       (lyskom-format 'message-sent-to-all string))
	     lyskom-pers-no
	     lyskom-filter-outgoing-messages))
475
      (lyskom-format-insert-before-prompt 'message-nope 
476
477
478
                                          (or to-conf-stat
                                              (lyskom-get-string 'everybody))
                                          string)) ;+++ lyskom-errno
479
    ))
Per Cederqvist's avatar
.  
Per Cederqvist committed
480
481
482
483
484
485
486
487
488
489



;;; ================================================================
;;;       Endast l{sa senaste - Set unread articles in a conf. 
;;;            (Skip or re-read articles).

;;; Author: Linus Tolke


490
(def-kom-command kom-set-unread (&optional arg conf-no)
Per Cederqvist's avatar
.  
Per Cederqvist committed
491
  "Set number of unread articles in current conference."
492
  (interactive "P")
493
  (if (and (zerop lyskom-current-conf) (null conf-no))
David Kågedal's avatar
David Kågedal committed
494
      (lyskom-insert-string 'not-present-anywhere)
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
    (let ((conf-stat (blocking-do 'get-conf-stat (or conf-no 
                                                     lyskom-current-conf))))
      (if (null conf-stat)              ;+++ annan errorhantering
          (lyskom-insert "Error!\n")	;+++ Hrrrmmmmffff????
        (let* ((narg (prefix-numeric-value arg))
               (n (if (and arg
                           (<= 0 narg)
                           (<= narg (conf-stat->no-of-texts conf-stat)))
                      narg
                    (lyskom-read-num-range 
                     0 (conf-stat->no-of-texts conf-stat)
                     (lyskom-format 'only-last
                                    (conf-stat->no-of-texts conf-stat)
                                    (conf-stat->name conf-stat)))))
               (result (blocking-do 'set-unread
                                    (conf-stat->conf-no conf-stat) n)))
          (if (null result)
              (lyskom-insert-string 'only-error)
            (lyskom-refetch)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
514
515
516
517
518
519
520
521
522
523



;;; ================================================================
;;;                 Lista Nyheter - List News

;;; Author:   Linus Tolke
;;; Rehacked: Inge Wallin


524
525
526
(defvar lyskom-special-conf-name "\\`Inl.gg .t mig\\'"
  "Regexp to match conf names that are special.")

David Kågedal's avatar
David Kågedal committed
527
(def-kom-command kom-list-news (&optional num)
Per Cederqvist's avatar
.  
Per Cederqvist committed
528
  "Print the number of unread articles to the user."
David Kågedal's avatar
David Kågedal committed
529
530
531
  (interactive "P")
  (lyskom-prefetch-all-confs)
  (let ((num-arg (cond
532
533
534
535
536
                  ((numberp num) num)
                  ((and (listp num)
                        (numberp (car num))) (car num))
                  (t nil)))
        (sum 0))
Per Cederqvist's avatar
.  
Per Cederqvist committed
537
538
539
    (mapcar
     (function
      (lambda (info)
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
        (let ((un (length (cdr (read-info->text-list info))))
              (name (conf-stat->name (read-info->conf-stat info)))
              (conf-stat (read-info->conf-stat info)))
          (cond
           ((eq (read-info->type info) 'CONF)
            (if (or (not num-arg)
                    (>= (-- num-arg) 0))
                (lyskom-insert 
                 (if (and (boundp 'lyskom-special-conf-name)
                          (stringp lyskom-special-conf-name)
                          (string-match lyskom-special-conf-name name))
                     (if (/= un 1)
                         (lyskom-format 'you-have-unreads-special un conf-stat)
                       (lyskom-format 'you-have-an-unread-special conf-stat))
                   (if (/= un 1)
                       (lyskom-format 'you-have-unreads un conf-stat)
                     (lyskom-format 'you-have-an-unread conf-stat)))))
            (setq sum (+ sum un)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
558
559
     (read-list->all-entries lyskom-to-do-list))
    (if (= 0 sum)
560
        (lyskom-insert-string 'you-have-read-everything)
Per Cederqvist's avatar
.  
Per Cederqvist committed
561
562
      (lyskom-insert 
       (if (/= sum 1)
563
564
565
           (lyskom-format 'total-unreads 
                          sum)
         (format (lyskom-get-string 'total-unread)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580


;;; ================================================================
;;; 			V{nta - Idle wait


(defun kom-busy-wait (arg)
  "Sets the kom-session in wait-mode.
The wait-mode is interrupted when a text in a conference with higher priority
than that of the next text to be read.
If you want another priority to break that the ones higher that the next text 
to be read, give the priority as a prefix argument.
When a text is received the new text is displayed."
  (interactive "P")
  (lyskom-start-of-command 'kom-busy-wait)
David Kågedal's avatar
David Kågedal committed
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
  (unwind-protect
      (let ((waitfor (or (cond
			  ((integerp arg) arg)
			  ((listp arg) (car arg)))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 -2)))
	(lyskom-tell-server kom-mercial)
	(if (not (read-list-isempty lyskom-reading-list))
	    (set-read-list-empty lyskom-reading-list))
	(if (= waitfor -2)
	    (lyskom-insert-string 'waiting-for-anything)
	  (lyskom-format-insert 'waiting-higher-than waitfor))
	(lyskom-scroll)
	(setq lyskom-is-waiting
	      (list '>
		    '(or (read-info->priority
			  (read-list->first lyskom-reading-list))
			 (read-info->priority
			  (read-list->first lyskom-to-do-list))
			 257)
		    waitfor))
	(while lyskom-is-waiting
	  ;; This is a bit trial-and-error stuff at the momemt.
	  ;; o How to make personal messages appear *fast*
	  ;; o How to enable C-g with a quick response
David Kågedal's avatar
David Kågedal committed
607
	  (sit-for 0)
David Kågedal's avatar
David Kågedal committed
608
609
610
611
612
613
	  (accept-process-output nil 1)
	  (sit-for 0)
	  (if lyskom-quit-flag
	      (signal 'quit nil))))
    (lyskom-end-of-command))
  ;; We are done waiting
614
  (lyskom-beep kom-ding-on-wait-done)
David Kågedal's avatar
David Kågedal committed
615
616
617
618
  (if (read-list-isempty lyskom-reading-list)
      (kom-go-to-next-conf))
  (kom-next-command))
  
Per Cederqvist's avatar
.  
Per Cederqvist committed
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638


(defun lyskom-time-greater (time1 time2)
  "Returns t if TIME2 is before TIME1 chronologically."
  (cond
   ((< (time->year time2) (time->year time1)))
   ((< (time->mon time2) (time->mon time1)))
   ((< (time->mday time2) (time->mday time1)))
   ((< (time->hour time2) (time->hour time1)))
   ((< (time->min time2) (time->min time1)))
   ((< (time->sec time2) (time->sec time1)))
   (t nil)))


;;; ================================================================
;;;               Lista {rende - list summary

;;; Author: Linus Tolke


David Kågedal's avatar
David Kågedal committed
639
(def-kom-command kom-list-summary ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
640
641
642
643
  "List a summary of the unread in the current conf.
The summary contains the date, number of lines, author and subject of the text
on one line."
  (interactive)
David Kågedal's avatar
David Kågedal committed
644
645
  (if (read-list-isempty lyskom-reading-list)
      (lyskom-insert-string 'have-to-be-in-conf-with-unread)
646
	
David Kågedal's avatar
David Kågedal committed
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
    (lyskom-list-summary
      (text-list->texts 
       (read-info->text-list 
	(let ((list (read-list->all-entries lyskom-reading-list))
	      (len (read-list-length lyskom-reading-list))
	      (r 0))
	  (while (< r len)
	    (let ((type (read-info->type 
			 (read-list->nth lyskom-reading-list
					 r))))
	      (if (or (eq type 'CONF)
		      (eq type 'REVIEW-MARK)
		      (eq type 'REVIEW))
		  (setq len 0)
		(++ r))))
	  (read-list->nth lyskom-reading-list r)))))))

;; This function is commented out untile we might implement marks in a
;; new way. But it works as it is.

;;(def-kom-command kom-list-marks (&optional mark)
;;  "List a summary of marked texts with mark MARK."
;;  (interactive (list (or (and current-prefix-arg
;;			      (prefix-numeric-value current-prefix-arg))
;;			 (lyskom-read-num-range
;;			  1 255
;;			  (lyskom-get-string 'what-mark-to-list)))))
;;  (let ((texts (delq nil
;;		     (mapcar (function
;;			      (lambda (x) (and (= (elt (cdr x) 1) mark)
;;					       (elt (cdr x) 0))))
;;			     (blocking-do 'get-marks)))))
;;    (lyskom-list-summary texts)
;;    (lyskom-format-insert 'you-have-marks (length texts) mark)))


(defun lyskom-list-summary (texts)
  "List a summary of the texts in TEXTS.
The summary contains the date, number of lines, author and subject of the text
on one line."
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
  (let ((time (blocking-do 'get-time))
	(author-width (/ (- (lyskom-window-width) 22) 3)))
    
    ;; Start fetching all text-stats and text to list them.
    (lyskom-format-insert (concat "%-8#1s%-6#2s%-4#3s %-"
				  (int-to-string author-width)
				  "#4s  %#5s\n")
			  (lyskom-get-string 'Texts)
			  (lyskom-get-string 'Date)
			  (lyskom-get-string 'Lines)
			  (lyskom-get-string 'Author)
			  (lyskom-get-string 'Subject))
    (lyskom-traverse
	text-no texts
      (let ((text-stat (blocking-do 'get-text-stat text-no))
	    (text (blocking-do 'get-text text-no))
	    ;; We could do som optimization here. 
	    ;; We really don't need the whole text.
	    )
	(lyskom-print-summary-line text-stat text text-no 
				   (time->year time) (time->yday time))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
708
709


David Kågedal's avatar
David Kågedal committed
710
(defun lyskom-print-summary-line (text-stat text text-no year day)
Per Cederqvist's avatar
.  
Per Cederqvist committed
711
712
713
714
715
716
717
718
719
720
  "Handle the info, fetch the author and print it.
Args: TEXT-STAT TEXT TEXT-NO YEAR DAY.
The year and day is there to be able to choose format on the day.
Format is 23:29 if the text is written today. Otherwise 04-01."
  (if (not (and text-stat text))	;+++ B{ttre felhantering.
      (lyskom-format-insert 'could-not-read text-no)
    (let* ((lines (text-stat->no-of-lines text-stat))
	   (txt (text->text-mass text))
	   (eos (string-match (regexp-quote "\n") txt))
	   (subject (substring txt 0 eos))
David Byers's avatar
David Byers committed
721
	   ;; length of the number %%%%%% :8
Per Cederqvist's avatar
.  
Per Cederqvist committed
722
723
724
725
726
727
728
729
730
731
	   ;; length for time is: 6
	   (time (text-stat->creation-time text-stat))
	   (time (if (and (= year (time->year time))
			  (= day (time->yday time)))
		     (format "%02d:%02d" (time->hour time)
			     		 (time->min time))
		   (format "%02d-%02d" (1+ (time->mon time))
			   	       (time->mday time))))
	   ;; length for lines is: 4
	   ;; We split the rest between author and subject
David Byers's avatar
David Byers committed
732
733
	   (namelen (/ (- (lyskom-window-width) 22) 3))
	   (subjlen (/ (* (- (lyskom-window-width) 22) 2) 3))
734
735
736
737
738
739
740
	   (author-name (lyskom-format "%#1:P" (text-stat->author text-stat)))
	   (format-string (concat "%=-8#1n%#2s%4#3d  %=-"
				  (int-to-string namelen)
				  "#4P  %[%#5@%=-"
				  (int-to-string subjlen)
				  "#6r%]\n")))
      (lyskom-format-insert format-string
741
742
743
			    text-no
			    time
			    lines
744
			    (text-stat->author text-stat)
745
746
			    (lyskom-default-button 'text
						   text-no)
747
			    subject))))
748

Per Cederqvist's avatar
.  
Per Cederqvist committed
749
750


David Byers's avatar
David Byers committed
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
;;; ============================================================
;;;     kom-who-am-i - Vem r jag
;;;
;;; Author: David Byers

(def-kom-command kom-who-am-i ()
  "Show my name"
  (interactive)
  (if (and lyskom-current-conf
           (not (zerop lyskom-current-conf)))
      (lyskom-format-insert 'who-i-am-present 
                            lyskom-pers-no
                            lyskom-current-conf)
    (lyskom-format-insert 'who-i-am-not-present lyskom-pers-no))

  (lyskom-format-insert 
   'who-i-am-server
   lyskom-server-name
   (if (zerop (% (server-info->version lyskom-server-info) 100))
       (format "%d.%d"
               (/ (server-info->version lyskom-server-info) 10000)
               (/ (% (server-info->version lyskom-server-info) 10000) 
                  100))
     (format "%d.%d.%d"
             (/ (server-info->version lyskom-server-info) 10000)
             (/ (% (server-info->version lyskom-server-info) 10000)
                100)
             (% (server-info->version lyskom-server-info) 100))))

  (lyskom-format-insert 'who-i-am-client
                        lyskom-clientversion)

  (lyskom-format-insert 'who-i-am-emacs
                        (emacs-version)))
                        

Per Cederqvist's avatar
.  
Per Cederqvist committed
787
788
789
790
791
792
793

;;; ================================================================
;;;      kom-display-who-buffer - Visa vilka-listan

;;; Author: Linus Tolke


David Kågedal's avatar
David Kågedal committed
794
(def-kom-command kom-display-who-buffer ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
795
796
797
798
799
800
801
802
803
804
  "Make the who-buffer appear on the screen as a temp buffer."
  (interactive)
  (let ((win (selected-window))
	(who (display-buffer lyskom-who-info-buffer)))
    (unwind-protect
	(progn
	  (select-window who)
	  (if (numberp kom-who-buffer-size-when-displaying)
	      (enlarge-window (- kom-who-buffer-size-when-displaying 
				 (window-height who)))))
David Kågedal's avatar
David Kågedal committed
805
      (select-window win))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
806
807
808
809
810
811
812
813
814
815
816
817



;;; ================================================================
;;;          Hj{lp vid del av kommando - Help function

;;; Author: Linus Tolke


(defun lyskom-help ()
  "Prints a short list of alternatives when you don't know what you can do."
  (interactive)
818
  (let* ((tohere (cond
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
                  ((stringp (this-command-keys))
                   (substring (this-command-keys) 0 -1))
                  (t                    ;This is the case in the lucid-emacs.
                   (let* ((tck (this-command-keys))
                          (newvec (make-vector (1- (length tck)) nil))
                          (r 0))
                     (while (< r (length newvec))
                       (aset newvec r (aref tck r))
                       (++ r))
                     newvec))))
         (binding (key-binding tohere))
         (keymap (cond
                  ((and (symbolp binding)
                        (fboundp binding))
                   (symbol-function binding))
                  (t binding)))
         (keylis (lyskom-help-get-keylist keymap))
         (text (format "\n%s: \n%s\n"
                       (mapconcat 'single-key-description tohere " ")
                       (mapconcat
                        (function
                         (lambda (arg)
                           (format "%s - %s" 
                                   (if (fboundp 'map-keymap)
                                       (if (symbolp (car arg))
                                           (format "%s" (car arg))
                                         (format "%c" (car arg)))
                                     (format "%c" (car arg)))
                                   (or (lyskom-command-name (cdr arg))
                                       (and (keymapp (cdr arg))
                                            (lyskom-get-string 'multiple-choice))
                                       (cdr arg)))))
                        keylis
                        "\n")))
         next-char)
Per Cederqvist's avatar
.  
Per Cederqvist committed
854
    (if (eq major-mode 'lyskom-mode)
855
856
857
        (progn
          (lyskom-insert text)
          (lyskom-end-of-command))
Per Cederqvist's avatar
.  
Per Cederqvist committed
858
      (with-output-to-temp-buffer "*Help*"
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
        (princ text)))))


(defun lyskom-help-get-keylist (keymap)
  (cond
   ((fboundp 'map-keymap)
    (and keymap
         (let (list)
           (map-keymap
            (function
             (lambda (event function)
               (setq list (cons (cons event function) list))))
            keymap t)
           (nreverse list))))
   ((vectorp keymap)
    (let ((lis nil)
          (r 0))
      (while (< r (length keymap))
        (if (aref keymap r)
            (setq lis (cons (cons r (aref keymap r))
                            lis)))
        (++ r))
      (nreverse lis))) 
   (t
    (cdr keymap))))




Per Cederqvist's avatar
.  
Per Cederqvist committed
888
889
890
891
;    (setq next-char (read-char))
;    (cond
;     ((commandp (key-binding (concat tohere (char-to-string next-char))))
;      (command-execute (concat tohere (char-to-string next-char))))
892
;     (t (lyskom-message "%s" (lyskom-get-string 'does-not-exist))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
893
894
895
896
897
898
899
900


;;; ================================================================
;;;           Skapa bugg-rapport - Compile bugg-report

;;; Author: Linus Tolke


Linus Tolke's avatar
Linus Tolke committed
901
(defun kom-bug-report ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
902
903
904
  "This command should make it easier to include the correct info in a buggreport"
  (interactive)
  (let* ((curbuf (current-buffer))
905
906
907
908
         (old-buf (if (boundp 'debugger-old-buffer)
                      (symbol-value 'debugger-old-buffer)
                    (current-buffer)))
         (repname "*lyskom-bugreport*"))
909
    (lyskom-message "%s" (lyskom-get-string 'buggreport-compilestart))
Per Cederqvist's avatar
.  
Per Cederqvist committed
910
911
    (set-buffer old-buf)
    (cond
912
     ((condition-case error
913
914
          (eq old-buf (process-buffer lyskom-proc))
        (error nil)))
915
     ((condition-case error
916
917
918
919
920
          (save-excursion
            (set-buffer (process-buffer lyskom-proc))
            (set-buffer lyskom-unparsed-buffer)
            (eq old-buf (current-buffer)))
        (error nil))
Per Cederqvist's avatar
.  
Per Cederqvist committed
921
922
923
      (set-buffer (process-buffer lyskom-proc)))
     (t
      (error "I dont know what buffer you are running lyskom in (%s)?" 
924
             old-buf)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
925
926
927
    (with-output-to-temp-buffer repname
      (princ (lyskom-get-string 'buggreport-description))
      (princ (lyskom-get-string 'buggreport-internals))
Linus Tolke's avatar
Linus Tolke committed
928
929
930
931
      (princ (lyskom-get-string 'buggreport-command-keys))
      (terpri)
      (princ (key-description (recent-keys)))
      (terpri)
Per Cederqvist's avatar
.  
Per Cederqvist committed
932
933
      (princ (lyskom-get-string 'buggreport-version))
      (print lyskom-clientversion)
Linus Tolke's avatar
Linus Tolke committed
934
935
936
937
938
939
      (princ (lyskom-get-string 'buggreport-emacs-version))
      (print (emacs-version))
      (princ (lyskom-get-string 'buggreport-system-id))
      (print system-type)
      (princ (lyskom-get-string 'buggreport-ctl-arrow-doc))
      (print (condition-case error
940
941
                 (documentation-property 'ctl-arrow 'variable-documentation)
               (error)))
Linus Tolke's avatar
Linus Tolke committed
942

Per Cederqvist's avatar
.  
Per Cederqvist committed
943
944
      (princ (lyskom-get-string 'buggreport-unparsed))
      (print (save-excursion
945
946
947
948
949
950
951
952
953
954
955
               (set-buffer lyskom-unparsed-buffer)
               (goto-char (point-min))
               (forward-line 10)
               (buffer-substring (point-min) (point))))
      (if (and (boundp 'debugger-old-buffer) 
               (symbol-value 'debugger-old-buffer))
          (princ (lyskom-format 'buggreport-backtrace
                                (save-excursion
                                  (set-buffer curbuf)
                                  (buffer-substring (point-min) 
                                                    (point-max))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
956
      (if lyskom-debug-communications-to-buffer
957
958
959
960
961
          (progn
            (princ (lyskom-get-string 'buggreport-communications))
            (print (save-excursion
                     (set-buffer lyskom-debug-communications-to-buffer-buffer)
                     (buffer-substring (point-min) (point-max))))))
Linus Tolke's avatar
Linus Tolke committed
962
963
964
      (princ (lyskom-get-string 'buggreport-all-kom-variables))
      (mapatoms
       (function
965
966
967
968
        (lambda (symbol)
          (and (boundp symbol)
               (string-match "^\\(kom-\\|lyskom-\\)" (symbol-name symbol))
               (not (string-match "-cache$\\|^kom-dict$\\|^lyskom-strings$\
969
\\|-map$\\|^lyskom-commands$\\|^lyskom-swascii"
970
971
972
973
974
975
                                  (symbol-name symbol)))
               (progn
                 (terpri)
                 (princ (symbol-name symbol))
                 (princ ":")
                 (print (symbol-value symbol))))))))
Linus Tolke's avatar
Linus Tolke committed
976
    
Per Cederqvist's avatar
.  
Per Cederqvist committed
977
978
979
    (save-excursion
      (set-buffer repname)
      (goto-char (point-min))
980
      (replace-regexp "byte-code(\".*\""
981
                      (lyskom-get-string 'buggreport-instead-of-byte-comp)))
982
    (lyskom-message "%s" (lyskom-get-string 'buggreport-compileend))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
983

Linus Tolke's avatar
Linus Tolke committed
984
985
(fset 'kom-compile-bug-report (symbol-function 'kom-bug-report))

Per Cederqvist's avatar
.  
Per Cederqvist committed
986
987
988
989
990
991
992
993
994



;;; ================================================================
;;;      [ndra livsl{ngd - Set lifespan of texts in a conference

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
995
(def-kom-command kom-set-garb-nice ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
996
997
  "Set the garb-nice value for a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
998
999
  (let ((conf-stat (lyskom-read-conf-stat
		    (lyskom-get-string 'conf-to-set-garb-nice-q)
1000
		    '(all))))
David Kågedal's avatar
David Kågedal committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
      (let ((garb-nice (lyskom-read-number
			(lyskom-get-string 'new-garb-nice-q))))
	(lyskom-format-insert 'garb-nice-for-is
			      conf-stat
			      garb-nice)
	(if (not (blocking-do 'set-garb-nice
			      (conf-stat->conf-no conf-stat) 
			      garb-nice))
	    (lyskom-insert-string 'nope) ;+++lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1014
1015


Linus Tolke's avatar
Linus Tolke committed
1016
1017
1018
1019
1020
;;; ================================================================
;;;       S{tt till}tna f|rfattare - set-permitted-submitters

;;; Author: Linus Tolke

David Kågedal's avatar
David Kågedal committed
1021
(def-kom-command kom-set-permitted-submitters ()
Linus Tolke's avatar
Linus Tolke committed
1022
1023
  "Set the permitted submitters of a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1024
1025
  (let ((conf-stat (lyskom-read-conf-stat 
		    (lyskom-get-string 'conf-to-set-permitted-submitters-q)
1026
		    '(all))))
David Kågedal's avatar
David Kågedal committed
1027
1028
1029
1030
1031
1032

    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
      (let ((new-conf (lyskom-read-conf-stat
		       (lyskom-format 'new-permitted-submitters-q
				      (conf-stat->name conf-stat))
1033
1034
		       '(all) 
		       t)))
David Kågedal's avatar
David Kågedal committed
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
	(if (eq new-conf nil)
	    (lyskom-format-insert 'permitted-submitters-removed-for-conf 
				  conf-stat)
	  (lyskom-format-insert 'submitters-conf-for-is
				conf-stat
				new-conf))
	(if (not (blocking-do 'set-permitted-submitters
			      (conf-stat->conf-no conf-stat) 
			      (if (eq new-conf nil) ;Allowing all to write there
				  0
				(conf-stat->conf-no new-conf))))
	    (lyskom-insert-string 'nope) ;+++ lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
Linus Tolke's avatar
Linus Tolke committed
1049
1050


inge's avatar
inge committed
1051
1052
1053
1054
1055
1056
;;; ================================================================
;;;             [ndra superm|te - Set super conference 

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1057
(def-kom-command kom-set-super-conf ()
inge's avatar
inge committed
1058
1059
  "Set the super conference for a conference."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1060
1061
  (let ((conf-stat (lyskom-read-conf-stat 
		    (lyskom-get-string 'conf-to-set-super-conf-q)
1062
		    '(all))))
David Kågedal's avatar
David Kågedal committed
1063
1064
1065
1066
1067
    (if (not conf-stat)
	(lyskom-insert-string 'somebody-deleted-that-conf)
      (let ((new-conf (lyskom-read-conf-stat
		       (lyskom-format 'new-super-conf-q
				      (conf-stat->name conf-stat))
1068
		       '(all))))
1069
      
David Kågedal's avatar
David Kågedal committed
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
	;; Set the super conference for conf-stat to new-conf.
	(lyskom-format-insert 'super-conf-for-is
			      conf-stat
			      new-conf)
	(if (not (blocking-do 'set-super-conf 
			      (conf-stat->conf-no conf-stat) 
			      (conf-stat->conf-no new-conf)))
	    (lyskom-insert-string 'nope) ;+++ lyskom-errno
	  (lyskom-insert-string 'done)
	  (cache-del-conf-stat (conf-stat->conf-no conf-stat)))))))
inge's avatar
inge committed
1080
1081
1082



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
;;; ================================================================
;;;                  Spara databasen - Save database
;;;

(def-kom-command kom-sync-database ()
  "Save the LysKOM database."
  (interactive)
  (if (lyskom-ja-or-nej-p (lyskom-get-string 'really-sync))
      (progn (lyskom-insert-string 'syncing-server)
             (lyskom-report-command-answer (blocking-do 'sync)))))

inge's avatar
inge committed
1094

Per Cederqvist's avatar
.  
Per Cederqvist committed
1095
1096
1097
1098
1099
;;; ================================================================
;;;                  St{ng av servern - Shutdown

;;; Author: Inge Wallin

1100
(def-kom-command kom-shutdown-server ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1101
1102
  "Shutdown the LysKOM server."
  (interactive)
Linus Tolke's avatar
Linus Tolke committed
1103
  (if (lyskom-ja-or-nej-p (lyskom-get-string 'really-shutdown))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1104
1105
      (progn
	(lyskom-insert-string 'closing-server)
1106
        (lyskom-report-command-answer (blocking-do 'shutdown 0)))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1107
1108
1109
1110
1111
1112
1113
1114
1115


;;; ================================================================
;;;       \verg} till adm.mod - Enable administrator capabilities
;;;     \verg} till normalmod - Disable administrator capabilities

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1116
(def-kom-command kom-enable-adm-caps ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1117
1118
  "Enable the LysKOM adminstrator commands for the current user."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1119
1120
1121
  (lyskom-enable-adm-caps (blocking-do 'enable 255)
			  (lyskom-get-string 'administrator)
			  t))
David Kågedal's avatar
David Kågedal committed
1122
  
Per Cederqvist's avatar
.  
Per Cederqvist committed
1123

David Kågedal's avatar
David Kågedal committed
1124
(def-kom-command kom-disable-adm-caps ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1125
1126
  "Disable the LysKOM adminstrator commands for the current user."
  (interactive)
David Kågedal's avatar
David Kågedal committed
1127
1128
1129
  (lyskom-enable-adm-caps (blocking-do 'enable 0)
			  (lyskom-get-string 'no-longer-administrator)
			  nil))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1130
1131
1132
1133
1134
1135
1136

(defun lyskom-enable-adm-caps (answer string is-administrator)
  "Tell the user if the call succeded."
  (if answer
      (progn
	(lyskom-format-insert 'you-are-now string)
	(setq lyskom-is-administrator is-administrator))
David Kågedal's avatar
David Kågedal committed
1137
    (lyskom-insert-string 'nope)))	;+++ lyskom-errno
Per Cederqvist's avatar
.  
Per Cederqvist committed
1138
1139
1140
1141
1142
1143
1144
1145


;;; ================================================================
;;;         S{tt loginmeddelande - Set message of the day

;;; Author: Inge Wallin


1146
(def-kom-command kom-set-motd ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1147
1148
1149
1150
  "Set the message of the day for LysKOM."
  (interactive)
  (if (server-info->motd-of-lyskom lyskom-server-info)
      (initiate-get-text 'main 'lyskom-set-motd
1151
                         (server-info->motd-of-lyskom lyskom-server-info))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
    (lyskom-set-motd nil)))


(defun lyskom-set-motd (old-motd-text)
  "Set the message of the day for LysKOM. 
Use OLD-MOTD-TEXT as the default text if non-nil."
  
  (lyskom-edit-text
   lyskom-proc
1161
   (lyskom-create-misc-list)
Per Cederqvist's avatar
.  
Per Cederqvist committed
1162
   (if (and old-motd-text
1163
            (string-match "\n" (text->text-mass old-motd-text)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1164
1165
1166
       (substring (text->text-mass old-motd-text) 0 (1- (match-end 0)))
     "")
   (if (and old-motd-text
1167
            (string-match "\n" (text->text-mass old-motd-text)))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1168
1169
1170
1171
1172
       (substring (text->text-mass old-motd-text) (match-end 0))
     "")
   'lyskom-set-motd-2))


David Kågedal's avatar
David Kågedal committed
1173
;; Should really fix lyskom-edit text instead of the ugly IGNORE
1174

David Kågedal's avatar
David Kågedal committed
1175
(defun lyskom-set-motd-2 (text-no ignore)
Per Cederqvist's avatar
.  
Per Cederqvist committed
1176
  "Set motd of LysKOM to the newly created text TEXT-NO."
1177
1178
1179
  (lyskom-insert-before-prompt
   (lyskom-format 'setting-motd text-no))
  (initiate-set-motd-of-lyskom 'background 'lyskom-set-motd-3
1180
                               text-no text-no))
1181
1182
1183
1184
1185
1186


(defun lyskom-set-motd-3 (result text-no)
  "Handle the return from the initiate-set-motd-of-lyskom call."
  (if result
      (progn
1187
1188
1189
1190
1191
        (lyskom-insert-before-prompt
         (lyskom-get-string (if (zerop text-no)
                                'removed-motd 
                              'set-motd-success)))
        (set-server-info->motd-of-lyskom lyskom-server-info text-no))
1192
1193
    (lyskom-insert-before-prompt
     (lyskom-get-string 'set-motd-failed))))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1194
1195
1196
1197
1198
1199
1200
1201


;;; ================================================================
;;;       Ta bort loginmeddelande - Remove message of the day

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1202
(def-kom-command kom-remove-motd ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1203
1204
1205
  "Remove the message of the day for LysKOM."
  (interactive)
  (lyskom-insert-string 'removing-motd)
1206
  (initiate-set-motd-of-lyskom 'background 'lyskom-set-motd-3
David Kågedal's avatar
David Kågedal committed
1207
			       0 0))
Per Cederqvist's avatar
.  
Per Cederqvist committed
1208
1209
1210
1211
1212
1213
1214

;;; ================================================================
;;;                  Kasta ut - force logout

;;; Author: Inge Wallin


David Kågedal's avatar
David Kågedal committed
1215
(def-kom-command kom-force-logout ()
Per Cederqvist's avatar
.  
Per Cederqvist committed
1216
1217
  "Force another user to log out."
  (interactive)
1218
1219
1220
1221
1222
1223
1224
1225
  (let ((session (car-safe (lyskom-read-session-no
                            (lyskom-get-string 'who-to-throw-out)
                            nil nil t))))
    (if session
        (progn
          (lyskom-format-insert 'throwing-out session)
          (lyskom-report-command-answer
           (blocking-do 'disconnect session))))))
Per Cederqvist's avatar
Per Cederqvist committed
1226

inge's avatar
inge committed
1227

Per Cederqvist's avatar
Per Cederqvist committed
1228
1229
1230
1231
1232
1233
;;; ================================================================
;;;                  Skjut upp l{sning - postpone

;;; Author: Per Cederqvist


David Kågedal's avatar
David Kågedal committed
1234
(def-kom-command kom-postpone (today)
Per Cederqvist's avatar
Per Cederqvist committed
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
  "Postpone the reading of all but the last TODAY articles in the
current conference to another session."
  (interactive (list
		(cond
		 ((null current-prefix-arg)
		  (lyskom-read-number
		   (lyskom-get-string 'postpone-prompt)
		   17))
		 (t (prefix-numeric-value current-prefix-arg)))))

  (let ((len (read-list-length lyskom-reading-list))
	(finished nil))
    (while (and (not finished)
		(> len 0))
      (let ((type (read-info->type (read-list->first lyskom-reading-list))))
	(cond 
	 ((or (eq type 'REVIEW)
	      (eq type 'REVIEW-TREE)
	      (eq type 'REVIEW-MARK))
	  (read-list-rotate lyskom-reading-list))
	 ((or (eq type 'COMM-IN)
	      (eq type 'FOOTN-IN))
	  (set-read-list-del-first lyskom-reading-list))
	 ((eq type 'CONF)
	  (let* ((rlist (read-info->text-list
			 (read-list->first lyskom-reading-list)))
Linus Tolke's avatar
Linus Tolke committed
1261
		 (cell (nthcdr (max (- (length rlist) today) 1)
Per Cederqvist's avatar
Per Cederqvist committed
1262
1263
1264
1265
1266
1267
			       rlist)))
	    (setcdr rlist cell))
	  (setq finished t))
	 (t
	  (signal 'lyskom-internal-error '("lyskom-remove-comment-chains")))))
      (-- len)))
Per Cederqvist's avatar
Per Cederqvist committed
1268
1269
1270
1271
1272

  ;; Delete the 'CONF entry if we selected 0 entries.
  (cond
   ((zerop today)
    (read-list-delete-text nil lyskom-reading-list)
David Kågedal's avatar
David Kågedal committed
1273
    (read-list-delete-text nil lyskom-to-do-list))))
Linus Tolke's avatar
Linus Tolke committed
1274
1275
1276



David Kågedal's avatar
David Kågedal committed
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
;;; ================================================================
;;;              S{tt l{sniv} - Sess session priority

;;; Author: David K}gedal

(def-kom-command kom-set-session-priority (priority)
  "Set the priority level of the current session.
This sets the variable kom-session-priority and refetches all
membership info."
  (interactive "P")
  (let ((pri (or priority
1288
1289
1290
1291
1292
		 (lyskom-read-num-range 0
                                255
                                (lyskom-get-string 'set-session-priority)
                                t
                                100))))
David Kågedal's avatar
David Kågedal committed
1293
1294
1295
1296
1297
    (setq lyskom-session-priority pri)
    (lyskom-refetch)))



Linus Tolke's avatar
Linus Tolke committed
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
;;; ================================================================
;;;              Begrav lyskom-sessionen - kom-bury

;;; Author: Linus Tolke

(defun kom-bury () 
  "Puts the kom-session in the background."
  (interactive)
  (let ((session-name (buffer-name (current-buffer)))
	(buffer (current-buffer)))
David Kågedal's avatar
David Kågedal committed
1308
1309
;;;    (if lyskom-debug-communications-to-buffer
;;;	(bury-buffer lyskom-debug-communications-to-buffer-buffer))
Linus Tolke's avatar
Linus Tolke committed
1310
1311
1312
    (if lyskom-who-info-buffer
	(bury-buffer lyskom-who-info-buffer))
    (bury-buffer)
David Kågedal's avatar
David Kågedal committed
1313
1314
    (while (and (string-match (regexp-quote session-name)
			      (buffer-name (current-buffer)))
Linus Tolke's avatar
Linus Tolke committed
1315
		(not (eq buffer (current-buffer))))
1316
      (bury-buffer))))
Linus Tolke's avatar
Linus Tolke committed
1317
1318


1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
(defun lyskom-buffer-p (buf)
  ;; Returns non-nil if BUF is an active LysKOM buffer
  (if (and buf (bufferp buf) (buffer-name buf))
      (save-excursion
	(set-buffer buf)
	(and (eq major-mode 'lyskom-mode)
	     (boundp 'lyskom-proc)
	     lyskom-proc
	     (processp lyskom-proc)
	     (memq (process-status lyskom-proc) '(run open))))))

1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
;;;(defun lyskom-update-lyskom-buffer-list ()
;;;  (mapcar (function
;;;	   (lambda (buf)
;;;	     (if (and (lyskom-buffer-p buf)
;;;		      (not (memq buf lyskom-buffer-list)))
;;;		 ;; This is a LysKOM buffer that we haven't seen yet --
;;;		 ;; If it is the current buffer, add it at the start
;;;		 ;; of lyskom-buffer-list, otherwise add it to the end
;;;		 (if (eq buf (current-buffer))
;;;		     (setq lyskom-buffer-list (cons buf
;;;						    lyskom-buffer-list))
;;;		   (setq lyskom-buffer-list
;;;			 (nconc lyskom-buffer-list (list buf)))))))
;;;	  (buffer-list))
;;;  (mapcar (function
;;;	   (lambda (buf)
;;;	     (if buf
;;;		 (setq lyskom-buffer-list
;;;		       (delete buf lyskom-buffer-list)))))
;;;	  (mapcar (function
;;;		   (lambda (buf)
;;;		     (if (lyskom-buffer-p buf) nil buf)))
;;;		  lyskom-buffer-list)))

1354
1355


1356
1357
1358
(defun kom-next-kom ()
  "Pop up the next lyskom-session."
  (interactive)
1359
1360
  (if (lyskom-buffer-p (current-buffer))
      (lyskom-tell-internat 'kom-tell-next-lyskom))
1361
1362
  (if lyskom-buffer-list
      (progn
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
	(if (lyskom-buffer-p (car lyskom-buffer-list))
	    ;; If there is an "active" lyskom buffer, send it to the
	    ;; back of the list.
	    (progn
	      ;; If the "active" lyskom buffer is the current buffer,
	      ;; and kom-bury-buffers is non-nil, bury it.
	      (if (and kom-bury-buffers
		       (eq (car lyskom-buffer-list)
			   (current-buffer)))
		  (kom-bury))
	      (setq lyskom-buffer-list
		    (nconc (cdr lyskom-buffer-list)
			   (list (car lyskom-buffer-list)))))
	  ;; The "active" lyskom buffer is dead, so we remove it from
1377
1378
1379
1380
1381
1382
1383
	  ;; some lists.
	  (setq lyskom-sessions-with-unread
		(delq (car lyskom-buffer-list)
		      lyskom-sessions-with-unread))
	  (setq lyskom-sessions-with-unread-letters
		(delq (car lyskom-buffer-list)
		      lyskom-sessions-with-unread-letters))
1384
1385
1386
1387
1388
	  (setq lyskom-buffer-list (cdr lyskom-buffer-list)))
	;; Don't switch to dead sessions.
	(if (lyskom-buffer-p (car lyskom-buffer-list))
	    (switch-to-buffer (car lyskom-buffer-list))
	  (kom-next-kom)))
David Kågedal's avatar
David Kågedal committed
1389
    (error "No active LysKOM buffers")))
1390
1391
1392
1393
1394


(defun kom-previous-kom ()
  "Pop up the previous lyskom-session."
  (interactive)
1395
1396
  (if (lyskom-buffer-p (current-buffer))
      (lyskom-tell-internat 'kom-tell-next-lyskom))
1397
  (if (> (length lyskom-buffer-list) 1)
1398
1399
1400
1401
      (let (lastbuf
	    (last-but-one lyskom-buffer-list))
	(while (cdr (cdr last-but-one))
	  (setq last-but-one (cdr last-but-one)))
1402
1403
1404
1405
	(setq lastbuf (car (cdr last-but-one)))
	(if (lyskom-buffer-p (car lyskom-buffer-list))
	    ;; If there is an "active" lyskom buffer, send it to the
	    ;; back of the list.
1406
	    (progn
1407
1408
1409
1410
1411
1412
	      ;; If the "active" lyskom buffer is the current buffer,
	      ;; and kom-bury-buffers is non-nil, bury it.
	      (if (and kom-bury-buffers
		       (eq (car lyskom-buffer-list)
			   (current-buffer)))
		  (kom-bury))
1413
	      (setq lyskom-buffer-list (cons lastbuf lyskom-buffer-list))
1414
1415
	      (rplacd last-but-one nil))
	  ;; The "active" lyskom buffer is dead, so we remove it from
1416
1417
1418
1419
1420
1421
1422
	  ;; some lists.
	  (setq lyskom-sessions-with-unread
		(delq (cdr last-but-one)
		      lyskom-sessions-with-unread))
	  (setq lyskom-sessions-with-unread-letters
		(delq (cdr last-but-one)
		      lyskom-sessions-with-unread-letters))
1423
1424
1425
1426
1427
1428
	  (rplacd last-but-one nil))
	(if (lyskom-buffer-p (car last-but-one))
	    (switch-to-buffer lastbuf)
	  (kom-previous-kom)))
    (if (null lyskom-buffer-list)
	(error "No active LysKOM buffers"))))
1429
1430
1431
1432
1433


(defun kom-next-unread-kom ()
  "Pop up the next LysKOM session with unread texts in."
  (interactive)
1434
1435
  (if (not (lyskom-buffer-p (current-buffer)))
      (kom-next-kom))
1436
1437
1438
  (let ((thisbuf (current-buffer)))
    (kom-next-kom)
    (while (and (not (eq thisbuf (current-buffer)))
1439
		(not (memq lyskom-buffer lyskom-sessions-with-unread)))
1440
1441
      (kom-next-kom))))

Linus Tolke's avatar
Linus Tolke committed
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
;;;============================================================
;;;  Visa user-arean                    (kom-show-user-area)
;;;
;;;  Author: David Byers

(defun kom-show-user-area ()
  "Get and display the user area of the current person"
  (interactive)
  (lyskom-start-of-command 'kom-show-user-area)
  (let ((pers-stat (blocking-do 'get-pers-stat lyskom-pers-no)))
1453
1454
    (lyskom-view-text (pers-stat->user-area pers-stat)
		      nil nil nil nil nil)
1455
1456
1457
1458
1459
1460
1461
1462
    (lyskom-run 'main 'lyskom-end-of-command)))


;;;============================================================
;;;   ndra mtestyp                    (kom-change-conf-type)
;;;
;;;   Author: Tomas Abrahamsson & David Byers

David Kågedal's avatar
David Kågedal committed
1463
(def-kom-command kom-change-conf-type ()
1464
1465
  "Change type of a conference"
  (interactive)
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
  (let* ((conf-stat (lyskom-read-conf-stat
                     (lyskom-get-string 'what-conf-to-change)
                     '(conf pers) nil "" t))
         (foo
          (let* ((type (conf-stat->conf-type conf-stat))
                 (box (conf-type->letterbox type))
                 (ori (conf-type->original type))
                 (pro (conf-type->rd_prot type))
                 (sec (conf-type->secret type)))
            (lyskom-format-insert 'change-type-prompt
                                  conf-stat
                                  conf-stat
                                  (cond
                                   ((or box ori pro sec)
                                    (concat
                                     "("
                                     (if box (lyskom-get-string 'Mailbox) "")
                                     (if (and box (or sec ori pro)) ", " "")
                                     (if sec (lyskom-get-string
                                              'Protected) "")
                                     (if (and sec (or ori pro)) ", " "")
                                     (if ori (lyskom-get-string
                                              'no-comments) "")
                                     (if (and ori pro) ", " "")
                                     (if pro (lyskom-get-string 'closed) "")
                                     ")"))
                                   (t "")))))
	 (open (lyskom-j-or-n-p (lyskom-get-string 'anyone-member)))
David Kågedal's avatar
David Kågedal committed
1494
	 (secret (if (not open)
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
		     (lyskom-j-or-n-p (lyskom-get-string 'secret-conf))))
	 (orig (lyskom-j-or-n-p (lyskom-get-string 'comments-allowed)))
         (anarchy (lyskom-j-or-n-p (lyskom-get-string 'anonymous-allowed))))
    (cache-del-conf-stat (conf-stat->conf-no conf-stat))
    (if (not (blocking-do 
              'set-conf-type
              (conf-stat->conf-no conf-stat)
              (lyskom-create-conf-type (not open)
                                       (not orig)
                                       secret
                                       (conf-type->letterbox
                                        (conf-stat->conf-type  conf-stat))
                                       anarchy
                                       (conf-type->rsv1
                                        (conf-stat->conf-type conf-stat))
                                       (conf-type->rsv2
                                        (conf-stat->conf-type conf-stat))
                                       (conf-type->rsv3
                                        (conf-stat->conf-type conf-stat)))))
David Kågedal's avatar
David Kågedal committed
1514
1515
1516
1517
	(progn (lyskom-insert-string 'nope)
	       (lyskom-format-insert 'error-code
				     (lyskom-get-error-text lyskom-errno)
				     lyskom-errno)))))
1518
1519