option-edit.el 59.8 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991, 1996  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 2, 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. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
David Byers's avatar
David Byers committed
29
;;;; File: option-edit.el
30
;;;;
David Byers's avatar
David Byers committed
31
;;;; Customization for LysKOM
32
33
34
35
36
37
38
;;;;


(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

39
40
41
(lyskom-external-function widget-default-format-handler)
(lyskom-external-function popup-mode-menu)

42
43
;;; ======================================================================
;;; Require Per Abrahamsens widget package, version 0.991 or later.
David Byers's avatar
David Byers committed
44
45
;;;

46
47
48
;;; ======================================================================
;;; Global variables

David Byers's avatar
David Byers committed
49
50
51
(defvar lyskom-widgets nil
  "List of widgets in the customize buffer.")

52
(defvar lyskom-customize-buffer-format
David Byers's avatar
David Byers committed
53
  '("\n"
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    (lyskom bold centered)
    "\n\n"
    lyskom-doc
    "\n\n"
    [kom-customize-format]
    "\n\n"
    section
    (look-and-feel-misc bold centered)
    section
    "\n"
    [kom-default-language]
    [kom-show-namedays]
    [kom-show-week-number]
    "\n"
    [kom-idle-hide]
    [kom-show-where-and-what]
    [kom-show-since-and-when]
    "\n"
    [kom-friends]
73
    [kom-morons]
74
    "\n"
75
    [kom-show-unread-in-frame-title]
76
77
78
    [kom-presence-messages]
    [kom-presence-messages-in-buffer]
    "\n"
79
    [kom-prompt-for-text-no]
80
    [kom-page-before-command]
81
82
    [kom-deferred-printing]
    [kom-max-buffer-size]
83
    [kom-trim-buffer-minimum]
84
    [kom-bury-buffers]
85
    [kom-keep-alive-interval]
86
    "\n"
87
88
    [kom-agree-text]
    [kom-mercial]
89
90
91
92
93
94
95
    "\n"
    [kom-user-prompt-format]
    [kom-user-prompt-format-executing]
    [kom-anonymous-prompt-format]
    [kom-anonymous-prompt-format-executing]
    [kom-enabled-prompt-format]
    [kom-enabled-prompt-format-executing]
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    "\n\n"
    section
    (window-locations bold centered)
    section
    "\n"
    (windows-where bold centered)
    "\n"
    windows-doc
    "\n\n"
    [kom-customize-in-window]
    [kom-edit-filters-in-window]
    [kom-prioritize-in-window]
    [kom-list-membership-in-window]
    [kom-write-texts-in-window]
    [kom-view-commented-in-window]
    [kom-personal-messages-in-window]
    
    "\n\n"
    section
    (audio-cues bold centered)
    section
    "\n"
    [kom-audio-player]
    "\n"
    (audio-cues-when bold centered)
    "\n"
    audio-cues-doc
    "\n\n"
124
125
    [kom-ding-on-priority-break]
    [kom-ding-on-new-letter]
David Byers's avatar
David Byers committed
126
    [kom-ding-on-wait-done]
127
    [kom-ding-on-no-subject]
David Byers's avatar
David Byers committed
128
129
130
    [kom-ding-on-common-messages]
    [kom-ding-on-group-messages]
    [kom-ding-on-personal-messages]
Joel Rosdahl's avatar
Joel Rosdahl committed
131
    "\n"
132
133
134
135
136
137
138
139
140
    [kom-silent-ansaphone]
    "\n\n"
    section
    (reading bold centered)
    section
    "\n"
    [kom-default-session-priority]
    [kom-print-number-of-unread-on-entrance]
    [kom-allow-incompleteness]
141
    [kom-permissive-completion]
142
    [kom-complete-numbers-before-names]
143
144
    [kom-continuous-scrolling]
    [kom-inhibit-typeahead]
145
    [kom-confirm-add-recipients]
146
    "\n"
147
148
    [kom-higher-priority-breaks]
    [kom-review-priority]
149
150
151
    [kom-server-priority]
    [kom-server-priority-breaks]
    "\n"
152
153
    [kom-read-depth-first]
    [kom-reading-puts-comments-in-pointers-last]
154
155
    [kom-show-footnotes-immediately]
    [kom-follow-comments-outside-membership]
156
    [kom-follow-attachments]
157
    [kom-created-texts-are-read]
158
    [kom-created-texts-are-saved]
159
    "\n"
160
    [kom-saved-file-name]
161
    [kom-default-mark]
162
    [kom-symbolic-marks-alist]
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    [kom-membership-default-priority]
    [kom-membership-default-placement]
    [kom-unsubscribe-makes-passive]
    [kom-postpone-default]
    "\n"
    [kom-autowrap]
    [kom-show-author-at-end]
    [kom-show-creating-software]
    [kom-show-imported-importer]
    [kom-show-imported-external-recipients]
    [kom-show-imported-envelope-sender]
    [kom-smileys]
    [kom-w3-simplify-body]
    "\n"
    [kom-dashed-lines]
    [kom-long-lines]
    [kom-text-footer-format]
    [kom-text-header-dash-length]
    [kom-text-footer-dash-length]
    "\n"
    [kom-truncate-threshold]
    [kom-truncate-show-lines]
    "\n"
    [kom-ignore-message-senders]
    [kom-ignore-message-recipients]
    [kom-show-personal-message-date]
189
    [lyskom-filter-outgoing-messages]
190
191
192
193
194
195
196
197
198
199
200
201
    "\n\n"
    section
    (writing bold centered)
    section
    "\n"
    [kom-cite-string]
    [kom-ispell-dictionary]
    "\n"
    sending-doc
    "\n\n"
    [kom-confirm-multiple-recipients]
    [kom-check-commented-author-membership]
202
    [kom-dont-check-commented-authors]
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
    [kom-check-for-new-comments]

    "\n\n"
    section
    (urls bold centered)
    section
    "\n"
    [kom-url-viewer-preferences]
    [kom-mosaic-command]
    [kom-netscape-command]

    "\n\n"
    section
    (personal-messages bold centered)
    section
    "\n"
    [kom-show-personal-messages-in-buffer]
    [kom-pop-personal-messages]
    [kom-default-message-recipient]
    "\n"
    (automatic-replies bold centered)
    "\n"
    [kom-ansaphone-record-messages]
    [kom-ansaphone-show-messages]
    "\n"
    [kom-ansaphone-default-reply]
229
230
    "\n"
    [kom-ansaphone-replies]
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    "\n\n"
    section
    (remote-control bold centered)
    section
    "\n"
    [kom-remote-control]
    [kom-self-control]
    "\n"
    [kom-remote-controllers]
    "\n\n"
    section
    (hooks bold centered)
    section
    "\n"
    [kom-login-hook]
    [kom-do-when-done]
247
248
249
    ))

;;; ======================================================================
David Byers's avatar
David Byers committed
250
251
252
253
254
255
256
257
258
259
;;;     User functions
;;;

(defun lyskom-customize-apply ()
  "Set the variables in the LysKOM buffer according to their values in the
customize buffer but do not save them to the server."
  (interactive)
  (let ((tmp lyskom-widgets))
    (save-excursion
      (set-buffer lyskom-buffer)
David Byers's avatar
David Byers committed
260
261
      (when (listp kom-dont-read-saved-variables)
        (setq kom-dont-read-saved-variables nil))
David Byers's avatar
David Byers committed
262
263
264
      (while tmp
        (set (car (car tmp))
             (widget-value (cdr (car tmp))))
David Byers's avatar
David Byers committed
265
266
267
268
269
270
271
272
273
        (when (not (widget-value (widget-get (cdr (car tmp)) 
                                             ':lyskom-storage-widget)))
          (set-default (car (car tmp)) (widget-value (cdr (car tmp))))
          (when (and (listp kom-dont-read-saved-variables)
                     (or (memq (car (car tmp)) lyskom-elisp-variables)
                         (memq (car (car tmp)) lyskom-global-boolean-variables)
                         (memq (car (car tmp)) lyskom-global-non-boolean-variables)))
            (setq kom-dont-read-saved-variables 
                  (cons (car (car tmp)) kom-dont-read-saved-variables))))
David Byers's avatar
David Byers committed
274
275
        (setq tmp (cdr tmp))))))

David Byers's avatar
David Byers committed
276
277
(eval-when-compile (defvar save-options-init-file nil))

David Byers's avatar
David Byers committed
278
279
280
281
282
283
284
(defun lyskom-customize-send ()
  "Save variables to the server"
  (save-excursion
    (set-buffer lyskom-buffer)
    (lyskom-save-options (current-buffer)
                         (lyskom-get-string 'saving-settings)
                         (lyskom-get-string 'saving-settings-done)
David Byers's avatar
David Byers committed
285
286
287
288
289
290
291
                         (lyskom-get-string 'could-not-save-options))
    (let ((var-list nil))
      (mapcar 
       (function 
        (lambda (e)
          (when (and (vectorp e)
                     (symbolp (elt e 0))
David Byers's avatar
David Byers committed
292
293
294
295
296
                     (or 
                      (and (not (memq (elt e 0) lyskom-elisp-variables))
                           (not (memq (elt e 0) lyskom-global-boolean-variables))
                           (not (memq (elt e 0) lyskom-global-non-boolean-variables)))
                      (memq (elt e 0) kom-dont-read-saved-variables))
David Byers's avatar
David Byers committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
                     (boundp (elt e 0)))
            (setq var-list (cons (cons (elt e 0)
                                       (symbol-value (elt e 0)))
                                 var-list)))))
       lyskom-customize-buffer-format)
      
      (let* ((actual-save-options-init-file
              (or (and (boundp 'save-options-init-file)
                       save-options-init-file)
                  (and (not (equal user-init-file ""))
                       user-init-file)
                  (and (eq system-type 'ms-dos)
                       (concat "~" (user-login-name) "/_emacs"))
                  (concat "~" (user-login-name) "/.emacs")))
             (init-output-buffer (find-file-noselect
                                  actual-save-options-init-file))
             (init-output-marker nil))

        (save-excursion
          (set-buffer init-output-buffer)
          ;;
          ;; Find and delete the previously saved data, and position to write.
          ;;
          (goto-char (point-min))
          (if (re-search-forward "^;;; LysKOM Settings *\n" nil 'move)
              (let ((p (match-beginning 0)))
                (goto-char p)
                (or (re-search-forward
                     "^;;; End of LysKOM Settings *\\(\n\\|\\'\\)"
                     nil t)
                    (error "can't find END of saved state in .emacs"))
                (delete-region p (match-end 0)))
            (goto-char (point-max))
            (insert "\n"))
          (setq init-output-marker (point-marker)))

    (let ((standard-output init-output-marker))
      (princ ";;; LysKOM Settings\n")
      (princ ";;; =====================\n")
David Byers's avatar
David Byers committed
336
337
338
339
340
341
342
343
344
      (mapcar (lambda (x)
                (princ (format "(setq-default %S %s%S)\n" 
                               (car x)
                               (cond ((eq (cdr x) t) "")
                                     ((null (cdr x)) "")
                                     ((symbolp (cdr x)) "'")
                                     ((listp (cdr x)) "'")
                                     (t ""))
                               (cdr x))))
David Byers's avatar
David Byers committed
345
346
347
348
349
350
351
352
353
       var-list)
      (princ ";;; ============================\n")
      (princ ";;; End of LysKOM Settings\n"))

    (set-marker init-output-marker nil)
    (save-excursion
      (set-buffer init-output-buffer)
      (save-buffer))
    ))))
David Byers's avatar
David Byers committed
354
355
356
357
358
359
360
361
362
363

(defun lyskom-customize-save ()
  "Apply changes and save them to the server."
  (interactive)
  (lyskom-customize-apply)
  (lyskom-customize-send))

(defun lyskom-customize-quit ()
  "Quit the customize buffer without saving"
  (interactive)
364
365
366
  (let ((buf (current-buffer)))
    (lyskom-undisplay-buffer buf)
    (kill-buffer buf)))
David Byers's avatar
David Byers committed
367
368
369
370
371
372
373
374

(defun lyskom-customize-save-and-quit ()
  "Save and quit the customize buffer"
  (interactive)
  (lyskom-customize-apply)
  (lyskom-customize-send)
  (lyskom-customize-quit))

David Byers's avatar
David Byers committed
375
376
377
378
(defun lyskom-customize-help ()
  (interactive)
  (message (lyskom-get-string 'customize-help)))

David Byers's avatar
David Byers committed
379
380
381
382
383
384
385
(defun lyskom-widget-click (event)
  (interactive "e")
  (let ((pos (event-point event)))
    (if (and pos (widget-at pos))
        (widget-button-click event)
      (popup-mode-menu))))

David Byers's avatar
David Byers committed
386
387
388
(defun kom-customize ()
  "Open the customize buffer"
  (interactive)
David Byers's avatar
X    
David Byers committed
389
390
391
392
393
  (let ((buf (lyskom-get-buffer-create 'customize
                                       (lyskom-format
                                        (lyskom-custom-string 'buffer-name)
                                        lyskom-server-name)
                                       t)))
David Byers's avatar
David Byers committed
394
395
396
397
398
    (unwind-protect
        (progn
          (lyskom-start-of-command 'kom-customize)
           (save-excursion
             (set-buffer buf)
David Byers's avatar
X    
David Byers committed
399
             (kill-all-local-variables)
David Byers's avatar
David Byers committed
400
401
402
403
             (make-local-variable 'lyskom-widgets)
             (setq lyskom-widgets nil)
             (let ((inhibit-read-only t))
               (erase-buffer))
David Byers's avatar
David Byers committed
404
             (use-local-map lyskom-customize-map)
David Byers's avatar
David Byers committed
405
             (condition-case nil
406
                 (lyskom-copy-face 'kom-active-face 'widget-button-face)
David Byers's avatar
David Byers committed
407
               (error nil))
David Byers's avatar
David Byers committed
408
409
410
411
412
413
414
415
416
417
             (mapcar 'lyskom-custom-insert lyskom-customize-buffer-format)
             (widget-setup)
             (mapcar (function
                      (lambda (variable)
                        (widget-value-set (cdr variable)
                                          (save-excursion
                                            (set-buffer lyskom-buffer)
                                            (symbol-value (car variable))))))
                     lyskom-widgets)
             (widget-setup))
David Byers's avatar
X    
David Byers committed
418
           (lyskom-display-buffer buf))
David Byers's avatar
David Byers committed
419
420
421
422
423
      (save-excursion
        (set-buffer lyskom-buffer)
        (lyskom-end-of-command)))
    (goto-char (point-min))))

424

David Byers's avatar
David Byers committed
425
426
427
428
429
430
;;; ============================================================
;;; Non-user functions
;;;

(defun lyskom-custom-insert (w)
  (cond ((symbolp w)
431
         (widget-insert (substitute-command-keys (lyskom-custom-string w))))
David Byers's avatar
David Byers committed
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        ((listp w)
         (let ((start (point))
               (end nil)
               (inhibit-read-only t))
           (widget-insert (lyskom-custom-string (car w)))
           (setq end (point))
           (mapcar (function
                    (lambda (fn)
                      (funcall (intern (concat "lyskom-custom-insert-"
                                               (symbol-name fn)))
                               start end)))
                   (cdr w))))
        ((stringp w)
         (widget-insert w))
        ((vectorp w)
         (setq lyskom-widgets (cons (cons (aref w 0)
                                          (lyskom-create-widget (aref w 0)))
                                    lyskom-widgets)))))

(defun lyskom-custom-insert-bold (s e)
David Byers's avatar
David Byers committed
452
  (add-text-properties s e (list 'face 'bold 'end-closed nil)))
David Byers's avatar
David Byers committed
453
454
455
456
457
458
459
460
461
462
463
464

(defun lyskom-custom-insert-centered (s e)
  (save-excursion (goto-char s)
                  (center-line 1)))


(defun lyskom-custom-get-value (var)
  (save-excursion
    (set-buffer lyskom-buffer)
    (symbol-value var)))

(defun lyskom-custom-string (s)
465
  (lyskom-get-string s 'lyskom-custom-strings))
David Byers's avatar
David Byers committed
466
467


468
469
470
471
(defvar lyskom-custom-variables-missing '(kom-permanent-filter-list
                                          kom-quit-hook)
  "List of user variables not in lyskom-custom-variables.")

David Byers's avatar
David Byers committed
472
(defvar lyskom-custom-variables
473
  '((kom-personal-messages-in-window (open-window))
David Byers's avatar
David Byers committed
474
    (kom-write-texts-in-window (open-window))
David Byers's avatar
X    
David Byers committed
475
476
    (kom-list-membership-in-window (open-window))
    (kom-edit-filters-in-window (open-window))
David Byers's avatar
David Byers committed
477
478
    (kom-prioritize-in-window (open-window))
    (kom-customize-in-window (open-window))
David Byers's avatar
David Byers committed
479
480
481
    (kom-view-commented-in-window (open-window))
    (kom-edit-filters-in-window (open-window))
    (kom-list-membership-in-window (open-window))
482
483
    (kom-customize-format (choice ((const (long-format long))
                                   (const (short-format short)))))
David Byers's avatar
David Byers committed
484
    (kom-default-language (language-choice))
David Byers's avatar
X    
David Byers committed
485
486
    (kom-user-prompt-format (string))
    (kom-user-prompt-format-executing (string))
487
488
489
490
    (kom-anonymous-prompt-format (string))
    (kom-anonymous-prompt-format-executing (string))
    (kom-enabled-prompt-format (string))
    (kom-enabled-prompt-format-executing (string))
David Byers's avatar
David Byers committed
491
492
    (kom-cite-string (string))
    (kom-created-texts-are-read (toggle (yes no)))
493
494
    (kom-created-texts-are-saved (choice ((const (no nil))
                                          (file nil :tag to-file))))
David Byers's avatar
David Byers committed
495
    (kom-default-mark (choice ((number (0 255) 
David Byers's avatar
David Byers committed
496
                                       :tag selected-mark
497
498
                                       :format "%[%t%] (%v)"
                                       :size 0)
David Byers's avatar
David Byers committed
499
                               (const (ask nil)))))
500
501
502
503
504
505
    (kom-symbolic-marks-alist (repeat (mark-association
                                       nil
                                       :tag symbolic-mark-association
                                       :mark-key-prompt symbolic-mark-name
                                       :mark-value-prompt mark-type-to-assoc)
                                      :indent 4))
506
    (kom-reading-puts-comments-in-pointers-last (toggle (after before)))
David Byers's avatar
David Byers committed
507
508
509
    (kom-autowrap (choice ((const (on t))
                           (const (off nil))
                           (number nil :tag max-text-length))))
David Byers's avatar
David Byers committed
510
    (kom-dashed-lines (toggle (on off)))
David Byers's avatar
David Byers committed
511
    (kom-show-author-at-end (toggle (on off)))
512
513
514
515
516

    (kom-truncate-threshold (choice ((const (off nil))
				     (number nil :tag truncate-threshold-lines))))
    (kom-truncate-show-lines (number nil))

David Byers's avatar
David Byers committed
517
    (kom-print-number-of-unread-on-entrance (toggle (yes no)))
David Byers's avatar
David Byers committed
518
519
520
521
522
523
    (kom-presence-messages (choice ((const (on t))
                                    (const (friends friends))
                                    (repeat (person nil :tag name)
                                            :indent 4
                                            :tag some-persons
                                            :menu-tag some-persons))))
524
525
    (kom-presence-messages-in-buffer
     (choice ((const (on t))
David Byers's avatar
David Byers committed
526
              (const (friends friends))
527
              (repeat (person nil :tag name)
David Byers's avatar
David Byers committed
528
                      :indent 4
529
530
                      :tag some-persons
                      :menu-tag some-persons))))
David Byers's avatar
David Byers committed
531
    (kom-show-where-and-what (toggle (yes no)))
532
    (kom-show-since-and-when (toggle (yes no)))
David Byers's avatar
David Byers committed
533
534
535
536
537
538
539
540
541
    (kom-idle-hide (number))
    (kom-show-footnotes-immediately (toggle (yes no)))
    (kom-follow-comments-outside-membership (toggle (yes no)))
    (kom-read-depth-first (toggle (depth-first time-order)))
    (kom-continuous-scrolling  (toggle (on off)))
    (kom-deferred-printing (toggle (on off)))
    (kom-higher-priority-breaks (choice ((const (express-break express))
                                         (const (break t))
                                         (const (no-break nil)))))
542
    (kom-server-priority (number))
543
544
545
546
547
548
549
550
    (kom-server-priority-breaks (choice ((const (express-server-break express))
                                         (const (express-server-letters-break express-letters))
                                         (const (server-break t))
                                         (const (letters-server-break letters))
                                         (const (after-conf-server-break after-conf))
                                         (const (after-conf-letters-server-break after-conf-letters))
                                         (const (when-done-server-break when-done))
                                         (const (no-break nil)))))
David Byers's avatar
David Byers committed
551
552
    (kom-login-hook (repeat (command nil :tag command)
                            :indent 4))
David Byers's avatar
David Byers committed
553
554
555
    (kom-do-when-done (repeat (choice ((command nil :tag command)
                                       (kbd-macro nil :tag kbd-macro))
                                      :tag execute
David Byers's avatar
David Byers committed
556
                                      :help-echo select-what-to-execute
David Byers's avatar
David Byers committed
557
558
                                      :format "%[%t%] %v")
                              :indent 4))
David Byers's avatar
David Byers committed
559
560
561
562
    (kom-page-before-command (choice ((const (page-none nil))
                                      (const (page-all t))
                                      (repeat (command nil
                                                       :tag command)
David Byers's avatar
David Byers committed
563
                                              :indent 4
David Byers's avatar
David Byers committed
564
                                              :tag page-some
565
                                              :menu-tag page-some
David Byers's avatar
David Byers committed
566
                                              :format "%[%t%] %v"
567
                                              :value (kom-view-next-text)))
David Byers's avatar
David Byers committed
568
                                     :format "%[%t%] %v"))
David Byers's avatar
David Byers committed
569
570
    (kom-permissive-completion (noggle (on off)))
    (kom-membership-default-priority
571
572
     (choice ((const (ask-every-time ask))
              (const (ask-every-time nil))
David Byers's avatar
David Byers committed
573
574
              (number (0 255)
                      :tag fixed-priority 
David Byers's avatar
David Byers committed
575
                      :help-echo select-priority
576
577
                      :format "%[%t%] (%v)"
                      :size 0))))
David Byers's avatar
David Byers committed
578
579
580
    (kom-show-personal-messages-in-buffer
     (choice ((const (messages-in-lyskom-buffer t))
              (const (discard-messages nil))
David Byers's avatar
David Byers committed
581
              (string nil :tag in-named-buffer :help-echo select-buffer))))
David Byers's avatar
David Byers committed
582
    (kom-pop-personal-messages (toggle (yes no)))
583
    (kom-ding-on-new-letter (ding))
David Byers's avatar
David Byers committed
584
585
586
587
588
    (kom-ding-on-priority-break (ding))
    (kom-ding-on-wait-done (ding))
    (kom-ding-on-common-messages (ding))
    (kom-ding-on-group-messages (ding))
    (kom-ding-on-personal-messages (ding))
David Byers's avatar
David Byers committed
589
    (kom-ding-on-no-subject (ding))
David Byers's avatar
David Byers committed
590
591
592
593
    (kom-audio-player (file))
    (kom-default-message-recipient 
     (choice ((const (everybody-rcpt everybody))
              (const (group-rcpt group))
594
595
              (const (sender-rcpt sender))
              (const (last-recipient-recpt last-recipient)))))
David Byers's avatar
David Byers committed
596
    (lyskom-filter-outgoing-messages (noggle (yes no)))
David Byers's avatar
David Byers committed
597
    (kom-friends (repeat (person nil :tag name) :indent 4))
598
    (kom-morons (repeat (person nil :tag name) :indent 4))
David Byers's avatar
David Byers committed
599
600
    (kom-url-viewer-preferences (repeat (url-viewer nil :tag viewer-program)
                                        :indent 4))
David Byers's avatar
David Byers committed
601
602
603
604
605
606
607
608
    (kom-mosaic-command (file))
    (kom-netscape-command (file))
    (kom-confirm-multiple-recipients
     (choice ((const (dont-check nil))
              (const (check-before-open before))
              (const (check-before-send after)
                     :match (lambda (w v) (and v (not (eq v 'before))))))))
    (kom-check-commented-author-membership (toggle (yes no)))
David Byers's avatar
David Byers committed
609
    (kom-check-for-new-comments (toggle (yes no)))
David Byers's avatar
David Byers committed
610
611
    (kom-inhibit-typeahead (noggle (yes no)))
    (kom-max-buffer-size (choice ((const (no-size-limit nil))
David Byers's avatar
David Byers committed
612
613
614
                                  (number nil 
                                          :tag max-size-in-bytes
                                          :help-echo select-buffer-size))))
David Byers's avatar
David Byers committed
615
616
617

    (kom-ansaphone-record-messages (toggle (yes no)))
    (kom-ansaphone-show-messages (toggle (yes no)))
David Byers's avatar
David Byers committed
618
    (kom-ansaphone-default-reply (string nil :format "%[%t%]\n%v"))
David Byers's avatar
David Byers committed
619
    (kom-remote-control (toggle (on off)))
David Byers's avatar
David Byers committed
620
621
    (kom-remote-controllers (repeat (person nil :tag name)
                                    :indent 4))
David Byers's avatar
David Byers committed
622
    (kom-self-control (toggle (yes no)))
623
    (kom-ispell-dictionary (ispell-dictionary))
David Byers's avatar
David Byers committed
624
    (kom-show-namedays (toggle (on off)))
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664

    (kom-show-week-number (toggle (on off)))
    (kom-membership-default-placement (choice ((const (last last))
                                               (const (first first))
                                               (number nil
                                                       :tag specific-placement
                                                       ))))
    (kom-show-imported-importer (toggle (on off)))
    (kom-show-imported-envelope-sender (toggle (on off)))
    (kom-show-imported-external-recipients (toggle (on off)))
    (kom-agree-text (choice ((string nil :tag a-string)
                             (repeat (string nil
                                             :tag a-string
                                             :format "%[%t%] `%v'\n")
                                     :indent 4
                                     :tag some-string
                                     :menu-tag some-string))))
    (kom-silent-ansaphone (noggle (on off)))
    (kom-default-session-priority (choice ((const (unspecified nil))
                                           (number nil
                                                   :tag priority))))
    (kom-unsubscribe-makes-passive (toggle (on off)))
    (kom-review-priority (choice ((const (same-as-conf nil))
                                  (number nil :tag fixed-priority))))
    (kom-show-creating-software (toggle (on off)))
    (kom-text-footer-format (choice ((const (default-format nil))
                                     (string nil :tag custom-format))))
    (kom-long-lines (toggle (on off)))
    (kom-postpone-default (number))
    (kom-allow-incompleteness (toggle (on off)))
    (kom-smileys (toggle (on off)))
    (kom-ignore-message-senders (repeat (person nil :tag name)
                                    :indent 4))
    (kom-ignore-message-recipients (repeat (person nil 
                                                   :tag name
                                                   :lyskom-predicate (pers conf))
                                    :indent 4))
    (kom-text-header-dash-length (number))
    (kom-text-footer-dash-length (number))
    (kom-show-personal-message-date (toggle (on off)))
665
666
    (kom-mercial (string))
    (kom-w3-simplify-body (toggle (on off)))
667
668
    (kom-bury-buffers (toggle (on off)))
    (kom-ansaphone-replies (ansaphone))
669
    (kom-complete-numbers-before-names (toggle (on off)))
670
    (kom-keep-alive-interval (number))
671
    (kom-prompt-for-text-no (repeat (command nil :tag command)))
672
    (kom-saved-file-name (file))
673
674
    (kom-follow-attachments (toggle (yes no)))
    (kom-show-unread-in-frame-title (toggle (yes no)))
675
    (kom-confirm-add-recipients (toggle (yes no)))
676
    (kom-trim-buffer-minimum (number))
677
678
    (kom-dont-check-commented-authors (repeat (person nil 
                                                      :tag name) :indent 4))
David Byers's avatar
David Byers committed
679
680
681
682
683
684
685
686
687
688
689
690
691
))

(defvar lyskom-widget-functions 
  '((toggle . lyskom-toggle-widget)
    (noggle . lyskom-toggle-widget-inverse)
    (ding   . lyskom-ding-widget)
    (choice . lyskom-choice-widget)
    (string . lyskom-string-widget)
    (number . lyskom-number-widget)
    (const .  lyskom-item-widget)
    (repeat . lyskom-repeat-widget)
    (kbd-macro . lyskom-kbd-macro-widget)
    (url-viewer . lyskom-url-viewer-widget)
692
    (ispell-dictionary . lyskom-ispell-dictionary-widget)
David Byers's avatar
David Byers committed
693
694
695
    (open-window . lyskom-open-window-widget)
    (command . lyskom-command-widget)
    (person . lyskom-person-widget)
David Byers's avatar
David Byers committed
696
    (language-choice . lyskom-language-widget)
David Byers's avatar
David Byers committed
697
    (file . lyskom-file-widget)
698
    (ansaphone . lyskom-ansaphone-reply-widget)
699
    (mark-association . lyskom-mark-association-widget)
David Byers's avatar
David Byers committed
700
701
))

David Byers's avatar
David Byers committed
702
703
704
705
706
707
(defun lyskom-make-menu-tag (str)
  "Make a menu tag from the string STR."
  (if (string-match "\\(.*\\):\\s-*" str)
      (match-string 1 str)
    str))

David Byers's avatar
David Byers committed
708
709
710
711
712
713
(defun lyskom-create-widget (variable)
  (let* ((el (assq variable lyskom-custom-variables))
         (dummy (or el (error "Unknown variable: %S" variable)))
         (spec (lyskom-widget-convert-specification (car (cdr el))))
         (tag-sym (intern (concat (symbol-name variable) "-tag")))
         (doc-sym (intern (concat (symbol-name variable) "-doc")))
714
         (help-sym (intern (concat (symbol-name variable) "-help")))
David Byers's avatar
David Byers committed
715
         (value (save-excursion (set-buffer lyskom-buffer)
David Byers's avatar
David Byers committed
716
717
718
                                (symbol-value variable)))
         (storage-widget nil))

719
    (lyskom-ignore value help-sym dummy)       ; Are they ever used?
David Byers's avatar
David Byers committed
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

    (setq storage-widget
          (condition-case nil
              (prog1
                (widget-create 'checkbox
                               ':value (and (not (memq variable kom-dont-read-saved-variables))
                                            (or (memq variable lyskom-elisp-variables)
                                                (memq variable lyskom-global-boolean-variables)
                                                (memq variable lyskom-global-non-boolean-variables)))
                               ':args variable
                               ':format "%[%v%]"
                               ':help-echo (lyskom-custom-string 'variable-type-help))
                (widget-insert " "))
            (error nil)))

David Byers's avatar
David Byers committed
735
736
    (setq spec 
          (cons (car spec)
737
738
739
                (append
                 (list ':tag
                       (lyskom-custom-string tag-sym)
David Byers's avatar
David Byers committed
740
741
                       ':menu-tag
                       (lyskom-make-menu-tag (lyskom-custom-string tag-sym))
742
743
                       ':value
                       (lyskom-custom-get-value variable)
David Byers's avatar
David Byers committed
744
745
746
747
                       ':help-echo
                       (lyskom-format 
                        (lyskom-custom-string 'default-help-echo)
                        (symbol-name variable))
David Byers's avatar
David Byers committed
748
                       ':lyskom-storage-widget storage-widget
749
750
                       )
                 (cdr spec))))
David Byers's avatar
David Byers committed
751
    (let ((widget (apply 'widget-create spec)))
David Byers's avatar
David Byers committed
752
753
      (condition-case nil
          (progn
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
            (if (string= "" (lyskom-custom-string doc-sym))
                (widget-insert "\n")
              (widget-insert "  ")
              (widget-create 'lyskom-widget-help
                             ':value (lyskom-default-value 'kom-customize-format)
                             ':help-echo
                             (if (eq (lyskom-default-value 'kom-customize-format)
                                     'long)
                                 (lyskom-custom-string 'hide-doc)
                               (lyskom-custom-string 'show-doc))
                             ':args
                             (list (list 'long
                                         "\n%s\n\n"
                                         (lyskom-custom-string doc-sym)
                                         (lyskom-custom-string 'hide-doc)
769
                                         "-")
770
771
772
773
774
775
                                   (list 'short 
                                         "%s"
                                         ""
                                         (lyskom-custom-string 'show-doc)
                                         "?"))
                             ':format "%[[%T]%]\n%D")))
David Byers's avatar
David Byers committed
776
777
        (error (widget-insert "\n")))
        widget)))
David Byers's avatar
David Byers committed
778
779
780
781
782
783
784
785
786
787


(defun lyskom-widget-convert-specification (spec)
  "Convert a LysKOM widget specification to something widget-create accepts"
  (let ((convertfn (assq (car spec) lyskom-widget-functions)))
    (if (null convertfn)
        (error "Unknown widget type: %S" spec))
    (nconc (funcall (cdr convertfn)
                    (car spec)
                    (car (cdr spec))
David Byers's avatar
David Byers committed
788
                    (cdr (cdr spec)))
David Byers's avatar
David Byers committed
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
           (lyskom-widget-convert-props spec))))

(defun lyskom-widget-convert-props (spec)
  "Convert widget properties to a format that widget-create likes"
  (let ((propl (nthcdr 2 spec))
        (result))
    (if (/= 0 (% (length propl) 2))
        (error "Widget property list has odd length: %S" spec))
    (while propl
      (setq result (cons (car propl) result))
      (setq propl (cdr propl))
      (setq result
            (cons (cond ((symbolp (car propl))
                         (cond ((eq (car propl) t) t)
                               ((eq (car propl) nil) nil)
                               (t (lyskom-custom-string (car propl)))))
                        ((and (consp (car propl))
                              (eq 'quote (car (car propl))))
                         (car (cdr (car propl))))
                        (t (car propl)))
                  result))
      (setq propl (cdr propl)))
    (nreverse result)))


David Byers's avatar
David Byers committed
814
815
816
817
818
819
820
821
822
823
(defun lyskom-build-simple-widget-spec (type defaults propl)
  (let (new-props)
    (while defaults
      (unless (plist-member propl (car defaults))
        (setq new-props (cons (car defaults)
                              (cons (car (cdr defaults)) new-props))))
      (setq defaults (cdr (cdr defaults))))
    (cons type new-props)))


David Byers's avatar
David Byers committed
824
(defun lyskom-file-widget (type &optional args propl)
David Byers's avatar
David Byers committed
825
  (lyskom-build-simple-widget-spec 'file
826
                                   '(:format "%[%t%] %v" :size 0)
David Byers's avatar
David Byers committed
827
                                   propl))
David Byers's avatar
David Byers committed
828
829

(defun lyskom-person-widget (type &optional args propl)
David Byers's avatar
David Byers committed
830
  (lyskom-build-simple-widget-spec 'lyskom-name nil propl))
David Byers's avatar
David Byers committed
831

832
833
834
(defun lyskom-mark-association-widget (type &optional args propl)
  (lyskom-build-simple-widget-spec 'lyskom-mark-association nil propl))

David Byers's avatar
David Byers committed
835
(defun lyskom-command-widget (type &optional args propl)
David Byers's avatar
David Byers committed
836
  (lyskom-build-simple-widget-spec 'lyskom-command nil propl))
David Byers's avatar
David Byers committed
837
838

(defun lyskom-kbd-macro-widget (type &optional args propl)
David Byers's avatar
David Byers committed
839
840
841
  (lyskom-build-simple-widget-spec 'lyskom-kbd-macro
                                   (list ':macro-buffer lyskom-buffer)
                                   propl))
David Byers's avatar
David Byers committed
842
843

(defun lyskom-item-widget (type &optional args propl)
David Byers's avatar
David Byers committed
844
845
846
847
848
849
  (lyskom-build-simple-widget-spec 'item
                                   (list ':format "%t"
                                         ':tag (lyskom-custom-string 
                                                (elt args 0))
                                         ':value (elt args 1))
                                   propl))
David Byers's avatar
David Byers committed
850

David Byers's avatar
David Byers committed
851
(defun lyskom-language-widget (type &optional args propl)
David Byers's avatar
David Byers committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list ':format "%[%t%] %v"
         ':case-fold t
         ':args
         (mapcar
          (function
           (lambda (x)
             (list 'item
                   ':tag (lyskom-language-name (car x))
                   ':format "%t"
                   ':value (elt x 0))))
          lyskom-languages))
   propl))
David Byers's avatar
David Byers committed
866

867
(defun lyskom-ispell-dictionary-widget (type &optional args propl)
868
869
  (let ((tmp-dictionary-alist nil))
    (condition-case nil 
David Byers's avatar
David Byers committed
870
871
        (progn (require 'ispell)
               (setq tmp-dictionary-alist ispell-dictionary-alist))
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
      (error (if (null ispell-dictionary-alist)
                 (setq tmp-dictionary-alist '("american" "brasiliano"
                                              "british" "castellano"
                                              "castellano8" "czech" 
                                              "dansk" "deutsch"
                                              "deutsch8" "english" 
                                              "esperanto" "esperanto-tex"
                                              "francais7" "francais" 
                                              "francais-tex" "nederlands"
                                              "nederlands8" "norsk"
                                              "norsk7-tex" "polish"
                                              "russian" "svenska")))))
    (lyskom-build-simple-widget-spec 
     'menu-choice
     (list ':format "%[%t%] %v"
           ':case-fold nil
           ':args
           (cons (list 'item
                       ':tag "ispell-dictionary"
                       ':format "%t"
                       ':value nil)
                 (delq nil
                       (mapcar 
                        (function
                         (lambda (x)
                           (and (car x)
                                (list 'item
                                      ':tag (car x)
                                      ':format "%t"
                                      ':value (car x)))))
                        tmp-dictionary-alist))))
     propl)))
904

David Byers's avatar
David Byers committed
905
(defun lyskom-url-viewer-widget (type &optional args propl)
David Byers's avatar
David Byers committed
906
907
908
909
910
911
912
913
914
915
916
917
918
919
  (lyskom-build-simple-widget-spec
   'menu-choice 
   (list ':format "%[%v%]\n"
         ':case-fold t
         ':help-echo (lyskom-custom-string 'select-url-viewer)
         ':args
         (list (list 'item
                     ':tag (lyskom-custom-string 'no-viewer)
                     ':format "%t"
                     ':value nil)
               (list 'item 
                     ':tag (lyskom-custom-string 'default-viewer)
                     ':format "%t"
                     ':value "default")
920
921
922
923
               (list 'item
                     ':tag (lyskom-custom-string 'windows-viewer)
                     ':format "%t"
                     ':value "windows")
David Byers's avatar
David Byers committed
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
               (list 'item
                     ':tag (lyskom-custom-string 'netscape-viewer)
                     ':format "%t"
                     ':value "netscape")
               (list 'item
                     ':tag (lyskom-custom-string 'emacs-w3-viewer)
                     ':format "%t"
                     ':value "w3")
               (list 'item 
                     ':tag (lyskom-custom-string 'emacs-general-viewer)
                     ':format "%t"
                     ':value "emacs")
               (list 'item
                     ':tag (lyskom-custom-string 'emacs-dired-viewer)
                     ':format "%t"
                     ':value "dired")
               (list 'item 
                     ':tag (lyskom-custom-string 'emacs-mail-viewer)
                     ':format "%t"
                     ':value "mail-mode")
               (list 'item
                     ':tag (lyskom-custom-string 'emacs-telnet-viewer)
                     ':format "%t"
                     ':value "telnet-mode")
               (list 'item
                     ':tag (lyskom-custom-string 'mosaic-viewer)
                     ':format "%t"
                     ':value "mosaic")
               (list 'item
                     ':tag (lyskom-custom-string 'lynx-viewer)
                     ':format "%t"
                     ':value "lynx")))
   propl))
David Byers's avatar
David Byers committed
957
958

(defun lyskom-open-window-widget (type &optional args propl)
David Byers's avatar
David Byers committed
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list ':case-fold t
         ':format "%[%t%] %v"
         ':args
         (list (list 'item
                     ':tag (lyskom-custom-string 'other-window)
                     ':format "%t"
                     ':value 'other)
               (list 'item 
                     ':tag (lyskom-custom-string 'other-frame)
                     ':format "%t"
                     ':value 'other-frame)
               (list 'item 
                     ':tag (lyskom-custom-string 'new-frame)
                     ':format "%t"
                     ':value 'new-frame)
               (list 'item
                     ':tag (lyskom-custom-string 'lyskom-window)
                     ':format "%t"
                     ':value nil)
               (list 'editable-field
                     ':tag (lyskom-custom-string 'window-on-buffer)
                     ':format "%[%t%]: `%v'"
                     ':value ""
                     ':size 0)))
   propl))
David Byers's avatar
David Byers committed
986
987

(defun lyskom-ding-widget (type &optional args propl)
David Byers's avatar
David Byers committed
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list  ':case-fold t
          ':format "%[%t%] %v"
          ':args
          (list (list 'item 
                      ':tag (lyskom-custom-string 'turned-off)
                      ':value 0
                      ':format "%t"
                      ':match '(lambda (w v) (eq v 0)))
                (list 'lyskom-number
                      ':tag (lyskom-custom-string 'number-of-times)
                      ':help-echo (lyskom-custom-string 'select-number)
                      ':value "1"
                      ':format "%[%t%]: (%v)"
                      ':size 0
                      ':min-value 1
                      ':max-value 255)
                (list 'lyskom-string
                      ':tag (lyskom-custom-string 'sound-file)
                      ':help-echo (lyskom-custom-string 'select-audio-file)
                      ':size 0)
                (list 'editable-list
                      ':format "%[%t%]\n%v%i"
                      ':indent 4
                      ':tag (lyskom-custom-string 'specific-spec)
                      ':menu-tag (lyskom-custom-string 'specific-spec)
                      ':args
                      `((cons :format "%v" 
                              :value (1 0)
1018
                              :args
David Byers's avatar
David Byers committed
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
                              ((menu-choice
                                :case-fold t
                                :format "%[%t%]: %v"
                                :tag ,(lyskom-custom-string 'conf-or-person)
                                :args
                                ((lyskom-name :lyskom-predicate (pers conf)
                                              :tag ,(lyskom-custom-string 'conf-or-person))
                                 (item :tag ,(lyskom-custom-string 'other-persons)
                                       :value t
                                       :format "%t\n")))
                               (menu-choice
                                :case-fold t
                                :format "%[%t%]: %v\n"
                                :tag ,(lyskom-custom-string 'ding)
                                :args
                                ((item :tag ,(lyskom-custom-string 'turned-off)
                                       :value nil
                                       :format "%t"
                                       :match (lambda (w v) (or (null v) (eq v 0))))
                                 (lyskom-number :tag ,(lyskom-custom-string 'number-of-times)
                                                :help-echo ,(lyskom-custom-string 'select-number)
                                                :value "1"
                                                :format "%[%t%]: (%v)"
                                                :size 0
                                                :min-value 1
                                                :max-value 255)
                                 (lyskom-string :tag ,(lyskom-custom-string 'sound-file)
                                                :help-echo ,(lyskom-custom-string 'select-audio-file)
                                                :size 0))))))
                      )
                ))
   propl))
David Byers's avatar
David Byers committed
1051
1052

(defun lyskom-toggle-widget-inverse (type &optional args propl)
David Byers's avatar
David Byers committed
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list ':case-fold t
         ':format "%[%t%] %v"
         ':args
         (list (list 'item ':tag (lyskom-custom-string (elt args 0))
                     ':value nil
                     ':format "%t")
               (list 'item 
                     ':tag (lyskom-custom-string (elt args 1))
                     ':value t
                     ':match '(lambda (w v) v)
                     ':format "%t")))
   propl))
David Byers's avatar
David Byers committed
1067
1068

(defun lyskom-toggle-widget (type &optional args propl)
David Byers's avatar
David Byers committed
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list ':case-fold t
         ':format "%[%t%] %v"
         ':args
         (list (list 'item
                     ':tag (lyskom-custom-string (elt args 0))
                     ':value t
                     ':format "%t"
                     ':match '(lambda (w v) v))
               (list 'item ':tag (lyskom-custom-string (elt args 1))
                     ':value nil
                     ':format "%t")))
   propl))
David Byers's avatar
David Byers committed
1083
1084
1085


(defun lyskom-repeat-widget (type &optional args propl)
David Byers's avatar
David Byers committed
1086
1087
1088
1089
1090
1091
  (lyskom-build-simple-widget-spec
   'editable-list 
   (list ':format "%[%t%]\n%v%i"
         ':args
         (list (lyskom-widget-convert-specification args)))
   propl))
David Byers's avatar
David Byers committed
1092
1093

(defun lyskom-choice-widget (type &optional args propl)
David Byers's avatar
David Byers committed
1094
1095
1096
1097
1098
1099
1100
  (lyskom-build-simple-widget-spec
   'menu-choice
   (list ':case-fold t
         ':format "%[%t%] %v"
         ':args
         (mapcar 'lyskom-widget-convert-specification args))
   propl))
David Byers's avatar
David Byers committed
1101
1102
1103


(defun lyskom-string-widget (type &optional args propl)
David Byers's avatar
David Byers committed
1104
1105
1106
1107
1108
  (lyskom-build-simple-widget-spec
   'lyskom-string 
   (list ':size 0 
         ':format "%[%t%] `%v'")
   propl))
David Byers's avatar
David Byers committed
1109
1110
1111
1112


(defun lyskom-number-widget (type &optional args propl)
  (if args
David Byers's avatar
David Byers committed
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
      (lyskom-build-simple-widget-spec
       'lyskom-number
       (list ':min-value (elt args 0)
             ':max-value (elt args 1)
             ':size 0)
       propl)
    (lyskom-build-simple-widget-spec
     'lyskom-number
     (list ':size 0)
     propl)))
David Byers's avatar
David Byers committed
1123

1124
1125
1126
1127
;;;
;;; The ansaphone reply widget (whew!)

(defun lyskom-ansaphone-reply-widget (type &optional args propl)
David Byers's avatar
David Byers committed
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
  (lyskom-build-simple-widget-spec
   'editable-list
   (list ':format "%t:\n%v%i\n"
         ':args
         `((group
            :args ((menu-choice :tag ,(lyskom-custom-string 'ar-message-type)
                                :format "%[%t%]: %v"
                                :args
                                ((item :value personal :tag ,(lyskom-custom-string 'ar-personal))
                                 (item :value group :tag ,(lyskom-custom-string 'ar-group))
                                 (item :value common :tag ,(lyskom-custom-string 'ar-alarm))
                                 (item :value nil :tag ,(lyskom-custom-string 'ar-any-type))))
                   (menu-choice :tag ,(lyskom-custom-string 'ar-sender)
                                :args
                                ((item :value nil :tag ,(lyskom-custom-string 'ar-any-sender))
                                 (editable-list :tag ,(lyskom-custom-string 'ar-specified-sender)
                                                :menu-tag ,(lyskom-custom-string 'ar-specified-sender)
                                                :format "%t:\n%v%i\n"
                                                :indent 14
                                                :args
                                                ((lyskom-name 
                                                  :format "%[%t%]: %v"
                                                  :tag ,(lyskom-custom-string 'ar-person))))))
                   (menu-choice :tag ,(lyskom-custom-string 'ar-recipient)
                                :args
                                ((item :value nil :tag ,(lyskom-custom-string 'ar-any-recipient))
                                 (editable-list :tag ,(lyskom-custom-string 'ar-specified-recipient)
                                                :menu-tag ,(lyskom-custom-string 'ar-specified-recipient)
                                                :format "%t:\n%v%i\n"
                                                :indent 14
                                                :args
                                                ((lyskom-name :tag ,(lyskom-custom-string 'ar-pers-or-conf)
                                                              :format "%[%t%]: %v"
                                                              :lyskom-predicate (pers conf))))))
                   (menu-choice :tag ,(lyskom-custom-string 'ar-message-text)
                                :args
                                ((item :value nil :tag ,(lyskom-custom-string 'ar-any-message))
                                 (lyskom-string :tag ,(lyskom-custom-string 'ar-matching-regexp)
                                                :size 0
                                                :format "%[%t%] `%v'\n")))
                   (menu-choice :tag ,(lyskom-custom-string 'ar-reply)
                                :args
                                ((item :value nil :tag ,(lyskom-custom-string 'ar-no-reply))
                                 (lyskom-string :tag ,(lyskom-custom-string 'ar-reply-text)
                                                :size 0
                                                :format "%[%t%] `%v'\n")))))))
   propl))
David Byers's avatar
David Byers committed
1175

1176
1177

;;; ======================================================================
David Byers's avatar
David Byers committed
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
;;; Generic LysKOM widget functions
;;;

(defun lyskom-widget-value-get (widget)
  (widget-get widget ':value))

(defun lyskom-widget-value-delete (widget)
  (set-marker (widget-get widget ':value-from) nil)
  (set-marker (widget-get widget ':value-to) nil))
  

(defun lyskom-widget-value-to-external (widget value)
  value)

(defun lyskom-widget-value-to-internal (widget value)
  value)

1195
1196
1197
1198
1199
1200
(defun lyskom-widget-invalid-value (widget)
  (widget-put widget ':error 
              (lyskom-format (lyskom-custom-string 'invalid-value)
                             (widget-value widget)))
  widget)

David Byers's avatar
David Byers committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226

;;;
;;; The Person Widget
;;;

(defun lyskom-widget-name-action (widget &optional event)
  (widget-value-set widget
                    (save-excursion
                      (set-buffer lyskom-buffer)
                      (lyskom-read-conf-no
                       (lyskom-custom-string
                        (cond ((widget-get widget ':lyskom-prompt)
                               (widget-get widget ':lyskom-prompt))
                              ((and 
                                (memq 'pers (widget-get widget
                                                        ':lyskom-predicate))
                                (memq 'conf (widget-get widget
                                                        ':lyskom-predicate)))
                               'which-conf-or-person)
                              ((memq 'pers (widget-get widget
                                                       ':lyskom-predicate))
                               'which-person)
                              ((memq 'conf (widget-get widget
                                                       ':lyskom-predicate))
                               'which-conf)
                              (t 'which-name)))
1227
1228
1229
1230
                       (widget-get widget ':lyskom-predicate)
                       nil
                       nil
                       t)))
David Byers's avatar
David Byers committed
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
  (widget-setup))
               
(defun lyskom-widget-name-value-create (widget)
  (let* ((size (widget-get widget ':size))
         (value (widget-get widget ':value))
         (from (point))
         (string (save-excursion
                   (set-buffer lyskom-buffer)
                   (cond ((or (null value) (eq 0 value)) "")
                         (t (or (conf-stat->name
                                 (blocking-do 'get-conf-stat value))
                                (lyskom-format
                                 (lyskom-custom-string 'some-person)
                                 value)))))))
    (if (null size)
        (insert string)
      (insert string)
David Byers's avatar
David Byers committed
1248
1249
      (if (< (lyskom-string-width value) size)
          (insert-char ?\  (- size (lyskom-string-width value)))))
David Byers's avatar
David Byers committed
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

    (widget-put widget ':value-from (copy-marker from))
    (widget-put widget ':value-to (copy-marker (point)))
    (set-marker-insertion-type (widget-get widget ':value-to) nil)
    (if (null size)
        (insert ?\n)
      (insert ?\ ))))

(defun lyskom-widget-name-match (widget value)
  (and (numberp value)
       (>= value 0)))

(defun lyskom-widget-name-validate (widget)
  (let ((value (widget-value widget)))
1264
1265
1266
1267
    (if (and (numberp value)
             (>= value 0))
        nil
      (lyskom-widget-invalid-value widget))))
David Byers's avatar
David Byers committed
1268
1269
1270
1271

(define-widget 'lyskom-name 'default
  "A LysKOM person"
  ':format "%[[*]%] %v"
David Byers's avatar
David Byers committed
1272
  ':help-echo (lyskom-custom-string 'change-this-name)
David Byers's avatar
David Byers committed
1273
  ':value 0
1274
  ':lyskom-predicate '(pers)
David Byers's avatar
David Byers committed
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
  ':action 'lyskom-widget-name-action
  ':value-create 'lyskom-widget-name-value-create
  ':value-delete 'lyskom-widget-value-delete
  ':value-get 'lyskom-widget-value-get
  ':value-to-external 'lyskom-widget-value-to-external
  ':value-to-internal 'lyskom-widget-value-to-internal
  ':match 'lyskom-widget-name-match
  ':validate 'lyskom-widget-name-validate
)

(define-widget 'lyskom-name-list 'editable-list
  "A list of LysKOM commands"
  ':entry-format "%i %d %v"
  ':args '(lyskom-name))


;;;
;;; The Command Widget
;;;

(defun lyskom-widget-command-action (widget &optional event)
  (widget-value-set widget
1297
1298
1299
		    (save-excursion
		      (set-buffer lyskom-buffer)
		      (lyskom-read-extended-command)))
David Byers's avatar
David Byers committed
1300
1301
1302
1303
1304
1305
1306
1307
1308
  (widget-setup))
               
(defun lyskom-widget-command-value-create (widget)
  (let* ((size (widget-get widget ':size))
         (value (widget-get widget ':value))
         (from (point))
         (string (save-excursion
                   (set-buffer lyskom-buffer)
                   (cond ((null value) "")
1309
                         (t (or (lyskom-get-string value 'lyskom-command)
David Byers's avatar
David Byers committed
1310
1311
1312
1313
1314
1315
                                (lyskom-format
                                 (lyskom-custom-string 'unknown-command)
                                 (symbol-name value))))))))
    (if (null size)
        (insert string)
      (insert string)
David Byers's avatar
David Byers committed
1316
1317
      (if (< (lyskom-string-width value) size)
          (insert-char ?\  (- size (lyskom-string-width value)))))
David Byers's avatar
David Byers committed
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329

    (widget-put widget ':value-from (copy-marker from))
    (widget-put widget ':value-to (copy-marker (point)))
    (set-marker-insertion-type (widget-get widget ':value-to) nil)
    (if (null size)
        (insert ?\n)
      (insert ?\ ))))

(defun lyskom-widget-command-match (widget value)
  (symbolp value))

(defun lyskom-widget-command-validate (widget)
1330
1331
1332
1333
  (if (symbolp (widget-value widget))
      nil
    (lyskom-widget-invalid-value widget)))
  
David Byers's avatar
David Byers committed
1334
1335
1336

(define-widget 'lyskom-command 'default
  "A LysKOM command"
David Byers's avatar
David Byers committed
1337
  ':format "%[%t%] %v"
David Byers's avatar
David Byers committed
1338
  ':help-echo (lyskom-custom-string 'select-command)
David Byers's avatar
David Byers committed
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
  ':value 'kom-display-time
  ':action 'lyskom-widget-command-action
  ':value-create 'lyskom-widget-command-value-create
  ':value-delete 'lyskom-widget-value-delete
  ':value-get 'lyskom-widget-value-get
  ':value-to-external 'lyskom-widget-value-to-external
  ':value-to-internal 'lyskom-widget-value-to-internal
  ':match 'lyskom-widget-command-match
  ':validate 'lyskom-widget-command-validate
)

(define-widget 'lyskom-command-list 'editable-list
  "A list of LysKOM commands"
  ':entry-format "%i %d %v"
  ':args '(lyskom-command))


David Byers's avatar
David Byers committed
1356

David Byers's avatar
David Byers committed
1357
1358
1359
1360
1361
;;;
;;; A new String widget
;;;

(defun lyskom-widget-string-action (widget &optional event)
1362
  (let ((tmp (lyskom-read-from-minibuffer 
David Byers's avatar
David Byers committed
1363
              (format "%s: " (widget-get widget ':tag))
David Byers's avatar
David Byers committed
1364
              (widget-value widget))))
David Byers's avatar
David Byers committed
1365
1366
1367
1368
1369
1370
    (widget-value-set widget tmp)
    (widget-setup)))


(define-widget 'lyskom-string 'editable-field
  "A string"
David Byers's avatar
David Byers committed
1371
  ':format "%[%t%] %v"
David Byers's avatar
David Byers committed
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
  ':action 'lyskom-widget-string-action)

;;;
;;; A Number widget
;;;

(defun lyskom-widget-number-action (widget &optional event)
  (let ((min (widget-get widget ':min-value))
        (max (widget-get widget ':max-value)))
    (widget-value-set
     widget
     (if (and min max)
         (lyskom-read-num-range min max
                                (concat (widget-get widget ':tag) ": ")
                                t
                                (widget-value widget))
       (lyskom-read-number (concat (widget-get widget ':tag) ": ")
                           (widget-value widget))))
    (widget-setup)))

(defun lyskom-widget-number-value-to-external (widget value)
  (string-to-int value))

(defun lyskom-widget-number-value-to-internal (widget value)
David Byers's avatar
David Byers committed
1396
  (format "% 4d " value))
David Byers's avatar
David Byers committed
1397
1398

(defun lyskom-widget-number-validate (widget)
1399
1400
1401
  (if (numberp (widget-value widget))
      nil
    (lyskom-widget-invalid-value widget)))
David Byers's avatar
David Byers committed
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413

(defun lyskom-widget-number-match (widget value)
  (if (and (widget-get widget ':max-value)
           (widget-get widget ':min-value))
      (and (numberp value)
           (>= value (widget-get widget ':min-value))
           (<= value (widget-get widget ':max-value)))
    (numberp value)))


(define-widget 'lyskom-number 'editable-field
  "A number"
David Byers's avatar
David Byers committed
1414
  ':format "%[%t%] %v"
David Byers's avatar
David Byers committed
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
  ':action 'lyskom-widget-number-action
  ':value-to-external 'lyskom-widget-number-value-to-external
  ':value-to-internal 'lyskom-widget-number-value-to-internal
  ':match 'lyskom-widget-number-match
  ':validate 'lyskom-widget-number-validate)


;;;
;;; Keyboard macro widget
;;;

(defun lyskom-widget-kbd-macro-match (widget value)
  (or (stringp value)
      (vectorp value)))

(defun lyskom-widget-kbd-macro-validate (widget)
1431
1432
1433
  (if (lyskom-widget-kbd-macro-match widget (widget-value widget))
      nil
    (lyskom-widget-invalid-value widget)))
David Byers's avatar
David Byers committed
1434
1435
1436
1437
1438
1439
1440
1441
1442

(defun lyskom-widget-kbd-macro-value-create (widget)
  (let* ((size (widget-get widget ':size))
         (value (widget-get widget ':value))
         (from (point))
         (string (mapconcat 'single-key-description (append value nil) " ")))
    (if (null size)
        (insert string)
      (insert string)
David Byers's avatar
David Byers committed
1443
1444
      (if (< (lyskom-string-width string) size)
          (insert-char ?\  (- size (lyskom-string-width string)))))
David Byers's avatar
David Byers committed
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476

    (widget-put widget ':value-from (copy-marker from))
    (widget-put widget ':value-to (copy-marker (point)))
    (set-marker-insertion-type (widget-get widget ':value-to) nil)
    (if (null size)
        (insert ?\n)
      (insert ?\ ))))

;;;
;;; This is a truly disgusting piece of work. In Gnu Emacs it's not
;;; possible to simply read a keyboard macro in a recursive command
;;; loop and have the command loop end when macro definition time is
;;; up, so we start a macro definition, make the normal end-kbd-macro
;;; keys just exit the recursive command loop, go recursive and when
;;; the recursive loop is over, any which way, we see if a macro was
;;; defined and reset the keyboard bindings.
;;;

(defun lyskom-widget-end-kbd-macro ()
  (interactive)
  (exit-recursive-edit))

(defun lyskom-widget-kbd-macro-action (widget &optional event)
  (let ((tmp last-kbd-macro)
        (value nil))
    (save-window-excursion
      (unwind-protect
          (progn
            (mapcar (function
                     (lambda (k)
                       (define-key global-map k 'lyskom-widget-end-kbd-macro)))
                    (where-is-internal 'end-kbd-macro))
1477
1478
            (if (widget-get widget ':macro-buffer)
                (pop-to-buffer (widget-get widget ':macro-buffer)))
David Byers's avatar
David Byers committed
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
            (start-kbd-macro nil)
            (recursive-edit))
        (mapcar (function
                 (lambda (k)
                   (define-key global-map k 'end-kbd-macro)))
                (where-is-internal 'lyskom-widget-end-kbd-macro))
        (condition-case e
            (end-kbd-macro)
          (error (setq last-kbd-macro nil)))))
    (setq value
          (prog1 last-kbd-macro
            (setq last-kbd-macro tmp)))
    (if value
        (progn
          (widget-value-set widget value)
          (widget-setup)))))


(define-widget 'lyskom-kbd-macro 'default
  "A Keyboard Macro"
  ':action 'lyskom-widget-kbd-macro-action
  ':value ""
David Byers's avatar
David Byers committed
1501
  ':format "%[%t%] %v"
David Byers's avatar
David Byers committed
1502
1503
1504
1505
1506
1507
1508
  ':validate 'lyskom-widget-kbd-macro-validate
  ':value-create 'lyskom-widget-kbd-macro-value-create
  ':value-delete 'lyskom-widget-value-delete
  ':value-get 'lyskom-widget-value-get
  ':value-to-external 'lyskom-widget-value-to-external
  ':value-to-internal 'lyskom-widget-value-to-internal
  ':match 'lyskom-widget-kbd-macro-match)
1509
1510


1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
;;;
;;; Mark association widget
;;;

(defun lyskom-widget-mark-association-action (widget &optional event)
  (widget-value-set
   widget
   (cons
    (lyskom-read-string (widget-get widget ':mark-key-prompt))
    (lyskom-read-num-range 0
                           255
                           (widget-get widget ':mark-value-prompt)
                           t)))
  (widget-setup))

(defun lyskom-widget-mark-association-match (widget value)
  (and (consp value)
       (let ((s (car value))
             (i (cdr value)))
         (and (stringp s