Subject: zwgc.el

From: [email-masked] (John G. Myers)
Date: Mon, 11 Jun 90 16:37:45 EDT

I got a copy of your zwgc.el file from someone and have cleaned it up.  My results follow:

; zwgc.el
;
; This file is part of the Project Athena Zephyr Notification System.
; Created by: Mark W. Eichin <[email-masked]>
; $Source: /afs/andrew.cmu.edu/ac/src/contributed/gnu-emacs/lisp/RCS/zwgc.el,v $
; $Author: jm36 $
; Copyright (c) 1988 by the Massachusetts Institute of Technology.
; For copying and distribution information, see the file
; "mit-copyright.h". 

;
; Emacs mode for running zwgc in a sub process of emacs. It pops up a
; window for every new message; if you make bells appear between each
; message, it will be able to seperate them. If you move the mouse
; into the message window and hit `delete' it will delete the current
; message; if there are other messages, it will show them, if not, it
; will make the window go away.
;
; Invoke with M-x zwgc.
; 

; Also included is M-x zwrite, which prompts for a user name and a
; message to send to them. If the message is blank, a buffer is popped
; up to edit the message in. If a prefix argument is given, zwrite
; prompts for an instance instead. If the user name is blank, the last
; one is reused.
; 

; The following should be added to your .zephyr.desc file if you want
; to take advantage of the zwgc message seperation features:
;	does $mode
;	match tty
;		beep
;	endmatch
;	enddoes
;
(defvar zwgc_el-RCS-id)
(setq zwgc_el-RCS-id "$Header: /afs/andrew.cmu.edu/ac/src/contributed/gnu-emacs/lisp/ 
RCS/zwgc.el,v 1.1 89/12/01 12:50:04 jm36 Exp $")
;
;

(defvar zwgc-prog "/usr/local/etc/zwgc" 

  "*Program to run as the zwgc process. Should set it for the machine type.")

(defun zwgc-wakeup (proc string)
  "Procedure called when zwgc spits something out"
  (save-excursion (set-buffer (process-buffer proc))
		  (goto-char (point-max))
		  (if (= 7 (string-to-char string))
		      (progn
			(ding t)
			(message "Got a Zephyr message!")
			(narrow-to-region (point) (point))))
		  (let ((buffer-read-only nil))
		    (insert string)
		    (goto-char (point-min))
		    (replace-string "\r" "")))
  (zwgc-pop-up-window (process-buffer proc))
  )

(defun zwgc ()
  "emacs mode for running zwgc in a sub process of emacs. It pops up a
window for every new message; if you make bells appear between each
message, it will be able to seperate them. If you move the mouse into
the message window and hit `delete' it will delete the current
message; if there are other messages, it will show them, if not, it
will make the window go away."
  (interactive)
  (let ((buffer (get-buffer-create "*Zephyr messages*")) proc status)
    (setq proc (get-buffer-process buffer))
    (if proc
	(setq status (process-status proc)))
    (save-excursion
      (set-buffer buffer)
      (setq buffer-read-only t)
      (if (memq status '(run stop))
	  nil
	(if proc (delete-process proc))
	(setq proc (start-process "Zwgc" buffer 

				  zwgc-prog "-ttymode" "-nofork"))
	(set-process-filter proc 'zwgc-wakeup)
	(process-kill-without-query proc))
      (local-set-key "\177" 'zwgc-punt)
      )
    ))

;(defun zwgc-pop-up-window (buffer &optional max-height)
;  "Pop up a window that is just big enough to hold the current buffer."
;  (interactive "bBuffer to pop: ")
;  (let* ((retwin (selected-window))
;	 (pop-up-windows t)
;	 (window-min-height 1))
;    (pop-to-buffer buffer)
;    (setq lines (1+ (count-lines (point-min) (point-max))))
;    (enlarge-window (- lines (window-height (selected-window))))
;    (goto-char (point-min))
;    (other-window 1)
;    ))

(defun zwgc-pop-up-window (buffer)
  "Pop up a window that is just big enough to hold BUFFER."
  (save-excursion
    (let* ((bufwin (get-buffer-window buffer))
	   (lines)
	   (window-min-height 1)
	   (owin (selected-window)))
      (set-buffer buffer)
      (setq lines (1+ (count-lines (point-min) (point-max))))
      (if bufwin
	  (progn
	    (select-window bufwin)
	    (enlarge-window (- lines (window-height bufwin)))
	    (goto-char (point-min)))
	(let* ((largest (get-largest-window))
	       (largebuf (window-buffer largest))
	       (splitwin))
	  (set-window-buffer largest buffer)
	  (setq splitwin (split-window largest lines))
	  (set-window-buffer splitwin largebuf)
	  (if (eq largest owin) (setq owin splitwin))))
      (select-window owin))))

(defun zwgc-punt ()
  "Delete the current ZephyrGram from the *Zephyr messages* buffer."
  (interactive)
  (let ((window-min-height 1))
    (set-buffer (get-buffer "*Zephyr messages*"))
    (display-buffer (current-buffer))
    (let ((buffer-read-only nil)) (delete-region (point-min) (point-max)))
    (widen)
    (if (not (search-backward "\007" nil t))
	(progn
	  (delete-windows-on (current-buffer))
	  (bury-buffer (current-buffer)))
      (narrow-to-region (point) (point-max))
      (enlarge-window (- (1+ (count-lines (point-min) (point-max)))
			 (window-height (selected-window))))
      (goto-char (point-min))
      )))
;;
;; [eichin:19880309.2005EST]
;; zsend.el
;; Send zephyrgrams from emacs...
;;

(defvar *zwgc*who* "" "last user sent to with zwrite")

(defun zwrite (&optional who message)
  "zwrite prompts for a user name and a message to send to them as a
ZephyrGram. If the message is blank, a buffer is popped up to edit the
message in. If a prefix argument is given, zwrite prompts for an
instance instead. If the user name is blank, the last one is reused."
  (interactive
   (list (if current-prefix-arg		; is this portable???
	     (cons 'instance (read-input "zwrite instance:"))
	   (cons 'who (read-input "Zwrite to: ")))
;	 (select-window (minibuffer-window))
;	 (enlarge-window 4)
	 (read-input "Message: ")))
  (save-excursion
    (let ((tempbuf (get-buffer-create " *zephyr*send*")))
      (switch-to-buffer tempbuf)
      (local-set-key "\C-c\C-c" 'exit-recursive-edit)
      (erase-buffer)
      (if (and (equal (cdr who) "")
	       (equal *who* ""))
	  (message "Please specify user at least once.")
	(if (not (equal (cdr who) ""))
	    (setq *who* who)		; save *who* for next time
	  (setq who *who*))		; or, use the old value
	(if (not (equal message ""))
	    (progn
	      (insert message)
	      (zwgc-send who))
	  (progn
	    (recursive-edit)
	    (zwgc-send who)))))))

(defun zwgc-send (who)
  "Send a ZephyrGram to user WHO, zwrite is the user interface to this."
  (if (eq 'who (car who))
      (call-process-region (point-min) (point-max) ;range
			   "/usr/local/bin/zwrite" ;process
			   t		;delete-p
			   t		;output-p
			   nil		;redisplay-p
			   "-a"		; jtkohl is being a twit
			   "-q"		;args
			   (cdr who))
    (call-process-region (point-min) (point-max) ;range
			   "/usr/local/bin/zwrite" ;process
			   t		;delete-p
			   t		;output-p
			   nil		;redisplay-p
			   "-a"		; jtkohl is being a twit
			   "-q"		;args
			   "-i"		;[eichin:19880312.0015EST]
			   (cdr who)))
  (if (not (equal (point-max) 1))
      (message (buffer-substring 1 (1- (point-max))))))

; suggested binding (control-meta-z)
;(global-set-key "\M-\C-z" 'zwrite)