1

I often find myself wondering how people handle program arguments when they are developing with Emacs. Let's say we have a Python script test.py and launching it requires supplying arguments, e.g. --fname example.txt. Most major modes feature a generic function like python-shell-send-buffer that effectively launches the script without supplying arguments.

Of course one solution would be to adapt test.py to not take any arguments by hard-coding default arguments but this can hardly be considered good practice.

How is this issue typically handled? (not necessarily Python-specific)

  • There are several options depending on what you're trying to achieve. Take a look at `shell-command` for example. There's also its async cousin, called `async-shell-command`. But I'd actually recommend you to use `compile`, which is a general way to start an async process and have its output sent to the `*compilation*` buffer. Please eval the following s-exp to read the relevant Emacs manual section: `(info "(emacs) Compilation")`. – aadcg Sep 18 '21 at 15:42
  • Also notice that `python-shell-send-buffer` is a different beast. It starts a python interpreter (unless it's running already) and sends the contents of the buffer to it. Basically, you're just sending expressions to be evaluated by the interpreter. Informally, your editor builds up a communication bridge between the source (the python program) and the interpreter (a process in your OS). – aadcg Sep 18 '21 at 15:49

1 Answers1

0

The general approach is to leverage compile.

You can find more information in the Emacs manual by evaluating (info "(emacs) Compilation").

Here's another good article by Mickey Petersen.

aadcg
  • 1,203
  • 6
  • 13