;;;
;;; Emacs 19 process specific code.
;;;
;;; ----------------------------------------------------------------------
;;; This file is part of ILOG Talk.
;;; Inquiries to ILOG S.A.
;;;              9 rue de Verdun, BP 85,
;;;              94253 Gentilly Cedex, France.
;;;
;;; Copyright (c) 1993-1996 by ILOG
;;; ----------------------------------------------------------------------
;;;

(require 'talk-macros)


;; Faces
;; -----
;;

(defvar tp:output-face 'tp:output-face
  "Face used to display Talk output.")

(defvar tp:input-face 'tp:input-face
  "Face used to display user input.")

(defvar tp:pseudo-input-face 'tp:pseudo-input-face
  "Face used to display user pseudo-input.")

(if tm:dark-background-p
    (progn
      (tm:create-face 'tp:output-face "wheat" () ())
      (tm:create-face 'tp:input-face "pink" () 'bold)
      (tm:create-face 'tp:pseudo-input-face "forest green" () 'italic))
  (progn
    (tm:create-face 'tp:output-face "black" () ())
    (tm:create-face 'tp:input-face "red" () 'bold)
    (tm:create-face 'tp:pseudo-input-face "SlateBlue" () 'italic)))


;; Global variables
;; ----------------
;;

(defvar tp:initializedp ()
  "T when Talk process mode has been intialized.")


;; Setup
;; -----
;;

(defun tpp:talk-process-specific-variables ()
  (make-local-variable 'before-change-function)
  (make-local-variable 'mode-line-modified)
  (tpp:make-buffer-write-protected))

	  
;; Process buffer control
;; ----------------------
;;

(defun tpp:accept-buffer-substring (start end type)
  (let ((extent (make-extent start end)))
    (set-extent-face extent
		     (cond
		      ((eq type 'talk-output) tp:output-face)
		      ((eq type 'user-input) tp:input-face)
		      ((eq type 'pseudo-user-input) tp:pseudo-input-face)))))
  
(defun tpp:make-buffer-writable ()
  (setq before-change-function ())
  (setq mode-line-modified "-----")
  (redraw-mode-line))

(defun tpp:make-buffer-write-protected ()
  (setq before-change-function 'tpp:before-change-function)
  (setq mode-line-modified "--%--")
  (redraw-mode-line))

(defun tpp:before-change-function (start end)
  (let ((limit (if (or (eq last-input-char ?\C-m)
		       (eq last-input-char 'return))
		   (1- tpp:insertion-marker)
		 tpp:insertion-marker)))
    (if (not (>= start limit))
	(error "Write-protected region. Use C-x C-q to toggle protected mode."))))


(defun tpp:toggle-protected-mode ()
  "Toggle between write-protected mode and unprotected mode for this buffer. In
write-protected mode, text printed by Talk or sent by the user cannot be
modified."
  (interactive)
  (if before-change-function
      (tpp:make-buffer-writable)
    (tpp:make-buffer-write-protected)))


(provide 'talk-process19)
