Question

I am writing a comint-mode for a python script.

The script can be launched with :

/usr/bin/python3.3 tool-name arg0

I am using comint-mode since this call will ask in the prompt some information before running.

If I create :

(defun create-app ()
  "create application by using python tool"
  (interactive)
  (progn 
    (setq default-directory "/path/to/tool")
    (setq buffer (get-buffer-create "*buffer_name*"))
    (apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil nil)
    )
  )

everything works fine and python is launched but if I write :

(defun create-app ()
  "create application by using python tool"
  (interactive)
  (progn 
    (setq default-directory "/path/to/tool")
    (setq buffer (get-buffer-create "*buffer_name*"))
    (apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3 tool-name arg0" nil nil)
    )
  )

the buffer tells me that it cannot exec program "/usr/bin/python3.3 tool-name arg0"

Does anyone have an idea (with or without comint) how I can launch this python process and have the script asking some information before launch ?

Was it helpful?

Solution

The docstring of make-comint-in-buffer (C-hfmake-comint-in-bufferRET) states the following

(make-comint-in-buffer NAME BUFFER PROGRAM &optional STARTFILE &rest
SWITCHES)

Make a Comint process NAME in BUFFER, running PROGRAM.
If BUFFER is nil, it defaults to NAME surrounded by `*'s.
If there is a running process in BUFFER, it is not restarted.

PROGRAM should be one of the following:
- a string, denoting an executable program to create via
  `start-file-process'
- a cons pair of the form (HOST . SERVICE), denoting a TCP
  connection to be opened via `open-network-stream'
- nil, denoting a newly-allocated pty.

...

If PROGRAM is a string, any more args are arguments to PROGRAM.

So the correct way to use the function is to have the only name of the program as a string and pass the arguments to be passed to the program, as additional arguments to make-comint-in-buffer as follows

(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil "tool-name" "arg0")

OTHER TIPS

You have to put tool-name and arg0 outside of the string. Do you want to ask the user interactively ? You can easily do that, see http://ergoemacs.org/emacs/elisp_basics.html (in the end).

exple:

defun myFunc (firstArg)
  (interactive "sWhat is first arg ? ") ;; note the s
  ( ;; use firstArg)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top