]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/zwgc.el
Initial revision
[1ts-debian.git] / zephyr / zwgc / zwgc.el
1 ; zwgc.el
2 ;
3 ; This file is part of the Project Athena Zephyr Notification System.
4 ; Created by: Mark W. Eichin <eichin@athena.mit.edu>
5 ; $Id: zwgc.el,v 1.4 1999/01/22 23:20:51 ghudson Exp $
6 ; Copyright (c) 1988 by the Massachusetts Institute of Technology.
7 ; For copying and distribution information, see the file
8 ; "mit-copyright.h". 
9 ;
10 ; Emacs mode for running zwgc in a sub process of emacs. It pops up a
11 ; window for every new message; if you make bells appear between each
12 ; message, it will be able to seperate them. If you move the mouse
13 ; into the message window and hit `delete' it will delete the current
14 ; message; if there are other messages, it will show them, if not, it
15 ; will make the window go away.
16 ;
17 ; Invoke with M-x zwgc.
18
19 ; Also included is M-x zsend, which prompts for a user name and a
20 ; message to send to them. If the message is blank, a buffer is popped
21 ; up to edit the message in. If a prefix argument is given, zsend
22 ; prompts for an instance instead. If the user name is blank, the last
23 ; one is reused.
24
25 ; The following should be added to your .zephyr.desc file if you want
26 ; to take advantage of the zwgc message seperation features:
27 ;       does $mode
28 ;       match tty
29 ;               beep
30 ;       endmatch
31 ;       enddoes
32 ;
33 (defvar zwgc_el-RCS-id)
34 (setq zwgc_el-RCS-id "$Id: zwgc.el,v 1.4 1999/01/22 23:20:51 ghudson Exp $")
35 ;
36 ;
37
38 (defun narrow-to-string (str)
39   "narrow and put up a string..."
40   (interactive "sString: ")
41   (narrow-to-region (point) (point))
42   (insert str))
43
44 (defvar zwgc-prog "/usr/etc/zwgc" 
45   "*Program to run as the zwgc process. Should set it for the machine type.")
46
47 (defun zwgc-wakeup (proc string)
48   "Procedure called when zwgc spits something out"
49   (let (start-limit)
50     (save-excursion (set-buffer (get-buffer "*zwgc*"))
51                     (setq start-limit (point))
52                     (goto-char (point-max))
53                     (if (= 7 (string-to-char string))
54                         (progn
55                           (ding 1)
56                           (message "got one!")
57                           (narrow-to-string string))
58                       (insert string))
59                     (search-backward "\007" start-limit t)
60                     (while (search-forward "\015" (point-max) t) ;flush ^M's
61                       (delete-backward-char 1)))
62     (Special-pop-up-window (get-buffer "*zwgc*"))
63     ))
64
65 (defun zwgc ()
66   "emacs mode for running zwgc in a sub process of emacs. It pops up a
67 window for every new message; if you make bells appear between each
68 message, it will be able to seperate them. If you move the mouse into
69 the message window and hit `delete' it will delete the current
70 message; if there are other messages, it will show them, if not, it
71 will make the window go away."
72   (interactive)
73   (require 'shell)
74   (let ((buffer (get-buffer-create "*zwgc*")) proc status)
75     (setq proc (get-buffer-process buffer))
76     (if proc
77         (setq status (process-status proc)))
78     (save-excursion
79       (set-buffer buffer)
80       (if (memq status '(run stop))
81           nil
82         (if proc (delete-process proc))
83         (setq proc (start-process "Zwgc" buffer 
84                                   zwgc-prog "-disable" "X"
85                                   "-default" "plain" "-nofork"))
86         (set-process-filter proc 'zwgc-wakeup))
87       (shell-mode)
88       (local-set-key "\177" 'zwgc-punt)
89       )
90     ))
91
92
93 (defun Special-pop-up-window (buffer &optional max-height)
94   "Pop up a window that is just big enough to hold the current buffer."
95   (interactive "bBuffer to pop: ")
96   (let* ((retwin (selected-window))
97          (pop-up-windows t)
98          (window-min-height 1))
99     (pop-to-buffer buffer)
100     (setq lines (1+ (count-lines (point-min) (point-max))))
101     (enlarge-window (- lines (window-height (selected-window))))
102     (goto-char (point-min))
103     (other-window 1)
104     ))
105
106 (defun zwgc-punt ()
107   "Delete the current ZephyrGram from the *zwgc* buffer."
108   (interactive)
109   (let ((window-min-height 1))
110     (display-buffer (get-buffer "*zwgc*"))
111     (delete-region (point-min) (point-max))
112     (widen)
113     (if (not (search-backward "\007" nil t))
114         (delete-windows-on "*zwgc*")
115       (narrow-to-region (point) (point-max))
116       (enlarge-window (- (1+ (count-lines (point-min) (point-max)))
117                          (window-height (selected-window))))
118       (goto-char (point-min))
119       )))
120 ;;
121 ;; [eichin:19880309.2005EST]
122 ;; zsend.el
123 ;; Send zephyrgrams from emacs...
124 ;;
125
126 (defvar *who* "" "last user sent to with zsend")
127
128 (defun zsend (&optional who message)
129   "zsend prompts for a user name and a message to send to them as a
130 ZephyrGram. If the message is blank, a buffer is popped up to edit the
131 message in. If a prefix argument is given, zsend prompts for an
132 instance instead. If the user name is blank, the last one is reused."
133   (interactive
134    (list (if current-prefix-arg         ; is this portable???
135              (cons 'instance (read-input "Instance:"))
136            (cons 'who (read-input "Who:")))
137 ;        (select-window (minibuffer-window))
138 ;        (enlarge-window 4)
139          (read-input "Message:")))
140   (save-excursion
141     (let ((tempbuf (get-buffer-create " *zephyr*send*")))
142       (switch-to-buffer tempbuf)
143       (local-set-key "\C-c\C-c" 'exit-recursive-edit)
144       (erase-buffer)
145       (if (and (equal (cdr who) "")
146                (equal *who* ""))
147           (message "Please specify user at least once.")
148         (if (not (equal (cdr who) ""))
149             (setq *who* who)            ; save *who* for next time
150           (setq who *who*))             ; or, use the old value
151         (if (not (equal message ""))
152             (progn
153               (insert message)
154               (zwrite who))
155           (progn
156             (recursive-edit)
157             (zwrite who)))))))
158
159
160 (defun zwrite (who)
161   "Send a ZephyrGram to user WHO, zsend is the user interface to this."
162   (if (eq 'who (car who))
163       (call-process-region (point-min) (point-max) ;range
164                            "/usr/athena/zwrite" ;process
165                            t            ;delete-p
166                            t            ;output-p
167                            nil          ;redisplay-p
168                            "-q"         ;args -- ignore server responses.
169                            (cdr who))
170     (call-process-region (point-min) (point-max) ;range
171                            "/usr/athena/zwrite" ;process
172                            t            ;delete-p
173                            t            ;output-p
174                            nil          ;redisplay-p
175                            "-q"         ;args -- ignore server responses.
176                            "-i"         ;[eichin:19880312.0015EST]
177                            (cdr who)))
178   (if (not (equal (point-max) 1))
179       (message (buffer-substring 1 (1- (point-max))))))
180
181 ; suggested binding (control-meta-z)
182 ;(global-set-key "\M-\C-z" 'zsend)
183
184