lyskom-buttons.el 26.1 KB
Newer Older
1
2
;;;;;
;;;;; $Id$
3
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
4
5
6
7
8
;;;;;
;;;;; 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 
9
;;;;; the Free Software Foundation; either version 2, or (at your option) 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;;;; 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
;;;;
;;;;

33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(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)))))
      


65
(defun kom-previous-link (num)
66
  "Move the cursor to the previous active area in the LysKOM buffer."
67
68
  (interactive "p")
  (while (> num 0)
69
70
    (let ((where (previous-single-property-change (point) 
                                                  'lyskom-button-text)))
71
72
      (if where
          (progn
73
74
75
76
            (if (not (get-text-property where 'lyskom-button-text))
                (setq where (previous-single-property-change 
                             where
                             'lyskom-button-text)))
77
78
79
80
81
82
83
            (if where
                (goto-char where)
              (goto-char (point-min))
              (setq num 1)))))
    (setq num (1- num))))

(defun kom-next-link (num)
84
  "Move the cursor to the next active area in the LysKOM buffer."
85
86
  (interactive "p")
  (while (> num 0)
87
    (let ((where (next-single-property-change (point) 'lyskom-button-text)))
88
89
      (if where
          (progn
90
            (if (not (get-text-property where 'lyskom-button-text))
91
                (setq where (next-single-property-change where
92
                                                         'lyskom-button-text)))
93
94
95
96
97
98
99
100
            (if where
                (goto-char where)
              (goto-char (point-max))
              (setq num 1)))))
    (setq num (1- num))))


(defun kom-key-mouse-2 ()
101
  "Simulate a mouse button press at point."
102
  (interactive)
103
  (lyskom-mouse-2 (point)))
104
105

(defun kom-mouse-2 (click)
106
107
  "Execute the default action of the active area under the mouse."
  (interactive "@e")
108
  (let ((start (event-start click)))
109
    (lyskom-mouse-2 (car (cdr start)))))
110

111
112
113
114
115
(defun kom-mouse-3 (event)
  "Pop up a menu of actions to be taken at the active area under the mouse."
  (interactive "@e")
  (let ((start (event-start event)))
    (lyskom-mouse-3 (car (cdr start)) event)))
David Kågedal's avatar
David Kågedal committed
116
117
118
119
120
121

(defun kom-mouse-null (event)
  "Do nothing."
  ;; This is here to pervent unwanted events when clicking mouse-3
  (interactive "e"))

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(defun lyskom-mouse-3 (pos event)
  "Internal function used by kom-mouse-3"
  (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))
         (title (lyskom-format 
                 (lyskom-get-string
                  (or (intern-soft (concat (symbol-name type)
                                           "-popup-title"))
                      'generic-popup-title))
                 text))
         (actl  (or (and data (elt data 3)) nil)))
    (cond ((null data) (goto-char pos))
          ((null actl) (goto-char pos))
          ((null buf) (goto-char pos))
          ((and buf (null (get-buffer buf)))
140
           (lyskom-message "%s" (lyskom-get-string 'no-such-buffer)))
141
142
143
144
145
146
147
148
149
150
151
          (t         
           (if (symbolp title) (setq title (lyskom-get-string title)))
           (set-buffer buf)
           ;;
           ;;   Using x-popup-menu is probably not the Right Thing
           ;;   I looked in mouse.el for the mouse-major-mode-menu,
           ;;   but it made Emacs abort when nothing was selected.
           ;;

           (let* ((menu (cons title (cons (cons "" actl) nil)))
                  (result (x-popup-menu event menu)))
David Kågedal's avatar
David Kågedal committed
152
153
154
155
156
	     ;; If mouse-3 is bound to its default
	     ;; mouse-save-than-kill, we will get an extra mouse event
	     ;; when the user clicks to get a menu that stays up. So
	     ;; we bind mouse-3 to a dummy function. Unfortunately it
	     ;; doesn't work completely.
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
             (if result
                 (funcall result buf arg text)))))))
         

(defun lyskom-mouse-2 (pos)
  "Execute the default action of the active area at POS if any."
  (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)))))
                 
    (cond ((null act) (goto-char pos))
          ((null buf) (goto-char pos))
          ((and buf (null (get-buffer buf))) 
175
           (lyskom-message "%s" (lyskom-get-string 'no-such-buffer)))
176
177
178
179
180
181
          (t (and buf (set-buffer buf))
             (funcall act
                      buf
                      arg
                      text)))))
                      
182
183


184
(defun lyskom-button-transform-text (text)
185
186
187
188
189
190
  "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)
        (el nil)
        (props nil))
191
192
    (while blist
      (setq el (car blist))
David Kågedal's avatar
David Kågedal committed
193
      (setq start 0)
194
      (while (string-match (elt el 0) text start)
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
        (add-text-properties 
         (match-beginning (or (elt el 2) 0))
         (match-end (or (elt el 2) 0))
         (cond ((eq (elt el 1) 'text)
                (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)))
               (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
239
  (elt el 4))
240

241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
(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))))
              ((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))))))
    result))


268
	
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
(defun lyskom-generate-button (type arg &optional text face)
  "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."
  (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)))
284
         (the-hint (lyskom-get-button-hint hints))
285
286
287
288
289
290
         (props 
          (cond ((and (or (eq type 'conf) 
                          (eq type 'pers))
                      numarg)
                 (list 'face 
                       (or face
David Byers's avatar
David Byers committed
291
292
293
                           (cond ((eq persno numarg) 'kom-me-face)
                                 ((memq numarg kom-friends) 'kom-friends-face)
                                 (t 'kom-active-face)))
294
295
296
297
298
299
                       'mouse-face 'kom-highlight-face
                       'lyskom-button-text text
                       'lyskom-button-type type
                       'lyskom-button-arg numarg
                       'lyskom-buffer lyskom-buffer))
                ((and (eq type 'text) numarg)
David Byers's avatar
David Byers committed
300
                 (list 'face (or face 'kom-text-no-face)
301
302
303
304
305
306
307
308
309
310
                       'mouse-face 'kom-highlight-face
                       'lyskom-button-text text
                       'lyskom-button-type type
                       'lyskom-button-arg numarg
                       '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
311
                       'lyskom-button-arg arg
312
                       'lyskom-buffer lyskom-buffer))
313
314
315
316
317
318
319
                (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
		       'lyskom-buffer lyskom-buffer)))))
320

321
322
323
324
325
    (append (list 'rear-nonsticky t)
	    (if the-hint
		(cons 'lyskom-button-hint
		      (cons the-hint props))
	      props))))
326
327
328
      
        
           
329
330

(defun lyskom-default-button (type arg)
331
332
333
  "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
type TYPE before being send to lyskom-generate-button."
David Kågedal's avatar
David Kågedal committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
  (and kom-text-properties
       (let (xarg text)
	 (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)))
		      ((numberp arg) (setq text "" xarg arg))
		      (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)))
		      ((lyskom-pers-stat-p arg)
		       (setq xarg (pers-stat->pers-no arg)
			     text ""))
		      ((numberp arg) (setq text "" xarg arg))
		      (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)
		(cond ((stringp arg) (setq xarg nil text arg))
		      (t (setq xarg nil text ""))))
	       (t (setq xarg arg text "")))
	 (lyskom-generate-button type xarg text nil))))
367
368
369
370
                  

           

371
372
373
374
375

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

376
377
378
379
380
381
(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)
           (kom-view arg))))
David Byers's avatar
David Byers committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396


(defun lyskom-button-review-tree (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)
	   (kom-review-tree arg))))

(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)
	   (kom-find-root arg))))
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
(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)
                 (lyskom-mark-text arg nil 1))
             (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)
                 (lyskom-mark-text arg nil 0))
             (lyskom-end-of-command)))))
  
435

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
(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)
           (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)
           (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)
           (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)
           (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))))

(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."
  (kill-new text))


(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."
  (let* ((url text)
         protocol
         url-manager)
    (string-match ":" url)
    (setq protocol (substring url 0 (match-beginning 0)))
    (setq url-manager (lyskom-get-url-manager protocol))
    (if (null url-manager)
        (lyskom-error "Can't find URL viewer"))
517
    (goto-char (point-max))
518
    (funcall (elt url-manager 3) url url-manager)))
519
520
521
522
523
524
525
526



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

(defun lyskom-get-url-manager (protocol)
527
  "Get the URL manager for PROTOCOL (a string). Returns a function."
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
  (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)
546
  "Tell the user that the URL manager MANAGER is starting."
547
  (lyskom-message "%s" (lyskom-format (lyskom-get-string 'starting-program)
548
549
550
551
				 (elt manager 2))))


(defun lyskom-view-url-w3 (url manager)
552
  "View the URL URL using W3. Second argument MANAGER is ignored."
553
554
555
  (w3-fetch url))

(defun lyskom-view-url-dired (url manager)
556
  "View the URL URL using dired. Second argument MANAGER is ignored."
557
558
559
560
561
562
563
564
565
566
  (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
567
568
    (if  (string-match ";type=.$" path)
        (setq path (substring path 0 (match-beginning 0))))
569
570
571
572
573
    (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
574
575
576
577
    (cond ((string= host "localhost") (find-file path))
          (t (find-file (concat "/" user "@" host ":/" path))))
    ;;    (message "%s  %s  %s" user host path)
    ))
578
579


580

581
(defun lyskom-view-url-telnet (url manager)
582
  "View the URL URL using telnet. Second argument MANAGER is ignored."
583
  (if (not (and (string-match 
David Byers's avatar
David Byers committed
584
                 "telnet://\\([^@]*@\\)?\\([^/:]*\\)\\(:[0-9]*\\)?"
585
586
587
588
589
590
591
592
		 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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
	(user (if (match-beginning 1)
                  (substring url (match-beginning 1) (1- (match-end 1)))
                nil))
        (password nil))
    (if (and user
             (string-match "^\\([^:]*\\):\\(.*\\)" user))
        (progn (setq password (substring user
                                         (match-beginning 2)
                                         (match-end 2)))
               (setq user (substring user 
                                     (match-beginning 1)
                                     (match-end 1)))))

    (telnet (concat host " " port))
;;    (message "u:%s  p:%s  h:%s  #:%s" 
;;             (or user "<u>")
;;             (or password "<p>")
;;             (or host "<h>")
;;             (or port "<#>"))

    ))
614

615

616
(defun lyskom-view-url-mailmode (url manager)
617
  "View the URL URL using mail in Emacs. The second argument MANAGER is ignored."
618
619
620
621
622
623
624
  (if (not (and (string-match "mailto:\\([^@]+@.*\\)$" url)
		(match-beginning 1)))
      (lyskom-error "Bad URL"))
  (mail nil (substring url (match-beginning 1) (match-end 1))))


(defun lyskom-view-url-netscape (url manager)
625
626
627
628
629
  "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
630
631
632
633
634
635
636
637
638
639
640
  (let* ((proc (apply 'start-process "netscape"
                      nil
                      (if (listp kom-netscape-command)
                          (car kom-netscape-command)
                        kom-netscape-command)
                      (if (listp kom-netscape-command)
                          (append (cdr kom-netscape-command)
                                  (list "-remote"
                                        (format "openUrl(%s)" url)))
                        (list "-remote"
                              (format "openUrl(%s)" url)))))
641
642
643
644
645
646
647
648
649
         (status 'run)
         (exit nil))
    (lyskom-url-manager-starting manager)
    (while (eq status 'run)
      (accept-process-output)
      (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
650
           (apply 'start-process "netscape"
651
                          nil
David Byers's avatar
David Byers committed
652
653
654
655
656
657
658
                          (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))))
659
          (t nil))))
660
661
662


(defun lyskom-view-url-mosaic (url manager)
663
664
  "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."
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
  (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
682
683
684
685
686
687
688
689
690
              (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)))
691
692
	    (lyskom-url-manager-starting manager)))
      (save-excursion
David Byers's avatar
David Byers committed
693
694
695
696
697
698
699
700
701
        (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)))
702
703
704
	(lyskom-url-manager-starting manager)))))


David Kågedal's avatar
David Kågedal committed
705
706
707
;;;
;;;	email buttons
;;;
708

David Kågedal's avatar
David Kågedal committed
709
710
(defun lyskom-button-send-mail (to)
  (mail nil to))