;;;
;;; FILE
;;;	sticky.el		$VER: V1.00 sticky.el
;;;
;;; DESCRIPTION
;;;	ELisp part of Emacs Starter Deluxe. This code 
;;;	is loaded when Emacs is invoked in "sticky" mode.
;;;
;;;	Place this file somewhere in your lisp-path, for example
;;;	in the directory GnuEmacs:lisp.
;;;
;;;	Please read the file "starter.doc".
;;;
;;; AUTHORS
;;;	Anders Lindgren, d91ali@csd.uu.se
;;;	Bo Liljegren, bo-lilje@dsv.su.se
;;;
;;; LICENSE
;;;     Copyright (C) 1993  Anders Lindgren  and  Bo Liljegren
;;;
;;;	This program is free software; you can redistribute it and/or modify
;;;	it under the terms of the GNU General Public License as published by
;;;	the Free Software Foundation; either version 2 of the License, or
;;;	(at your option) any later version.
;;;
;;;	This program is distributed in the hope that it will be useful,
;;;	but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;	MERCHANTABILITY of 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 this program; if not, write to the Free Software
;;;	Foundation, Inc., 675 Mass Ave, Cambridge, Ma 02139, USA.
;;;
;;; HISTORY
;;;	24-Sep-93 ALi  Created this file.
;;;


(provide 'sticky)

(make-variable-buffer-local 'sticky-rexx-port)
(set-default 'sticky-rexx-port nil)

(if (not (fboundp 'old-kill-buffer))
    (fset 'old-kill-buffer (symbol-function 'kill-buffer)))

;;; Redefine the kill-buffer function.
;;; If the buffer is in "sticky" mode, notify the client that this buffer is no more.
;;; The reason why we're asking whether to kill the buffer or not, is to avoid a situation
;;; where the client is notified but the user answers no.
(defun kill-buffer (buffer)
  "One arg, a string or a buffer.  Get rid of the specified buffer.
Any processes that have this buffer as the `process-buffer' are killed
with `delete-process'.
Patched to notify client."
  (interactive "bKill buffer: ")
  (if (eq (setq buffer (get-buffer buffer)) nil)
      nil
    (save-excursion
      (set-buffer buffer)
      (if (or (not (buffer-modified-p buffer))
	      (not (buffer-file-name))
	      noninteractive
	      (yes-or-no-p (format "Buffer %s modified; kill anyway? " (buffer-name))))
	  (progn
	    (set-buffer-modified-p nil)
	    (if sticky-rexx-port
		(amiga-arexx-send-command (concat "ADDRESS " sticky-rexx-port " TERMINATING") t))
	    (old-kill-buffer buffer))))))
