lyskom-buttons.el 49 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2
;;;;;
3
;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
5
;;;;;
6
;;;;; This file is part of the LysKOM Emacs LISP client.
7
8
9
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
10
;;;;; the Free Software Foundation; either version 2, or (at your option) 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;;; 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. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: lyskom-buttons.el
;;;; Author: David Byers
;;;;
;;;;

34

35
36
37
38
39
40
41
42
43
44
45
46
47
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

(lyskom-external-function glyph-property)
(lyskom-external-function widget-at)
(lyskom-external-function widget-get)
(lyskom-external-function w3-widget-button-click)
(lyskom-external-function w3-popup-menu)
(lyskom-external-function Info-goto-node)
(lyskom-external-function term-char-mode)


David Byers's avatar
X    
David Byers committed
48
49
50
(defun lyskom-menu-selection nil
  "Variable used to work around the handling of menus in XEmacs.")

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(defun lyskom-add-button-action (type text func)
  "Add a new action to the popup menu for a class of objects.
Arguments are TYPE, the type of object to adjust, TEXT the menu text
for the action and FUNC, the function to call when the action is
selected. By default TYPE may be any one of text, conf, pers or url 
although users can add other types.

FUNC must be a function with three arguments, BUFFER, ARGUMENT and
TEXT.  BUFFER is the LysKOM buffer that the command should use, TEXT
is the text of the selected button and ARGUMENT is the data argument
associated with the object. For button type text it is a text
number. For types conf and pers it is the conference number for the
object. For URLs it is the text of the URL (a string) or NIL. For
other (user-defined) types, it is a string.

For more information on button types and arguments, see the
documentation for the variable lyskom-text-buttons."
  (nconc (nth 3 (assq type lyskom-button-actions))
	 (list (cons text func))))

(defun lyskom-set-default-button-action (type func)
  "Set the default action for buttons of the type TYPE to FUNC. 

FUNC must be a valid button action function. For more information
on such functions see the documentation for lyskom-add-button-action."
  (let ((el (assq type lyskom-button-actions)))
    (setcdr (nthcdr 1 el)
	    (cons func (nthcdr 3 el)))))
      


82
(defun kom-previous-link (num)
83
  "Move the cursor to the previous active area in the LysKOM buffer."
84
  (interactive "p")
85
  (lyskom-prev-area num 'lyskom-button))
86
87

(defun kom-next-link (num)
88
  "Move the cursor to the next active area in the LysKOM buffer."
89
  (interactive "p")
90
  (lyskom-next-area num 'lyskom-button))
91
92


93
94
95
96
97
98
99
(defun kom-button-press-or-self-insert-command ()
  "Simulate a mouse button press at point, if there is a button."
  (interactive)
  (if (get-text-property (point) 'lyskom-button)
      (call-interactively 'kom-button-press)
    (call-interactively 'self-insert-command)))

David Byers's avatar
X    
David Byers committed
100
(defun kom-button-press ()
101
  "Simulate a mouse button press at point."
102
  (interactive)
David Byers's avatar
David Byers committed
103
104
105
106
107
108
109
110
  (let* ((type  (get-text-property (point) 'lyskom-button-type))
         (data  (assq type lyskom-button-actions))
         (hint (get-text-property (point) 'lyskom-button-hint))
         (act  (or (and kom-use-button-hints hint)
                   (and data (elt data 2)))))
    (cond ((null data) (lyskom-button-press (point)))
          ((null act) (lyskom-button-menu (point) 'key))
          (t (lyskom-button-press (point))))))
111

112
113
114
115
116
117
118
119
(defun kom-menu-button-press-or-self-insert-command ()
  "Simulate a menu mouse button press at point, if there is a button."
  (interactive)
  (if (get-text-property (point) 'lyskom-button)
      (call-interactively 'kom-menu-button-press)
    (call-interactively 'self-insert-command)))


120
121
122
123
124
(defun kom-menu-button-press ()
  "Simulate a menu mouse button press at point."
  (interactive)
  (lyskom-button-menu (point) 'key))

David Byers's avatar
David Byers committed
125
126
127
128
(defun kom-button-click (event &optional do-default)
  "Execute the default action of the active area under the mouse.
If optional argument do-default is non-nil, call the default binding of
this-command-keys."
129
  (interactive "@e")
David Byers's avatar
David Byers committed
130
131
132
133
134
135
  (let* ((pos (event-point event))
         (glyph (event-glyph event))
         (widget (and pos 
                      (or (and glyph (glyph-property glyph 'widget))
                          (widget-at pos))))
         (parent (and widget (widget-get widget ':parent)))
David Byers's avatar
David Byers committed
136
137
138
         (href (or (and widget (widget-get widget ':href))
                   (and parent (widget-get parent ':href))
                   (and widget (widget-get widget 'href))
David Byers's avatar
David Byers committed
139
                   (and parent (widget-get parent 'href)))))
140
141
    (cond (href (require 'w3)
                (w3-widget-button-click event))
David Byers's avatar
David Byers committed
142
143
144
145
146
147
          ((and do-default
                (or (null pos)
                    (null (get-text-property pos 'lyskom-button-type))))
           (let ((fn (lookup-key global-map (this-command-keys))))
             (when (commandp fn)
               (call-interactively fn))))
David Byers's avatar
David Byers committed
148
149
          (t (lyskom-button-press pos)))))

David Byers's avatar
David Byers committed
150
151
152
153
154
155
(defun kom-button-click-or-yank (event)
  "Execute the default action of the active area under the mouse.
If there is no active area, then do something else."
  (interactive "@e")
  (kom-button-click event t))

David Byers's avatar
X    
David Byers committed
156
(defun kom-popup-menu (event)
157
158
  "Pop up a menu of actions to be taken at the active area under the mouse."
  (interactive "@e")
David Byers's avatar
David Byers committed
159
160
161
162
163
164
  (let* ((pos (event-point event))
         (glyph (event-glyph event))
         (widget (and pos 
                      (or (and glyph (glyph-property glyph 'widget))
                          (widget-at pos))))
         (parent (and widget (widget-get widget ':parent)))
David Byers's avatar
David Byers committed
165
166
167
         (href (or (and widget (widget-get widget ':href))
                   (and parent (widget-get parent ':href))
                   (and widget (widget-get widget 'href))
David Byers's avatar
David Byers committed
168
                   (and parent (widget-get parent 'href)))))
169
170
    (cond (href (require 'w3)
                (w3-popup-menu event))
David Byers's avatar
David Byers committed
171
172
173
          ((and pos (get-text-property pos 'lyskom-button-type))
           (lyskom-button-menu pos event))
          (t (lyskom-background-menu pos event)))))
David Kågedal's avatar
David Kågedal committed
174
  
David Kågedal's avatar
David Kågedal committed
175
176
(defun kom-mouse-null (event)
  "Do nothing."
177
  (interactive "@e")
David Kågedal's avatar
David Kågedal committed
178
  ;; This is here to pervent unwanted events when clicking mouse-3
David Byers's avatar
David Byers committed
179
  (identity 1))
David Kågedal's avatar
David Kågedal committed
180

David Byers's avatar
X    
David Byers committed
181
(defun lyskom-make-button-menu (title entries buf arg text)
182
  "Create a menu keymap from a list of button actions."
David Kågedal's avatar
David Kågedal committed
183
184
185
  ;; Use the command as the event for simplicity.  Note that the menu
  ;; function alters the menu, so we copy the entries to prevent it
  ;; from fiddling with lyskom-button-actions.
David Byers's avatar
David Byers committed
186
187
  (let* ((lyskom-language lyskom-global-language)
         (title (lyskom-maybe-recode-string title 'iso-8859-1 t)))
David Byers's avatar
David Byers committed
188
189
190
    (when (> (length title) 44) (setq title (concat (substring title 0 40)
                                                    " ...")))
    (cond ((string-match "XEmacs" (emacs-version))
David Byers's avatar
David Byers committed
191
           (cons (lyskom-maybe-recode-string title 'iso-8859-1 t)
David Byers's avatar
David Byers committed
192
193
                 (mapcar (function
                          (lambda (entry)
194
                            (vector (lyskom-maybe-recode-string
David Byers's avatar
David Byers committed
195
                                     (lyskom-get-string (car entry)) 'iso-8859-1 t)
David Byers's avatar
David Byers committed
196
197
198
199
200
201
202
203
204
205
206
                                    (list (cdr entry)
                                          buf
                                          (if (listp arg)
                                              (list 'quote arg)
                                            arg)
                                          text)
                                    ':active t)))
                         entries)))
          (t (append (list 'keymap title)
                     (mapcar (function (lambda (entry)
                                         (let ((tmp (copy-tree entry)))
207
                                           (setcar tmp (lyskom-maybe-recode-string
David Byers's avatar
David Byers committed
208
                                                        (lyskom-get-string (car tmp))
David Byers's avatar
David Byers committed
209
                                                        'iso-8859-1 t))
David Byers's avatar
David Byers committed
210
211
212
213
214
215
                                           (cons (` ((, (cdr entry)) 
                                                     (, buf)
                                                     (, arg)
                                                     (, text)))
                                                 tmp))))
                             entries))))))
David Byers's avatar
X    
David Byers committed
216
217


218

David Kågedal's avatar
David Kågedal committed
219
(defun lyskom-button-menu (pos event)
David Byers's avatar
X    
David Byers committed
220
  "Internal function used by kom-popup-menu"
221
222
223
224
225
  (let* ((type  (get-text-property pos 'lyskom-button-type))
         (arg   (get-text-property pos 'lyskom-button-arg))
         (text  (get-text-property pos 'lyskom-button-text))
         (buf   (get-text-property pos 'lyskom-buffer))
         (data  (assq type lyskom-button-actions))
226
227
228
229
230
231
232
         (title (cond 
                 ((get-text-property pos 'lyskom-button-menu-title)
                  (apply 'lyskom-format 
                         (get-text-property pos 'lyskom-button-menu-title)))
                 ((elt data 1)
                  (lyskom-format (lyskom-get-string (elt data 1)) text))
                 (t (lyskom-format (lyskom-get-string 'generic-popup-title) text))))
233
234
235
236
         (actl  (or (and data (elt data 3)) nil)))
    (cond ((null data) (goto-char pos))
          ((null actl) (goto-char pos))
          ((null buf) (goto-char pos))
237
          ((null (get-buffer buf))
238
           (lyskom-message "%s" (lyskom-get-string 'no-such-buffer)))
239
240
241
          (t         
           (if (symbolp title) (setq title (lyskom-get-string title)))
           (set-buffer buf)
242
243
244
245
246

	   ;; There is a simple bug in x-popup-menu which causes menus
	   ;; from simple keymaps to be title-less. A list consisting
	   ;; of a single keymap works better. A patch is submittet to
	   ;; the GNU folks. /davidk
247
248
249
250
251
252
253
254
255
	   (if (eq event 'key)
	       (lyskom-keyboard-menu title actl buf arg text)
	     (let* ((menu (lyskom-make-button-menu title actl
						   buf arg text)))
	       (lyskom-do-popup-menu menu event)))))))


(defun lyskom-keyboard-menu (title entries buf arg text)
  "Do a keyboard menu selection."
David Byers's avatar
David Byers committed
256
257
258
259
260
261
262
263
264
265
  (let* ((prompt nil)
         (maxlen 0)
         (entries (mapcar (lambda (el)
                            (cons (if (stringp (car el)) (car el) (lyskom-get-string (car el)))
                                  (cdr el))) entries))
         (title (if (stringp title) title (lyskom-get-string title)))
         (completion-ignore-case t))
    (lyskom-traverse e entries
      (if (> (lyskom-string-width (car e)) maxlen)
          (setq maxlen (lyskom-string-width (car e)))))
266
267
268
269
270
271
272
273
    (setq prompt (substring title 0
			    (min (lyskom-string-width title)
				 (- (window-width (minibuffer-window))
				    maxlen 3))))

    (let ((choice (lyskom-read-from-menu prompt
                                         (lyskom-maybe-frob-completion-table
                                          entries t))))
David Byers's avatar
David Byers committed
274
      (when choice
275
        (funcall (cdr choice)
David Byers's avatar
David Byers committed
276
277
                 buf arg text)))))

278
       
David Byers's avatar
X    
David Byers committed
279
280

(defun lyskom-button-press (pos)
281
  "Execute the default action of the active area at POS if any."
David Byers's avatar
David Byers committed
282
283
284
285
286
287
288
289
290
  (when pos
    (let* ((type (get-text-property pos 'lyskom-button-type))
           (arg  (get-text-property pos 'lyskom-button-arg))
           (text (get-text-property pos 'lyskom-button-text))
           (buf  (get-text-property pos 'lyskom-buffer))
           (hint (get-text-property pos 'lyskom-button-hint))
           (data (assq type lyskom-button-actions))
           (act  (or (and kom-use-button-hints hint)
                     (and data (elt data 2)))))
291
                 
David Byers's avatar
David Byers committed
292
293
294
295
296
297
298
299
300
      (cond ((null act) (goto-char pos))
            ((null buf) (goto-char pos))
            ((and buf (null (get-buffer buf))) 
             (lyskom-message "%s" (lyskom-get-string 'no-such-buffer)))
            (t (and buf (set-buffer buf))
               (funcall act
                        buf
                        arg
                        text))))))
301
                      
302

David Byers's avatar
David Byers committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
(defun lyskom-fix-pseudo-url (url)
  (save-match-data
    (if (not (string-match lyskom-url-protocol-regexp url))
        (cond ((string-match "^www\\." url) 
               (concat "http://" url))
              ((string-match "^ftp\\." url) 
               (concat "ftp://" url))
              ((string-match "^gopher\\." url) 
               (concat "gopher://" url))
              ((string-match "^wais\\." url)
               (concat "wais://" url))
              (t (concat "http://" url)))
      url)))

317

318
(defun lyskom-button-transform-text (text)
319
320
321
322
  "Add text properties to the string TEXT according to the definition of
lyskom-text-buttons. Returns the modified string."
  (let ((blist lyskom-text-buttons)
        (start 0)
323
        (el nil))
324
325
    (while blist
      (setq el (car blist))
David Kågedal's avatar
David Kågedal committed
326
      (setq start 0)
327
      (while (string-match (elt el 0) text start)
328
329
330
        (add-text-properties 
         (match-beginning (or (elt el 2) 0))
         (match-end (or (elt el 2) 0))
331
332
         (cond ((and (eq (elt el 1) 'text)
                     (not lyskom-transforming-external-text))
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
                (lyskom-generate-button 'text
                                        (lyskom-button-get-arg el text)
                                        (lyskom-button-get-text el text)
                                        (lyskom-button-get-face el)))
               ((eq (elt el 1) 'conf)
                (lyskom-generate-button 'conf
                                        (lyskom-button-get-arg el text)
                                        (lyskom-button-get-text el text)
                                        (lyskom-button-get-face el)))
               ((eq (elt el 1) 'pers)
                (lyskom-generate-button 'pers
                                        (lyskom-button-get-arg el text)
                                        (lyskom-button-get-text el text)
                                        (lyskom-button-get-face el)))
               ((eq (elt el 1) 'url)
                (lyskom-generate-button 'url
                                        nil
                                        (lyskom-button-get-text el text)
                                        (lyskom-button-get-face el)))
David Byers's avatar
David Byers committed
352
353
354
355
356
357
358
359
360

               ((eq (elt el 1) 'pseudo-url)
                (let ((url (lyskom-fix-pseudo-url
                            (lyskom-button-get-text el text))))
                  (lyskom-generate-button 'url
                                          nil
                                          url
                                          (lyskom-button-get-face el))))

361
362
363
364
365
 	       ((eq (elt el 1) 'info-node)
 		(lyskom-generate-button 'info-node
 					(lyskom-button-get-arg el text)
 					(lyskom-button-get-text el text)
 					(lyskom-button-get-face el)))
366
367
368
369
370
371

 	       ((eq (elt el 1) 'bugzilla)
 		(lyskom-generate-button 'bugzilla
 					(lyskom-button-get-arg el text)
 					(lyskom-button-get-text el text)
 					(lyskom-button-get-face el)))
372
               
373
374
375
376
377
               ((eq (elt el 1) 'email)
                (lyskom-generate-button 'email
                                        nil
                                        (lyskom-button-get-text el text)
                                        (lyskom-button-get-face el)))
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
               (t nil))
         text)
        (setq start (match-end 0)))
      (setq blist (cdr blist))))
  text)

(defun lyskom-button-get-arg (el text)
  "Get the button argument for button type EL from TEXT according to
the current match-data."
  (let ((no (or (elt el 3) 0)))
    (substring text (match-beginning no) (match-end no))))

(defun lyskom-button-get-text (el text)
  "Get the button text for button type EL from TEXT according to
the current match-data."
  (let ((no (or (elt el 2) 0)))
    (substring text (match-beginning no) (match-end no))))

(defun lyskom-button-get-face (el)
  "Get the button face for button type EL from TEXT according to
the current match-data."
David Byers's avatar
David Byers committed
399
  (elt el 4))
400

401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
(defun lyskom-get-button-hint (hints)
  "Get the hint to be used right now (if any) from HINTS"
  (let ((result nil)
        (hint nil))
    (while (and hints (null result))
      (setq hint (car hints))
      (setq hints (cdr hints))
      (cond ((null (car hint)) 
             (if (and (eq lyskom-current-function
                          (elt hint 1))
                      (or (null (elt hint 2))
                          (eq lyskom-current-function-phase
                              (elt hint 2))))
                 (setq result (elt hint 3))))
David Byers's avatar
X    
David Byers committed
416
417
418
419
420
421
422
423
424
            ((listp (car hint))
             (if (and lyskom-executing-command
                      (memq lyskom-current-command (car hint)))
                 (setq result (cdr hint))))
            ((symbolp (car hint))
             (if (and lyskom-executing-command
                      lyskom-current-command
                      (eq lyskom-current-command (car hint)))
                 (setq result (cdr hint))))))
425
426
427
    result))


428
	
429
430
431
432
433
434
435
436
437
(defun lyskom-generate-button (type arg &optional text face menu-title
				    subtle)
  "Generate the properties for a button of type TYPE with argument
ARG. Optional argument TEXT is the button text to be saved as a
property and FACE is the default text face for the button. Optional
argument MENU-TITLE defines the title for the popup menu. See
lyskom-default-button for more information. Optional argument SUBTLE
means don't set the lyskom-button property if non-nil. that means
kom-next- and -previous-link won't notice the button"
438
439
  (setq lyskom-dummy-variable-to-fool-the-byte-compiler
        (car menu-title))		; produce error if menu-title not cons
440
441
442
443
444
445
446
447
448
449
450
  (let* ((persno (cond ((boundp 'lyskom-pers-no) lyskom-pers-no)
                       ((and (boundp 'lyskom-buffer) lyskom-buffer)
                        (save-excursion
                          (set-buffer lyskom-buffer)
                          lyskom-pers-no))
                       (t -1)))
         (numarg (cond ((numberp arg) arg)
                       ((stringp arg) (string-to-number arg))
                       (t nil)))
         (data (assq type lyskom-button-actions))
         (hints (and data (elt data 4)))
451
         (the-hint (lyskom-get-button-hint hints))
452
         (props 
453
          (cond ((and (memq type '(conf pers))
454
455
456
                      numarg)
                 (list 'face 
                       (or face
David Byers's avatar
David Byers committed
457
458
                           (cond ((eq persno numarg) 'kom-me-face)
                                 ((memq numarg kom-friends) 'kom-friends-face)
459
                                 ((memq numarg kom-morons) 'kom-morons-face)
David Byers's avatar
David Byers committed
460
                                 (t 'kom-active-face)))
461
462
463
464
                       'mouse-face 'kom-highlight-face
                       'lyskom-button-text text
                       'lyskom-button-type type
                       'lyskom-button-arg numarg
David Byers's avatar
David Byers committed
465
                       'lyskom-button-menu-title menu-title
466
467
                       'lyskom-buffer lyskom-buffer))
                ((and (eq type 'text) numarg)
David Byers's avatar
David Byers committed
468
                 (list 'face (or face 'kom-text-no-face)
469
470
471
472
                       'mouse-face 'kom-highlight-face
                       'lyskom-button-text text
                       'lyskom-button-type type
                       'lyskom-button-arg numarg
David Byers's avatar
David Byers committed
473
                       'lyskom-button-menu-title menu-title
474
475
476
477
478
479
                       'lyskom-buffer lyskom-buffer))
                ((eq type 'url)
                 (list 'face (or face 'kom-active-face)
                       'mouse-face 'kom-highlight-face
                       'lyskom-button-text text
                       'lyskom-button-type type
480
                       'lyskom-button-arg arg
David Byers's avatar
David Byers committed
481
                       'lyskom-button-menu-title menu-title
482
                       'lyskom-buffer lyskom-buffer))
483
484
485
486
487
488
                (t
		 (list 'face (or face 'kom-active-face)
		       'mouse-face 'kom-highlight-face
		       'lyskom-button-text text
		       'lyskom-button-type type
		       'lyskom-button-arg arg
David Byers's avatar
David Byers committed
489
                       'lyskom-button-menu-title menu-title
490
		       'lyskom-buffer lyskom-buffer)))))
491

492
    (append (list 'rear-nonsticky t)
493
	    (if (not subtle) (list 'lyskom-button t))
494
495
496
497
	    (if the-hint
		(cons 'lyskom-button-hint
		      (cons the-hint props))
	      props))))
498
499
500
      
        
           
501

David Byers's avatar
David Byers committed
502
(defun lyskom-default-button (type arg &optional menu-title)
503
504
  "Generate a button of type TYPE from data in ARG. ARG can be almost any
type of data and is converted to the proper argument type for buttons of
505
type TYPE before being sent to lyskom-generate-button. Optional argument
David Byers's avatar
David Byers committed
506
507
508
MENU-TITLE is a list consisting of a format string or symbol and arguments
for the format string. The arguments are not when the menu is popped
up."
David Kågedal's avatar
David Kågedal committed
509
  (and kom-text-properties
510
       (let (xarg text face subtle)
David Kågedal's avatar
David Kågedal committed
511
512
513
514
515
516
	 (cond ((eq type 'conf)
		(cond ((lyskom-conf-stat-p arg)
		       (if (conf-type->letterbox (conf-stat->conf-type arg))
			   (setq type 'pers))
		       (setq xarg (conf-stat->conf-no arg)
			     text (conf-stat->name arg)))
517
518
519
520
521
                      ((lyskom-uconf-stat-p arg)
		       (if (conf-type->letterbox (uconf-stat->conf-type arg))
			   (setq type 'pers))
		       (setq xarg (uconf-stat->conf-no arg)
			     text (uconf-stat->name arg)))
522
523
524
525
526
527
528
529
530
531
		      ((numberp arg)
                       (if (setq xarg (cache-get-conf-stat arg))
                           (progn
                             (if (conf-type->letterbox
                                  (conf-stat->conf-type xarg))
                                 (setq type 'pers))
                             (setq text (conf-stat->name xarg))
                             (setq xarg (conf-stat->conf-no xarg)))
                         (setq text ""
                               xarg arg)))
David Kågedal's avatar
David Kågedal committed
532
533
534
535
536
		      (t (setq text "" xarg 0))))
	       ((eq type 'pers)
		(cond ((lyskom-conf-stat-p arg)
		       (setq xarg (conf-stat->conf-no arg)
			     text (conf-stat->name arg)))
537
538
                      ((lyskom-uconf-stat-p arg)
		       (setq xarg (uconf-stat->conf-no arg)
539
540
			     text (uconf-stat->name arg)))
		      ((lyskom-pers-stat-p arg)
David Kågedal's avatar
David Kågedal committed
541
		       (setq xarg (pers-stat->pers-no arg)
542
543
544
545
546
547
548
549
550
551
552
			     text 
                             (or (conf-stat->name
                                  (cache-get-conf-stat
                                   (pers-stat->pers-no arg)))
                                 "")))
		      ((numberp arg) 
                       (setq text
                             (or (conf-stat->name
                                  (cache-get-conf-stat arg))
                                 "")
                             xarg arg))
David Kågedal's avatar
David Kågedal committed
553
554
555
556
557
558
559
560
561
562
563
		      (t (setq text "" xarg 0))))
	       ((eq type 'text)
		(cond ((stringp arg) (setq xarg (string-to-number arg)
					   text arg))
		      ((numberp arg) (setq xarg arg
					   text (number-to-string arg)))
		      ((lyskom-text-stat-p arg)
		       (setq xarg (text-stat->text-no arg)
			     text (number-to-string (text-stat->text-no arg))))
		      (t (setq xarg 0 text ""))))
	       ((eq type 'url)
564
                (setq face 'kom-url-face)
David Kågedal's avatar
David Kågedal committed
565
566
		(cond ((stringp arg) (setq xarg nil text arg))
		      (t (setq xarg nil text ""))))
567
568
569
570
571
572

               ((eq type 'email)
                (setq face 'kom-url-face)
                (cond ((stringp arg) (setq xarg nil text arg))
                      (t (setq xarg nil text ""))))

573
	       ((eq type 'timestamp)
574
575
		(setq face 'kom-text-face
		      subtle t)
576
		(cond ((null arg) (setq xarg (current-time)
577
578
					;text (format-time-string "%Y-%m-%d %H:%M")
					))
579
		      (t (setq xarg arg
580
581
582
583
			       ;text (format-time-string "%Y-%m-%d %H:%M" arg)
			       ))))
	       (t (setq xarg arg
			text "")))
584
	 (lyskom-generate-button type xarg text face menu-title subtle))))
585
586
587
588
                  

           

589
590
591
592
593

;;;========================================
;;; Button actions
;;;

David Byers's avatar
X    
David Byers committed
594

595
596
597
598
599
(defun lyskom-button-view-text (buf arg text)
  "In the LysKOM buffer BUF, view the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
600
           (goto-char (point-max))
601
           (kom-view arg))))
David Byers's avatar
David Byers committed
602

David Byers's avatar
David Byers committed
603
604
605
606
607
608
(defun lyskom-button-copy-text-no (but arg text)
  "In the LysKOM buffer BUF, ignore ARG and copy TEXT to the kill ring.
This is a LysKOM button action."
  (kill-new text))


David Byers's avatar
David Byers committed
609
610
611
612
613
(defun lyskom-button-review-noconversion (buf arg text)
  "In the LysKOM buffer BUF, view the text ARG without conversion. 
Last argument TEXT is ignored. This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
614
           (goto-char (point-max))
David Byers's avatar
David Byers committed
615
           (kom-review-noconversion arg))))
David Byers's avatar
David Byers committed
616

617
(defun lyskom-button-find-root-review (buf arg text)
David Byers's avatar
David Byers committed
618
619
620
621
  "In the LysKOM buffer BUF, view the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
	(t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
622
           (goto-char (point-max))
623
	   (kom-find-root-review arg))))
David Byers's avatar
David Byers committed
624
625
626
627
628
629

(defun lyskom-button-find-root (buf arg text)
  "In the LysKOM buffer BUF, view the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
	(t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
630
           (goto-char (point-max))
David Byers's avatar
David Byers committed
631
	   (kom-find-root arg))))
632

633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
(defun lyskom-button-comment-text (buf arg text)
  "In the LysKOM buffer BUF, comment the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-write-comment arg))))

(defun lyskom-button-private-comment-text (buf arg text)
  "In the LysKOM buffer BUF, write a private comment the text ARG. 
Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-private-answer arg))))

(defun lyskom-button-mark-text (buf arg text)
  "In the LysKOM buffer BUF, mark the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (unwind-protect
               (progn
                 (pop-to-buffer buf)
                 (lyskom-start-of-command 'kom-mark-text)
656
                 (lyskom-mark-text arg))
657
658
659
660
661
662
663
664
665
666
             (lyskom-end-of-command)))))

(defun lyskom-button-unmark-text (buf arg text)
  "In the LysKOM buffer BUF, unmark the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (unwind-protect
               (progn
                 (pop-to-buffer buf)
                 (lyskom-start-of-command 'kom-unmark-text)
667
                 (lyskom-unmark-text arg))
668
             (lyskom-end-of-command)))))
669
670
671
672
673
674
675
676

(defun lyskom-button-save-text (buf arg text)
  "In the LysKOM buffer BUF, save the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (unwind-protect
               (progn (pop-to-buffer buf)
                      (kom-save-text nil (list arg)))))))
677
678
679
680
681
682
683
684

(defun lyskom-button-save-text-body (buf arg text)
  "In the LysKOM buffer BUF, save the text ARG. Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (unwind-protect
               (progn (pop-to-buffer buf)
                      (kom-save-text-body arg))))))
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

(defun lyskom-button-review-comments (buf arg text)
  "In the LysKOM buffer BUF, review comments to the the text ARG.
Last argument TEXT is ignored. This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-review-comments arg))))

(defun lyskom-button-review-tree (buf arg text)
  "In the LysKOM buffer BUF, recursively review comments to the the text ARG.
Last argument TEXT is ignored. This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-review-tree arg))))

(defun lyskom-button-write-footnote (buf arg text)
  "In the LysKOM buffer BUF, write a footnote to the the text ARG.
Last argument TEXT is ignored. This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-write-footnote arg))))

(defun lyskom-button-fast-reply (buf arg text)
  "In the LysKOM buffer BUF, make a remark to the the text ARG.
Last argument TEXT is ignored. This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-fast-reply arg))))

714

715
716
717
718
719
720
(defun lyskom-button-view-conf-presentation (buf arg text)
  "In the LysKOM buffer BUF, view the presentation of ARG. 
Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
721
           (goto-char (point-max))
722
723
724
725
726
727
728
729
           (kom-review-presentation arg))))

(defun lyskom-button-view-conf-status (buf arg text)
  "In the LysKOM buffer BUF, view the status of conference ARG. Last argument
TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
730
           (goto-char (point-max))
731
732
733
734
735
736
737
738
           (kom-status-conf arg))))

(defun lyskom-button-goto-conf (buf arg text)
  "In the LysKOM buffer BUF, go to the conference ARG. Last argument TEXT is
ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
739
           (goto-char (point-max))
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
           (kom-go-to-conf arg))))

(defun lyskom-button-add-self (buf arg text)
  "In the LysKOM buffer buf, add self to conference ARG."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-add-self arg))))

(defun lyskom-button-sub-self (buf arg text)
  "In the LysKOM buffer buf, sub self from conference ARG."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-sub-self arg))))

(defun lyskom-button-view-pers-presentation (buf arg text)
  "In the LysKOM buffer BUF, view the presentation of person ARG. 
Last argument TEXT is ignored.
This is a LysKOM button action."
  (lyskom-button-view-conf-presentation buf arg text))

(defun lyskom-button-view-pers-status (buf arg text)
  "In the LysKOM buffer BUF, view the status of person ARG. 
Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
David Byers's avatar
David Byers committed
766
           (goto-char (point-max))
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
           (kom-status-person arg))))

(defun lyskom-button-mail (buf arg text)
  "In the LysKOM buffer BUF, send mail to the conference ARG.
Last argument TEXT is ignored.
This is a LysKOM button action."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-send-letter arg))))

(defun lyskom-button-send-message (buf arg text)
  "In the LysKOM buffer BUF, send a personal message to person ARG."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-send-message arg nil))))

783
784
785
786
787
788
(defun lyskom-button-view-session-status (buf arg text)
  "In the LysKOM buffer BUF, show session status for person ARG."
  (cond ((not (integerp arg)) nil)
        (t (pop-to-buffer buf)
           (kom-status-session (lyskom-session-from-conf arg)))))

789
790
791
792
793
(defun lyskom-button-copy-email (but arg text)
  "In the LysKOM buffer BUF, ignore ARG and copy TEXT to the kill ring.
This is a LysKOM button action."
  (kill-new text))

794
(lyskom-external-function compose-mail)
795
796
797
(defun lyskom-button-open-email (but arg text)
  "In the LysKOM buffer BUF, ignore ARG and open TEXT as an e-mail address.
This is a LysKOM button action."
798
799
800
  (if (fboundp 'compose-mail)
      (compose-mail text)
    (mail nil text)))
801

802
803
804
805
806
807
808
809
810
811
812
813
814
815
(defun lyskom-button-show-bugzilla-bug (buf arg text)
  (let ((case-fold-search t)
        (url ""))
    (unless (string-match "^http" kom-my-bugzilla)
      (setq url "http://"))
    (setq url (concat url kom-my-bugzilla))
    (unless (string-match "/$" url)
      (setq url (concat url "/")))
    (setq url (concat url "show_bug.cgi?id=" arg))
    (lyskom-button-open-url buf
                            nil
                            url)))


816
817
818
(defun lyskom-button-copy-url (but arg text)
  "In the LysKOM buffer BUF, ignore ARG and copy TEXT to the kill ring.
This is a LysKOM button action."
David Byers's avatar
X    
David Byers committed
819
  (kill-new (replace-in-string text "\\s-+" "")))
820
821


David Byers's avatar
David Byers committed
822
823
824
825
826
827
828
(defun lyskom-transform-url (url)
  (let ((rules kom-url-transformation-rules))
    (while rules
      (setq url (replace-in-string url (car (car rules)) (cdr (car rules)))
            rules (cdr rules))))
  url)

829
830
831
(defun lyskom-button-open-url (buf arg text)
  "In the LysKOM buffer BUF, ignore ARG and open TEXT as an URL.
This is a LysKOM button action."
David Byers's avatar
David Byers committed
832
  (let* ((url (lyskom-fix-pseudo-url (replace-in-string text "\\s-+" "")))
833
834
         protocol
         url-manager)
David Byers's avatar
David Byers committed
835
    (setq url (lyskom-transform-url url))
David Byers's avatar
David Byers committed
836
837
    (string-match lyskom-url-protocol-regexp url)
    (setq protocol (match-string 1 url))
838
839
840
841
    (setq url-manager (lyskom-get-url-manager protocol))
    (if (null url-manager)
        (lyskom-error "Can't find URL viewer"))
    (funcall (elt url-manager 3) url url-manager)))
842

843
844
845
846
847
 
 
;;;
;;;	Info node button
;;;
848

849
850
851
852
853
854
855
856
857
858
(defun lyskom-button-goto-info-node (buf arg text)
  "In the LysKOM buffer BUF, open ARG as an Info node, and ignore TEXT.
This is a LysKOM button action."
  (when (not (fboundp 'Info-goto-node))
    (autoload 'Info-goto-node "info"
      "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME."
      t))
  (setq arg (replace-in-string arg "\n" " " t))
  (setq arg (replace-in-string arg " +" " " t))
  (Info-goto-node arg))
859
860
861
862
863
864
865
866
867
868

;;;
;;;	Timestamp button
;;;

(defun lyskom-button-copy-timestamp (but arg text)
  "In the LysKOM buffer BUF, ignore TEXT and copy ARG to the kill ring
after formating it as time. This is a LysKOM button action."
  (kill-new (format-time-string "%Y-%m-%d %H:%M" arg)))

869
870
871
872
873
874

;;;
;;;	LysKOM URL Management
;;;

(defun lyskom-get-url-manager (protocol)
875
  "Get the URL manager for PROTOCOL (a string). Returns a function."
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
  (let ((managers kom-url-managers)
	(preferences kom-url-viewer-preferences)
	(result nil))
    (while (and preferences (not result))
      (setq managers kom-url-managers)
      (while (and managers (not result))
	(if (and (string-match (car (car managers))
			       (car preferences))
		 (string-match (car (cdr (car managers)))
			       protocol))
	    (setq result (car managers)))
	(setq managers (cdr managers)))
      (setq preferences (cdr preferences)))
    result))



(defun lyskom-url-manager-starting (manager)
894
  "Tell the user that the URL manager MANAGER is starting."
895
  (lyskom-message "%s" (lyskom-format (lyskom-get-string 'starting-program)
896
897
898
				 (elt manager 2))))


David Byers's avatar
David Byers committed
899
900
(eval-when-compile (defvar browse-url-browser-function nil))

David Byers's avatar
X    
David Byers committed
901
902
903
904
(defun lyskom-view-url-browse-url (url manager)
  (require 'browse-url)
  (funcall browse-url-browser-function url))

905
(defun lyskom-view-url-w3 (url manager)
906
  "View the URL URL using W3. Second argument MANAGER is ignored."
907
908
909
  (w3-fetch url))

(defun lyskom-view-url-dired (url manager)
910
  "View the URL URL using dired. Second argument MANAGER is ignored."
911
912
913
914
915
916
917
918
919
920
  (if (not (and (string-match
		 "\\(file\\|ftp\\)://\\([^/:]*\\)\\(:[0-9]*\\)?\\(/\\|$\\)"
		 url)
		(match-beginning 0)
		(match-beginning 1)
		(match-beginning 2)))
      (lyskom-error "Bad URL"))
  (let ((host (substring url (match-beginning 2) (match-end 2)))
	(path (substring url (match-end 0)))
	(user "anonymous"))
David Byers's avatar
David Byers committed
921
922
    (if  (string-match ";type=.$" path)
        (setq path (substring path 0 (match-beginning 0))))
923
924
925
926
927
    (if (and (string-match "\\([^@]*\\)@" host)
	     (match-beginning 1))
	(progn
	  (setq user (substring host (match-beginning 1) (match-end 1)))
	  (setq host (substring host (match-end 0)))))
David Byers's avatar
David Byers committed
928
929
930
931
    (cond ((string= host "localhost") (find-file path))
          (t (find-file (concat "/" user "@" host ":/" path))))
    ;;    (message "%s  %s  %s" user host path)
    ))
932
933


934

935
(defun lyskom-view-url-telnet (url manager)
936
  "View the URL URL using telnet. Second argument MANAGER is ignored."
937
  (if (not (and (string-match 
David Byers's avatar
David Byers committed
938
                 "telnet://\\([^@]*@\\)?\\([^/:]*\\)\\(:[0-9]*\\)?"
939
940
941
942
943
944
945
946
		 url)
		(match-beginning 0)
		(match-beginning 2)))
      (lyskom-error "Bad URL"))
  (let ((host (substring url (match-beginning 2) (match-end 2)))
	(port (if (match-beginning 3)
		  (substring url (1+ (match-beginning 3)) (match-end 3))
		""))
David Byers's avatar
David Byers committed
947
948
949
	(user (if (match-beginning 1)
                  (substring url (match-beginning 1) (1- (match-end 1)))
                nil))
950
951
        ;; (password nil)
	)
David Byers's avatar
David Byers committed
952
953
    (if (and user
             (string-match "^\\([^:]*\\):\\(.*\\)" user))
954
955
956
957
958
959
960
961
        (progn
	  ;; (setq password (substring user
	  ;; 			    (match-beginning 2)
	  ;; 			    (match-end 2)))
	  (setq user (substring user 
				(match-beginning 1)
				(match-end 1)))))
    
David Byers's avatar
David Byers committed
962
    (telnet (concat host " " port))
963
964
965
966
967
    ;;    (message "u:%s  p:%s  h:%s  #:%s" 
    ;;             (or user "<u>")
    ;;             (or password "<p>")
    ;;             (or host "<h>")
    ;;             (or port "<#>"))
David Byers's avatar
David Byers committed
968
969

    ))
970

971

972
(defun lyskom-view-url-mailmode (url manager)
973
  "View the URL URL using mail in Emacs. The second argument MANAGER is ignored."
974
975
976
977
978
979
  (if (not (and (string-match "mailto:\\([^@]+@.*\\)$" url)
		(match-beginning 1)))
      (lyskom-error "Bad URL"))
  (mail nil (substring url (match-beginning 1) (match-end 1))))


980
981
982
(defun lyskom-view-url-windows (url manager)
  "View the URL URL in Microsoft Windows. MANGER is the URL manager.
Fall back on Netscape if not running in Microsoft Windows."
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
  (cond
   ((memq window-system '(win32 mswindows w32))
    (cond
     ((and (boundp 'kom-windows-browser-command)
           (and (not (null kom-windows-browser-command))
                (not (eq (length kom-windows-browser-command) 0))))
      ;; Explicit given file name of browser, so complain to user if
      ;; the value is bad.
      (if (not (file-executable-p kom-windows-browser-command))
          (error (concat "Not an executable file: %s;"
                         " kom-windows-browser-command has a bad value")
                 kom-windows-browser-command))

      (condition-case nil
          (progn
David Byers's avatar
David Byers committed
998
            (lyskom-url-manager-starting manager)
999
1000
1001
            (start-process "Browser"
                           nil
                           kom-windows-browser-command
David Byers's avatar
David Byers committed
1002
                           url))
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
        (error (error (concat "Failed starting browser using"
                              " kom-windows-browser-command"
                              " (%s)")
                      kom-windows-browser-command))))
     ((not (memq 'w32-shell-execute lyskom-compatibility-definitions))
      (w32-shell-execute "open" url)
      (lyskom-url-manager-starting manager))
      ;;(lyskom-message "Webb via [%s \"%s\" \"%s\"] ..."
      ;;                "w32-shell-execute" "open" url))
     (t (let ((programs (list
                         "start"
                         "explorer"
                         (concat "C:\\Program Files\\Netscape"
                           "\\Communicator\\Program\\netscape.exe")
                         (concat "C:\\Program Files\\Netscape"
                                 "\\Navigator\\Program\\netscape.exe"))))
          (while programs
            (condition-case nil
                (progn
David Byers's avatar
David Byers committed
1022
                  (lyskom-url-manager-starting manager)
1023
1024
1025
1026
1027
1028
1029
                  (start-process (car programs)
                                 nil
                                 (car programs)
                                 url)
                  (setq programs nil))
              (error (setq programs (cdr programs)))))))))
   (t (lyskom-view-url-netscape url manager))))
1030
1031


1032
(defun lyskom-view-url-netscape (url manager)
1033
1034
1035
1036
1037
  "View the URL URL using Netscape Navigator. The second argument
MANAGER is the URL manager that started Netscape.

This function attempts to load the URL in a running Netscape, but failing
that, starts a new one."
David Byers's avatar
David Byers committed
1038
  (setq url (replace-in-string url "," "%2C"))
David Byers's avatar
David Byers committed
1039
1040
  (setq url (replace-in-string url "(" "%28"))
  (setq url (replace-in-string url ")" "%29"))
1041
  (let* ((url-string (if (memq window-system '(win32 mswindows w32))
1042
1043
1044
1045
1046
                         (list url)
                       (list "-remote"
                             (format "openUrl(%s)" url))))
         
         (proc (apply 'start-process "netscape"
David Byers's avatar
David Byers committed
1047
1048
1049
1050
1051
1052
                      nil
                      (if (listp kom-netscape-command)
                          (car kom-netscape-command)
                        kom-netscape-command)
                      (if (listp kom-netscape-command)
                          (append (cdr kom-netscape-command)
1053
1054
                                  url-string)
                        url-string)))
1055
1056
1057
1058
         (status 'run)
         (exit nil))
    (lyskom-url-manager-starting manager)
    (while (eq status 'run)
David Byers's avatar
David Byers committed
1059
      (lyskom-accept-process-output)
1060
1061
1062
1063
      (setq status (process-status proc)))
    (setq exit (process-exit-status proc))
    (cond ((and (eq status 'exit) 
                (eq exit 1))
David Byers's avatar
David Byers committed
1064
           (apply 'start-process "netscape"
1065
                          nil
David Byers's avatar
David Byers committed
1066
1067
1068
1069
1070
1071
1072
                          (if (listp kom-netscape-command)
                              (car kom-netscape-command)
                            kom-netscape-command)
                          (if (listp kom-netscape-command)
                              (append (cdr kom-netscape-command)
                                      (list url))
                            (list url))))
1073
          (t nil))))
1074
1075
1076


(defun lyskom-view-url-mosaic (url manager)
1077
1078
  "View the URL URL using NCSA Mosaic. The attempts to open the URL in an
existing Mosaic process. Failing that, it starts a new Mosaic."
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
  (let ((pid -1)
        tempbuffer
        (filename "/tmp/Mosaic."))
    (if (file-exists-p (expand-file-name "~/.mosaicpid"))
        (save-excursion
          (set-buffer 
           (setq tempbuffer (get-buffer-create " *kom*-mosaicpid")))
          (insert-file-contents (expand-file-name "~/.mosaicpid"))
          (setq pid (read tempbuffer))
          (delete-region (point-min) (point-max))
          (insert "newwin\n")
          (insert url)
          (insert "\n")
          (setq filename (concat filename (number-to-string pid)))
          (write-region (point-min) (point-max) filename nil 'x)
          (kill-buffer tempbuffer)
          (if (= -1 (signal-process pid 30))
David Byers's avatar
David Byers committed
1096
1097
1098
1099
1100
1101
1102
1103
1104
              (apply 'start-process "mosaic"
                     (current-buffer)
                     (if (listp kom-mosaic-command)
                         (car kom-mosaic-command)
                       kom-mosaic-command )
                     (if (listp kom-mosaic-command)
                         (append (cdr kom-mosaic-command)
                                 (list url))
                       (list url)))
1105
1106
	    (lyskom-url-manager-starting manager)))
      (save-excursion
David Byers's avatar
David Byers committed
1107
1108
1109
1110
1111
1112
1113
1114
1115
        (apply 'start-process "mosaic"
               (current-buffer)
               (if (listp kom-mosaic-command)
                   (car kom-mosaic-command)
                 kom-mosaic-command )
               (if (listp kom-mosaic-command)
                   (append (cdr kom-mosaic-command)
                           (list url))
                 (list url)))
1116
1117
	(lyskom-url-manager-starting manager)))))

Ulrik Haugen's avatar
Ulrik Haugen committed
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
(defun lyskom-view-url-galeon (url manager)
  "View the URL URL using Galeon. The second argument MANAGER is the URL
manager that started Galeon.

This function attempts to load the URL in a running Galeon, but failing
that, starts a new one."
  (setq url (replace-in-string url "," "%2C"))
  (setq url (replace-in-string url "(" "%28"))
  (setq url (replace-in-string url ")" "%29"))
  (let* ((url-string (if (memq window-system '(win32 mswindows w32))
                         (list url)
                       (list "-n"
David Byers's avatar
David Byers committed
1130
                             (format "%s" url)))))
Ulrik Haugen's avatar
Ulrik Haugen committed
1131
    (lyskom-url-manager-starting manager)
David Byers's avatar
David Byers committed
1132
1133
1134
1135
1136
1137
1138
1139
1140
    (apply 'start-process "galeon"
           nil
           (if (listp kom-galeon-command)
               (car kom-galeon-command)
             kom-galeon-command)
           (if (listp kom-galeon-command)
               (append (cdr kom-galeon-command)
                       url-string)
             url-string))))
Ulrik Haugen's avatar
Ulrik Haugen committed
1141

Peter Liljenberg's avatar
Peter Liljenberg committed
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
1175
1176
1177
1178
1179
1180
1181
1182
;; Added by Peter Liljenberg
(defun lyskom-view-url-lynx (url manager)
  "View the URL URL using Lynx.
Lynx will be run either in an xterm or in Emacs terminal mode,
depending on the value of `kom-lynx-terminal'."
  (cond
   ((eq kom-lynx-terminal 'xterm)
    (apply 'start-process
	   "lynx"
	   nil
	   (car kom-lynx-xterm-command)
	   (append (cdr kom-lynx-xterm-command) (list url)))
    (lyskom-url-manager-starting manager))

   ((eq kom-lynx-terminal 'terminal)
    (let* ((lbuf (get-buffer "*Lynx*"))
	   (lproc (and lbuf (get-buffer-process lbuf))))
      (if lproc
	  ;; Tell existing Lynx to fetch URL
	  (process-send-string lproc (concat "g" url "\n"))

	;; Create a new Lynx
	(switch-to-buffer
	 (apply 'make-term "Lynx"
		(if (listp kom-lynx-terminal-command)
		    (car kom-lynx-terminal-command)
		  kom-lynx-terminal-command)
		nil
		(if (listp kom-lynx-terminal-command)
		    (append (cdr kom-lynx-terminal-command) (list url))
		  (list url))))
	(delete-other-windows)
	(term-char-mode)
	(set-process-sentinel
	 (get-buffer-process (current-buffer))
	 (function (lambda (proc str)
		     (kill-buffer (process-buffer proc))))))
      (lyskom-url-manager-starting manager)))

   (t (lyskom-error "Bad Lynx terminal: %s" kom-lynx-terminal))
   ))
1183

1184
1185
1186
1187
1188

;;;
;;;     aux-item buttons
;;;

David Byers's avatar
David Byers committed
1189
(defun lyskom-button-delete-aux (buf arg text)
1190
  (let ((aux nil))
1191
    (cond ((lyskom-aux-item-p arg))
1192
1193
1194
1195
1196
1197
          ((listp arg)
           (let ((items (cond ((eq 'text (car arg))
                               (text-stat->aux-items 
                                (blocking-do 'get-text-stat (elt arg 1))))
                              ((eq 'conf (car arg))
                               (conf-stat->aux-items 
David Byers's avatar
David Byers committed
1198
                                (blocking-do 'get-conf-stat (elt arg 1))))
1199
1200
1201
                              ((eq 'server (car arg))
                               (server-info->aux-item-list
                                (blocking-do 'get-server-info)))
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
                              (t nil))))
             (while items
               (when (eq (aux-item->aux-no (car items)) (elt arg 2))
                 (setq aux (car items))
                 (setq items nil))
               (setq items (cdr items))))))

    (when aux
      (lyskom-start-of-command nil)
      (unwind-protect
          (progn
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
            (unless (cond ((eq 'text (car arg))
                           (cache-del-text-stat (elt arg 1))
                           (blocking-do 'modify-text-info
                                        (elt arg 1)
                                        (list (aux-item->aux-no aux))
                                        nil))
                          ((eq 'conf (car arg))
                           (cache-del-conf-stat (elt arg 1))
                           (blocking-do 'modify-conf-info
                                        (elt arg 1)
                                        (list (aux-item->aux-no aux))
                                        nil))
                          ((eq 'server (car arg))
                           (prog1 (blocking-do 'modify-server-info
                                               (list (aux-item->aux-no aux))
                                               nil)
                             (lyskom-set-default 'lyskom-server-info (blocking-do 'get-server-info)))))
1230
1231
1232
1233
1234
1235
              (lyskom-report-command-answer nil)))
        (lyskom-end-of-command)))))
          

(defun lyskom-button-info-aux (buf arg text)
  (pop-to-buffer buf)
David Byers's avatar
David Byers committed
1236
  (goto-char (point-max))
1237
  (let ((aux nil))
1238
    (cond ((lyskom-aux-item-p arg))
1239
          ((listp arg) 
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
           (let ((items 
                  (cond ((eq 'text (car arg))
                         (text-stat->aux-items 
                          (blocking-do 'get-text-stat (elt arg 1))))
                        ((eq 'conf (car arg))
                         (conf-stat->aux-items 
                          (blocking-do 'get-conf-stat (elt arg 1))))
                        ((eq 'server (car arg))
                         (server-info->aux-item-list
                          (blocking-do 'get-server-info)))
                        (t nil))))
1251
1252
1253
1254
1255
1256
1257
             (while items
               (when (eq (aux-item->aux-no (car items)) (elt arg 2))
                 (setq aux (car items))
                 (setq items nil))
               (setq items (cdr items))))))
              
    (if aux
1258
        (let ((header (cond ((eq 'text (car arg)) 
1259
                             (lyskom-format 'aux-item-for-text-no (elt arg 1)))
1260
                            ((eq 'conf (car arg))
1261
                             (lyskom-format 'aux-item-for-conference-no
1262
1263
                                            (blocking-do 'get-conf-stat
                                                         (elt arg 1))))
1264
1265
                            ((eq 'server (car arg))
                             (lyskom-format 'aux-item-for-server))
1266
                            (t "????"))))
1267
1268
          (lyskom-start-of-command nil)
          (unwind-protect
1269
1270
1271
1272
1273
              (lyskom-insert (or (lyskom-aux-item-call aux
                                                       'info 
                                                       aux
                                                       header)
                                 (lyskom-aux-item-info aux header)))
1274
            (lyskom-end-of-command)))
1275
      (lyskom-format-insert-before-prompt 'cant-get-aux-item))))
1276
           
David Byers's avatar
David Byers committed
1277
1278
(defun lyskom-button-apply (buf arg text)
  (apply (car arg) (cdr arg)))