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

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

comint and point


From: Martin Rubey
Subject: comint and point
Date: 01 Oct 2007 08:43:02 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Dear all,

I'm still having a bad time with sending stuff to a proces, parsing the output
and deleting stuff and its output in comint mode.  The thing that worries me
most: I have no idea what's going out and how things are intended to work.

The bigger picture is as follows: I'm writting a specialised mode derived from
comint for a computer algebra system called axiom.  It does things like color
the output and make it read only, and enable tab-completion for file names if
the user is currently entering a system command, etc...

For the latter feature, I need to track the directory I'm in.  So here's the
plan: 

I can assume that we are just after an axiom prompt.

* delete the prompt

* send the axiom command ")sys pwd" to the axiom process, which will spit out
  the directory name.

* move a line backwards and to the end of this line

* cd to the directory, which is given by the text in the current line

* delete the line

The following code works roughly, as long as I'm using emacs 21 on X.  It
doesn't seem to work with emacs -nw.

But why do I need these (sit-for 0 100) and (sit-for 0) stuff?  It took me
hours to figure out, and I came to this sequence of commands only by
experimentation.  Could somebody PLEASE explain to me how to reliably position
point.

Many thanks in advance,

Martin


(defun axiom-resync-directory ()
  "Send )sys pwd to the axiom process, parse the result, cd to it and clean up
    output.  Assumes that we are just after a prompt."
  (let* ((inhibit-read-only t)
         (begin (progn (forward-line 0) (point)))
         (end (progn (end-of-line) (point)))
         (dir))
    (delete-region begin end)
    (process-send-string (get-buffer-process (current-buffer)) ")sys pwd\n")
    (sit-for 0 100)
    (forward-line -1)
    (end-of-line)
    (sit-for 0)
    (setq end (point))
    (cd (buffer-substring-no-properties begin end))
    (delete-region (1- begin) end)
    (forward-line 1)
    (end-of-line)))


reply via email to

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