(in-package "KPML-I")

;;; File: acl-editor-window.lisp
;;;
;;; Provides a resource editing functionality under ACL Windows
;;; by making use of the Editi interface between ACL and WinEmacs,
;;; a version of Emacs for PCs. 
;;;
;;; The form to be edited is brought up in a parallel running
;;; Emacs buffer. Then it is then the user's responsibility to
;;; EVALUATE the modified definition if she/he so wants.

;;; ----------------------------------------------------------------------
;;; Note: Attempts to use a multiline lisp widget  under a normal menu
;;; to work within  ACLPC   has not  worked (getting  the  appropriate
;;; comtab  to inform control  of events to  that widget  is not in my
;;; documentation and    seems to be   a  problem or...),  neither has
;;; replacing basic use of the ACLPC text editor worked. There seem to
;;; be problems as  to getting the  window served  sufficiently often:
;;; when a CLIM frame is up and running, these frames are more or less
;;; dead.
;;; ----------------------------------------------------------------------
 

;;; Following is the basic function that is called from the KPML
;;; interface whenever anything is to be edited. The definition contains
;;; the appropriate string for the definition.
;;;
;;; N.B. remember case sensitivity in Emacs Lisp!!!


(defvar *editing-frame-count* 1)

(defun MAKE-KPML-RESOURCE-EDITOR (definition)
  (unless (and (boundp acl::*external-edit-p*)
	       acl::*external-edit-p*)
	  (kpml::warning "The link to Emacs/WinEmacs is not established. You must initialize this in the prescribed fashion before using the Editing facilities.")
	  (return-from MAKE-KPML-RESOURCE-EDITOR nil))
  (let* ((buffer-contents definition)
	 (message
	  (format 
	   nil 
	   ";;; TO ACCEPT A MODIFIED DEFINITION PLACE THE CURSOR~% ;;; AT THE BEGINNING OF THE FORM AND EVALUATE (C-c C-c). ~% ;;; N.B. ACTIVATE VERSIONING IF REQUIRED!!!"))
	 (buffer-name 
	  (format nil 
		  "*kpml-resource-editor*[~A]"
		  *editing-frame-count*))
	 (associated-file 
	  (string-upcase
	   (namestring 
	    (merge-pathnames kpml-i::*default-kpml-hardcopy-directory*
			     buffer-name)))))
    (setf *editing-frame-count* (1+ *editing-frame-count*))
    (acl::send-string-to-emacs 
     (format nil "(KPML-EDIT-FORM ~S ~S ~S ~S)" 
	     buffer-name
	     associated-file
	     buffer-contents
	     message))))



