help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: axiom mode


From: Martin Rubey
Subject: Re: axiom mode
Date: 10 Jun 2007 08:41:48 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Dear Tom,

Tom Tromey <tromey@redhat.com> writes:

> >>>>> "Martin" == Martin Rubey <axiomize@yahoo.de> writes:
> 
> I'm just guessing, based on what you wrote & a quick glance at the code, but
> I think you want to set local hooks.
> 
> Martin>   (add-hook 'comint-output-filter-functions 'axiom-output-filter)
> 
> So here you would want:
> 
>   (add-hook 'comint-output-filter-functions 'axiom-output-filter nil t)

many thanks, that did the trick.

> I don't know the answers to your other questions, sorry.

well, there remain only two things I don't know how to do.  Maybe there are
some more emacs gurus around:

* port to xemacs

* write clean initalisation code.  In particular, it should be possible to have
  several buffers with different axiom processes, just like in shell mode.  I
  looked at shell.el, but fail to understand it.

  For those who don't want to dig through all the code, I copy the relevant
  four routines below.  (It's not me who wrote them, and I find them rather
  difficult to follow.)

Again, many many thanks

Martin

(defun axiom-comint-run ()
  "Run PROGRAM in a comint buffer with ARGS and switch to it."
  (switch-to-buffer (make-comint "axiom" axiom-command nil axiom-args)))


(define-derived-mode axiom-mode comint-mode "AXIOM")

(defun axiom ()
   "Run axiom in a terminal environment"
  (interactive)
  (if (and (processp axiom-process)
           (eq (process-status axiom-process) 'run))
      (switch-to-buffer (axiom-buffer))
    (axiom-mode-new-axiom-process))
  (axiom-mode))

;; If there is a running axiom process switch to this axiom buffer
;; In the other case clean buffer and process variables and 
;; start a new process in a new buffer.

(defun axiom-mode-new-axiom-process ()
  (when (processp axiom-process)
    (delete-process axiom-process)
    (kill-buffer (axiom-buffer))
    (setq axiom-process nil))
  (setq axiom-end-of-input 0)
  ;; First, let's get axiom up and running. 
  (axiom-run)
  ;; we make also the banner write-protected
  ;; note that because of the axiom-output-filter we might already have
  ;; write protected the banner.
  (let ((inhibit-read-only t))
    (remove-text-properties 1 (point) '(face nil rear-nonsticky nil))
    (put-text-property 1 (point) 'front-sticky t)
    (put-text-property 1 (point) 'read-only t)
    ;; We need to tell Emacs how to clean up if we close this
    ;; buffer - otherwise restarting is difficult:
    (add-hook 'kill-buffer-hook 'axiom-cleanup)
    ;; Then we clean up the prompt.
    (axiom-clean-up-prompt)
    ;; We need to explicitly write protect the first prompt, since it
    ;; is outside the normal write protect mode used for subsequent
    ;; output: 
    (axiom-make-prompt (- (point) 7) (point))
    ;; Next, we turn on some key bindings for our new mode:
    (use-local-map axiom-mode-map)
    (substitute-key-definition 'comint-previous-input 
                               'axiom-scroll-previous-input axiom-mode-map)
    (substitute-key-definition 'comint-next-input 
                               'axiom-scroll-next-input axiom-mode-map)
    ;; HyperDoc currently sends loading messages to the buffer.  Because of the
    ;; current setup, they are going to be read-only, and they are not followed
    ;; by a prompt.  Thus, lest we cannot append any further input, we have to
    ;; mute them.  Currently this is only possible via 
    ;; )set messages autoload off
    (insert ")se me au of")
    (axiom-eval)))

(defun axiom-run ()
  "Run Axiom in a buffer."
  ;; Get the command to use
  (axiom-get-command)
  ;; Run that command and switch to the new buffer
  (axiom-comint-run)
  ;; and identify the process as well:
  (setq axiom-process (get-buffer-process (current-buffer)))
  ;; We need a custom wait condition for the first case, since two input
  ;; prompts appear when "axiom" is used to as the startup command.
  ;; Note that the REGEXP used in re-search-backward
  ;; is not compatible with grep or other tools - it is specific to the
  ;; behavior of Emacs
  (when (equal axiom-command "axiom")
    (while (not (re-search-backward "(1) -> [^ ](1) ->" nil t))
      (accept-process-output axiom-process)))
  (when (equal axiom-command "AXIOMsys")
    (while (not (re-search-backward "(1) -> " nil t))
      (accept-process-output axiom-process)))
;; Tom Tromey: last argument being true means that the hook is buffer-local
  (add-hook 'comint-output-filter-functions 'axiom-output-filter nil t)
  (sit-for 0 axiom-after-output-wait))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]