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
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.
17 ; Invoke with M-x zwgc.
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
25 ; The following should be added to your .zephyr.desc file if you want
26 ; to take advantage of the zwgc message seperation features:
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 $")
38 (defun narrow-to-string (str)
39 "narrow and put up a string..."
40 (interactive "sString: ")
41 (narrow-to-region (point) (point))
44 (defvar zwgc-prog "/usr/etc/zwgc"
45 "*Program to run as the zwgc process. Should set it for the machine type.")
47 (defun zwgc-wakeup (proc string)
48 "Procedure called when zwgc spits something out"
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))
57 (narrow-to-string 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*"))
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."
74 (let ((buffer (get-buffer-create "*zwgc*")) proc status)
75 (setq proc (get-buffer-process buffer))
77 (setq status (process-status proc)))
80 (if (memq status '(run stop))
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))
88 (local-set-key "\177" 'zwgc-punt)
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))
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))
107 "Delete the current ZephyrGram from the *zwgc* buffer."
109 (let ((window-min-height 1))
110 (display-buffer (get-buffer "*zwgc*"))
111 (delete-region (point-min) (point-max))
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))
121 ;; [eichin:19880309.2005EST]
123 ;; Send zephyrgrams from emacs...
126 (defvar *who* "" "last user sent to with zsend")
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."
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))
139 (read-input "Message:")))
141 (let ((tempbuf (get-buffer-create " *zephyr*send*")))
142 (switch-to-buffer tempbuf)
143 (local-set-key "\C-c\C-c" 'exit-recursive-edit)
145 (if (and (equal (cdr 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 ""))
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
168 "-q" ;args -- ignore server responses.
170 (call-process-region (point-min) (point-max) ;range
171 "/usr/athena/zwrite" ;process
175 "-q" ;args -- ignore server responses.
176 "-i" ;[eichin:19880312.0015EST]
178 (if (not (equal (point-max) 1))
179 (message (buffer-substring 1 (1- (point-max))))))
181 ; suggested binding (control-meta-z)
182 ;(global-set-key "\M-\C-z" 'zsend)