CLIM mail archive


evaluation in a CLIM interactor pane

;;;; This method will alter the CLIM command reader such that if the user
;;;; types a Lisp form or atom in a CLIM interaction pane, that form or
;;;; atom will be evaluated, and the result printed in the interaction pane.

;;;; You must supply the name of your frame in the first line below, and
;;;; a command table in the second line below.

(gclos:defmethod clim:read-frame-command ((frame your-frame-here) &key stream)
  (let ((cmd-table (clim:find-command-table *cmd-table*)))

   (clim:with-command-table-keystrokes (keystrokes cmd-table)
    (multiple-value-bind (cmd type)

			 ;; The with-simple-restart is used to intercept ^Z if
			 ;; the user types it at command level.  Without this
			 ;; construct, an endless loop will be invoked because
			 ;; we are called within an embedded abort restart,
			 ;; which will be reinvoked with the ^Z character still
			 ;; in CLIM's input buffer.

			 (with-simple-restart (abort "Return to command level")
			    (read-cmd-using-keystrokes cmd-table keystrokes)

      (cond ((eq 'clim:form type)			;; The user typed a lisp form
	     (clim:terpri stream)
	     (clim::print (eval cmd) stream)
	     (clim:terpri stream)

	    ((and (eq nil cmd) (eq t type))		;; The user typed ^Z
	     (clim:read-char stream)

	    (t						;; The user clicked on a menu command
	     (values cmd type) )
      ) ) )

;; Read a command, allowing keystroke accelerators.  If we get a keystroke
;; with no corresponding command, just return the keystroke itself.
(defun read-cmd-using-keystrokes (command-table keystrokes
				      &key (stream clim::*query-io*)
					   (command-parser clim::*command-parser*)
					   (command-unparser clim::*command-unparser*)
					   (partial-command-parser clim::*partial-command-parser*)
					   (keystroke-test #'eql))
  (let ((clim::*command-parser* command-parser)
	(clim::*command-unparser* command-unparser)
	(clim::*partial-command-parser* partial-command-parser)
    (let ((command
	    (block keystroke
              (clim::handler-bind ((clim::accelerator-gesture
				    #'(lambda (c)
					(return-from keystroke
						     (clim::accelerator-gesture-event c))))
		(let ((clim::*accelerator-characters* keystrokes))
		  (multiple-value-setq (command type)
                                       (clim:accept `(clim:command-or-form :command-table ,command-table)
						    :prompt-mode :raw
;;;; This keyword is accepted by neither Lucid nor Franz CLIM, but I thought it
;;;; worked for Lucid at one time.
;;;;						    #-Franz-Inc :replace-input #-Franz-Inc nil
						    :stream stream :prompt nil)

      (if (characterp command)
	    ;; PKARP: I had to add the CLIM:READ-CHAR because the keystroke character seemed 
	    ;; to remain in the input buffer -- Grasper would loop, repeatedly processing
	    ;; the same command over and over again.
	    (clim:read-char stream)
	    (values (clim:lookup-keystroke-command-item command command-table
							:test keystroke-test)
		    type) )
	  (values command type)))))


Main Index | Thread Index