axiom-developer
[Top][All Lists]
Advanced

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

[Axiom-developer] [Axiom-mail] a very little emacs mode for axiom.


From: Francois Maltey
Subject: [Axiom-developer] [Axiom-mail] a very little emacs mode for axiom.
Date: Mon, 30 May 2005 14:42:16 -0500

Changes http://page.axiom-developer.org/zope/mathaction/AxiomMail/diff
--
Hello, 

I send here my very first axiom-mode for emacs. 
It isn't a finish program.

It's like the maxima mode for emacs, but without latex. 
I translate and clear my mupad-run-mode.el file.

You can tell me what you want. 
I don't know how to use axiom debogger, 
so I don't what emacs-key will be fine.

It's work with xemacs on a linux box.

--------------------------------------------------------------------------
;
; axiomacs-smallest.el - 5/2005 version - smallest version
; by Fran�ois Maltey in 2005, from the mupad-run.el.

; axiomacs allows to use axiom as an editor for a session of axiom.
; 
; You can load this file from your .emacs, by example.
; 
; The commands are :
;
; axiom-run in starts an axiom session in a *Axiom* buffer.
; axiom-run-bis starts an axiom session in an other buffer.
; there are also axiom-batch and axiom-batch-bis for next hidden sessions.
;
; emacs build little *.input axiom files.
;
; [C-return] sends one or many lines to axiom
; [C-c C-c] sends a break to axiom.
;
; update axiomRun-command-line and axiomRun-base-directory before use.
; and erase sometimes axiomacs*.input files after you use axiomacs.
; 
; This version is as smaller as possible.
;
; The axiom commands must be at the end of the buffer.
; It's very dangerous to change the buffer before last prompt.
;
; Today there is no history and no save-file, 
; but you can use emacs abilities.
;
; It will be possible to use a debugger, if someone explains me what he want.
; 
; Later custom, colors and read-only area in this mode will perhaps come.
;
 
(provide 'axiom-run)
(defconst axiom-run-mode-version "pre-2005-05" "Version of `axiom-run.el'.")
   
(defvar axiomRun-before-axiom-start-hook nil)
(add-hook 'axiomRun-before-axiom-start-hook 'axiomRun-configure-term-var)

(defun axiomRun-configure-term-var nil
  (if (not (getenv "TERM")) (setenv "TERM" "xterm")))

(defvar axiomRun-commandline "axiom -noht -noclef")

(defvar axiomRun-buffer-name "*Axiom*")

(defvar axiomRun-base-directory "/tmp/")

(defvar axiom-run-mode-map nil "Keyboard for axiom-run-mode.")
(when (not axiom-run-mode-map)
  (let ((map (make-sparse-keymap)))
    (define-key map [(control return)] (function axiomRun-from-edit-to-todo))
    (define-key map [(control c)(control c)] (function axiomRun-send-break))
    (setq axiom-run-mode-map map)))

;
; (almost) all variables are local. 
; 
; There is three area in the buffer 
; 1/ axiom writes results between the first char to axiomRun-marker-todo.
; 2/ After a [C-return] commands are in the todo area, 
;    from axiomRun-marker-todo to axiomRun-marker-edit.
; 3/ The user types his command at the end of the buffer, after
;    axiomRun-marker-edit.
; 
; This edit area begins at the first empty-line, not 
; on the prompt-line. So there are not problems for indent.
;

(defvar axiomRun-process nil)
(defvar axiomRun-buffer-name-history (list axiomRun-buffer-name))

(defun axiom-run-mode ()
  "Major mode version `axiom-run-mode-version' for running Axiom code.
\\<axiom-run-mode-map>
The main work is to run axiom in an emacs buffer.

Available special keys:
\\{axiom-run-mode-map}"
  (interactive)
  (when (mupad-run-mode-control)
    (unless mupad-run-less-questions (mupad-run-commandline-ask))
    (mupad-run-mode-intern)))

(defun axiomRun-axiom-run-p nil
  (cond
    ((and
        (eq major-mode 'axiom-run-mode)
        (boundp 'axiomRun-process)
        (processp axiomRun-process))
      t)
    ((and (boundp 'axiomRun-process) (processp axiomRun-process))
        "Incomplete or missing axiom-run-mode initialisation")
    ((eq major-mode 'axiom-run-mode) "Axiom doesn't run in the buffer")
    (t nil)))

(defun axiom-run nil 
  (interactive)
  (switch-to-buffer axiomRun-buffer-name)
  (axiomRun-before-axiom-start-in-buffer))

(defun axiom-batch nil 
  (interactive)
  (let ((oldbuf (current-buffer)))
    (save-excursion
      (get-buffer-create axiomRun-buffer-name)
      (axiomRun-before-axiom-start-in-buffer))))

(defun axiom-run-bis nil  
  (interactive)
  (switch-to-buffer 
    (axiomRun-read-buffer-name 
      "Name of the axiom-buffer : "
      (if (get-buffer "*Axiom*") "*Axiom<2>*" "*Axiom*")))
  (axiomRun-before-axiom-start-in-buffer))

(defun axiom-batch-bis nil 
  (interactive)
  (let ((oldbuf (current-buffer)))
    (save-excursion
      (get-buffer-create 
        (axiomRun-read-buffer-name 
          "Name of the axiom-buffer : "
          (if (get-buffer "*Axiom*") "*Axiom<2>*" "*Axiom*")))
      (axiomRun-before-axiom-start-in-buffer))))

(add-hook 'kill-buffer-hook 'axiomRun-kill-axiom)
(defun axiomRun-kill-axiom nil 
  (and 
     (eq major-mode 'axiom-run-mode)
     (boundp 'axiomRun-processss) 
     (processp axiomRun-process)
     (delete-process axiomRun-process)))

(defun axiomRun-read-buffer-name (prompt &optional initial-input)
  (completing-read prompt
    (mapcar #'(lambda (buf) (list (buffer-name buf))) (buffer-list))
    ;; don't take buffers that start with a blank
    #'(lambda (list) (not (eq (aref (car list) 0) ? )))
    nil
    initial-input))

(defun axiomRun-before-axiom-start-in-buffer nil
  (let ((tmp (axiomRun-axiom-run-p)))
    (cond 
      ( (eq tmp nil) (axiomRun-axiom-start-in-buffer))
      ( (eq tmp t) nil)
      ( t (error tmp)))))  

(defun axiomRun-axiom-start-in-buffer nil
  (run-hooks 'axiomRun-before-axiom-start-hook)
  (kill-all-local-variables)
  (use-local-map axiom-run-mode-map)
  (mapcar (lambda (var) (make-local-variable var))
    '(axiomRun-process axiomRun-output-str axiomRun-kernel-state
      axiomRun-marker-begin-last-output 
      axiomRun-marker-todo axiomRun-marker-edit 
      axiomRun-item-results axiomRun-item-todo))
  (setenv "COLUMNS" (format "%d" (frame-width)))
  (setq major-mode 'axiom-run-mode)
  (setq mode-name "axiom-run")
  (setq axiomRun-marker-begin-last-output (make-marker))
  (setq axiomRun-marker-todo (make-marker))
  (set-marker axiomRun-marker-todo (point))
  (setq axiomRun-marker-edit (make-marker))
  (set-marker axiomRun-marker-edit (point))
  (setq axiomRun-item-results 1)
  (setq axiomRun-item-todo 1)
  (setq axiomRun-output-str "")
  (setq axiomRun-kernel-state 'run)
  (setq axiomRun-process 
    (apply 
      (function start-process)
      (buffer-name)
      (current-buffer) 
      (split-string axiomRun-commandline)))
  (set-process-filter axiomRun-process 'axiomRun-filter))

(defun axiomRun-filter (proc str)
  (let ((oldbuf (current-buffer)))
    (axiomRun-debug "in filter" "START : in-filter")
    (set-buffer (process-buffer proc))
    (save-excursion
      (goto-char axiomRun-marker-todo)
      (setq tmp-pos (point))
      (insert-before-markers str)
      (axiomRun-kernel-state))
    (axiomRun-debug "in filter" "END   : in filter")
    (set-buffer oldbuf)))

(defun axiomRun-kernel-state nil
  (when 
    (and 
      (eq axiomRun-kernel-state 'begin)
      (goto-char (1+ axiomRun-marker-begin-last-output))
      (looking-at "\\(\015(.*) -> \015\\)"))
    (delete-region (point) (match-end 1))
    (setq axiomRun-kernel-state 'run))
  (when 
    (and 
      (eq axiomRun-kernel-state 'after-quit)
      (goto-char (1+ axiomRun-marker-begin-last-output))
      (looking-at "\015"))
    (delete-region (point) (1+ (point)))
    (setq axiomRun-kernel-state 'run))
 (goto-char axiomRun-marker-todo)
 (beginning-of-line)
 (when 
   (and 
     (posix-looking-at "\\(^(.*) -> \\)")  
     (= (match-end 1) (marker-position axiomRun-marker-todo)))
   (goto-char axiomRun-marker-todo)
   (insert-before-markers "\n")
   (setq axiomRun-kernel-state 'wait)
   (axiomRun-from-todo-to-axiom))
 (when (and (eq axiomRun-kernel-state 'run) (posix-looking-at "^\015"))
   (delete-char 1)
   (setq axiomRun-kernel-state 'quit)))
     
(defun axiomRun-from-edit-to-todo nil
  (interactive)
  (axiomRun-debug "in from-edit-to-todo" "START : from-edit-to-todo")
  (let (tmp-pos tmp-block)
    (cond 
      ( (and
          (<
            (marker-position axiomRun-marker-todo)
            (marker-position axiomRun-marker-edit))
          (memq axiomRun-kernel-state '(wait quit)))
        (axiomRun-from-todo-to-axiom)
        (axiomRun-from-edit-to-todo))
      ( (eq (marker-position axiomRun-marker-edit) (point-max))
        (goto-char (point-max)))
      ( t 
       (axiomRun-from-edit-to-todo-aux)
       (axiomRun-from-edit-to-todo)
  (axiomRun-debug "in from-edit-to-todo" "END : from-edit-to-todo")))))

(defun axiomRun-from-edit-to-todo-aux nil
  (axiomRun-debug "in from-edit-to-todo-aux" "START : from-edit-to-todo-aux")
  (goto-char axiomRun-marker-edit)
  (unless (posix-search-forward "^ *$" nil t)(goto-char (point-max)))
  ; the current point is now at the end of the first empty line
  (if (< (point) (point-max)) (forward-char 1)) 
  ; the current point is now at the beginning of a new line
  ; this loop jumps over all the empty-line, 
  ; and goes at the beginning of the first new block
  (while (and (< (point) (point-max))(posix-looking-at "\\(^ *$\\)"))
    (goto-char (match-end 1))
    (if (< (point) (point-max)) (forward-char 1)))
  ;  insert a new line at the end of the buffer without new-line
  (if (< (point-at-bol) (point)) (insert "\n"))
  (setq tmp-block (buffer-substring axiomRun-marker-edit (point)))
  (delete-region axiomRun-marker-edit (point))
  (goto-char axiomRun-marker-edit)
  (setq tmp-pos (point))
  ; the command is now in the todo area
  (insert-before-markers tmp-block)
  ; the at the beginning of the todo area must go back in this case
  (if 
    (= 
      (marker-position axiomRun-marker-edit)
      (marker-position axiomRun-marker-todo))
    (set-marker axiomRun-marker-todo tmp-pos))
    (put-text-property tmp-pos (point) 'axiomRun-todo axiomRun-item-todo)
    (setq axiomRun-item-todo (1+ axiomRun-item-todo))
  (axiomRun-debug "in from-edit-to-todo-aux" "END   : from-edit-to-todo-aux"))

(defun axiomRun-from-string-to-input-file (str)
  (let 
    ( (tmp-file-name
       (concat 
         axiomRun-base-directory 
         (format "axiomacs-%d-%03d.input" 
           (process-id axiomRun-process) axiomRun-item-results))))
    (with-temp-buffer (insert str) (write-file tmp-file-name))
  tmp-file-name))

(defun axiomRun-from-todo-to-axiom nil
  (interactive)
  (if 
    (/= 
      (marker-position axiomRun-marker-todo)
      (marker-position axiomRun-marker-edit))
    (axiomRun-from-todo-to-axiom-aux)))

(defun axiomRun-from-todo-to-axiom-aux nil
  (axiomRun-debug "in from-todo-to-axiom-aux" "START : from-todo-to-axiom-aux")
  (cond 
    ( (eq axiomRun-kernel-state 'wait) 
      (axiomRun-from-todo-to-axiom-file))
    ( t (axiomRun-from-todo-to-axiom-line)))
  (axiomRun-debug "in from-todo-to-axiom-aux" "END : from-todo-to-axiom-aux"))

(defun axiomRun-from-todo-to-axiom-file nil
  (axiomRun-debug 
    "in from-todo-to-axiom-file" 
    "START : from-todo-to-axiom-file")
  (let ((tmp-pos (marker-position axiomRun-marker-todo))
        tmp-pos2 tmp-str tmp-file)
    (goto-char axiomRun-marker-todo)
    (setq tmp-pos2 
      (or 
        (next-single-property-change (point) 'axiomRun-todo) 
        axiomRun-marker-edit))
    (setq tmp-str (buffer-substring tmp-pos tmp-pos2))
    (delete-region tmp-pos tmp-pos2)
    (setq tmp-file (axiomRun-from-string-to-input-file tmp-str))
    (goto-char axiomRun-marker-todo)
    (setq axiomRun-item-results (1+ axiomRun-item-results))
    (setq axiomRun-kernel-state 'begin)
    (backward-char 1)
    (set-marker axiomRun-marker-begin-last-output (point))
    (process-send-string axiomRun-process (concat ")read " tmp-file "\n"))
  (axiomRun-debug "in from-todo-to-axiom" "END : from-todo-to-axiom")))

(defun axiomRun-from-todo-to-axiom-line nil
  (axiomRun-debug 
    "in from-todo-to-axiom-line" 
    "START : from-todo-to-axiom-line")
  (let ((tmp-pos (marker-position axiomRun-marker-todo))
        tmp-pos2 tmp-str tmp-file)
    (goto-char axiomRun-marker-todo)
    (end-of-line)
    (setq tmp-pos2 (1+ (point)))
    (setq tmp-str (buffer-substring axiomRun-marker-todo tmp-pos2))
    (delete-region axiomRun-marker-todo tmp-pos2)
    (goto-char axiomRun-marker-todo)
    (setq axiomRun-item-results (1+ axiomRun-item-results))
    (setq axiomRun-kernel-state 'after-quit)
    (backward-char 1)
    (set-marker axiomRun-marker-begin-last-output (point))
    (process-send-string axiomRun-process tmp-str)
  (axiomRun-debug 
     "in from-todo-to-axiom-line" 
     "END : from-todo-to-axiom-line")))

(defun axiomRun-send-edit-to-axiom nil 
  (interactive)
  (let ((tmp (buffer-substring axiomRun-marker-edit (point-max))))
    (save-excursion
      (delete-region axiomRun-marker-edit (point-max))
      (process-send-string axiomRun-process (concat tmp "\n")))))

(defun axiomRun-send-break nil 
  (interactive)
  (process-send-string axiomRun-process "\003"))

; (defun axiomRun-from-todo-to-result nil)

(defun axiomRun-get-prop nil 
  (interactive)
  (let ((tmp (get-text-property (point) 'axiomRun-todo)))
    (if (not tmp) (message "NIL") (message (format "numero : %d" tmp)))))

(defun axiomRun-next-change nil
  (interactive)
  (goto-char 
    (or (next-single-property-change (point) 'axiomRun-todo) (point-max))))

(defvar axiomRun-debug-list '())
; (defun axiomRun-debug (name message) (message name))
 (defun axiomRun-debug (name message) nil)



_______________________________________________
Axiom-mail mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/axiom-mail

--
forwarded from http://page.axiom-developer.org/zope/mathaction/address@hidden




reply via email to

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