5 votes

How to run a custom formatting tool on save?

This can be done using: call-process-region to run the command and catch the stdout/stderr. replace-buffer-contents to update the region without causing the entire buffer to be replaced. This is ...
ideasman42's user avatar
  • 8,786
5 votes
Accepted

how to do command substitution in eshell generally (NOT just for loop)

I then tried various sorts of C-h and websearch, without success. Please check the manual first! (or second, after docstrings) (eshell) Dollars Expansion: Eshell has different ‘$’ expansion syntax ...
npostavs's user avatar
  • 9,203
5 votes
Accepted

Set environment variables for spawned subprocesses

setenv-internal and setenv change the list stored in process-environment (as local or special variable) by side-effects. It does not help if you assign the list (pointer) to a local variable process-...
Tobias's user avatar
  • 33.2k
5 votes
Accepted

How to attach/connect two subprocesses?

For two processes A and B mutually killing each other you can use the following approach: Start the first process just with start-process and remember its process (as lisp object). Start the second ...
Tobias's user avatar
  • 33.2k
4 votes
Accepted

How does one create back and forth communication to a process

The functionality used by comint mode is start-process, so I think you might like to start with that. You send data to the process with process-send-string, and the process's output is "automatically"...
Stefan's user avatar
  • 26.4k
4 votes
Accepted

Asynchronous version of shell-command-on-region?

Something in this spirit should do the trick. I tried it with espeak under Ubuntu; I guess it would work with say as well. (defun my-read-words-on-region () "Send the region to `espeak'." (...
Nsukami _'s user avatar
  • 6,521
4 votes
Accepted

Execute program on string

You can use call-process-region to send string to a program as standard input, for example, (with-temp-buffer (call-process-region "Hello, World!" nil "cat" nil t nil "-n") (buffer-string)) ;; =&...
xuchunyang's user avatar
  • 14.5k
4 votes
Accepted

start-process: Setting current directory: No such file or directory

Yes, that's the established technique. In my code I use temporary-file-directory instead, but this is just a detail.
Michael Albinus's user avatar
4 votes
Accepted

Looking for a better way to test whether the current Emacs process is running under GNU Screen

Skip all the pid stuff, and just check the STY environment variable. If it is set, then emacs is running inside screen.
db48x's user avatar
  • 18k
3 votes
Accepted

How to partially block user input while Emacs subprocess is running

I suspect that the simplest approach is entirely adequate here. Using a synchronous process will prevent you from inadvertently typing into the wrong buffer -- anything you do type while the command ...
phils's user avatar
  • 51.1k
3 votes
Accepted

How to start a persistent asynchronous process trough emacs?

You can use call-process the same way as you did, but just replace the third argument by 0. If the third argument is 0, Emacs don't wait for the process and quit without killing it. SHELL-PROMPT> ...
Nicolas Mace's user avatar
3 votes
Accepted

Process input seems buggy in Emacs on OS X

Not sure how to fix it (I really mean it: I've tried to fix this bug in the past, but my POSIX-fu is not strong enough), but you can circumvent it by creating your process with process-connection-type ...
Stefan's user avatar
  • 26.4k
3 votes

Set environment variables for spawned subprocesses

Since Emacs 28.1 you can use the with-environment-variables macro. Example: (with-environment-variables (("DESKTOP_SESSION" "TEST_VALUE")) (shell-command "echo $...
flonic's user avatar
  • 41
3 votes

Interpret terminal escape codes in generic process output

You can use "process sentinel" mentioned in @steve-lorimer's answer if it is OK for you to get color AFTER the process is finished, otherwise you should use "process filter" instead. Take command ...
xuchunyang's user avatar
  • 14.5k
3 votes
Accepted

How to stop a subprocess?

On my system, yes doesn't react to SIGTSTP, which is the signal sent by stop-process (rather than SIGSTOP as one might assume). When you run yes in your terminal and shell, C-z is going to ...
phils's user avatar
  • 51.1k
2 votes
Accepted

How can Emacs set an environment/shell variable in a subordinate shell?

After (re)reading the code of the shell function, here's what I'd do: (advice-add 'make-comint-in-buffer :around #'my-enable-auto-save-in-shell) (defun my-enable-auto-save-in-shell (...
Stefan's user avatar
  • 26.4k
2 votes

Set environment variables for spawned subprocesses

The "let binding" way is the following (notice that contrary to Tobias's answer, this does not involve any copying or "set"ting): (let ((process-environment (cons "HOME" (cons (...
Stefan's user avatar
  • 26.4k
2 votes
Accepted

How can I run a subprocess with emacs --script

Basically, Emacs exits before the subprocess has exited. All you have to do is delay the exit until the subprocess has exited. Since Emacs does not have anything useful to do, you can have it sleep ...
NickD's user avatar
  • 29.8k
2 votes

Cannot paste text copied from Emacs to synchronous subprocess

There are several ways of copying text between programs on Linux. I'm just guessing that you're using Linux, but I don't think that this problem could occur on Windows or OSX. I also surmise that you'...
db48x's user avatar
  • 18k
2 votes

Convenient piping for multiple processes?

This utility function takes list arguments, each one is a commend that is piped to the next command. :input keyword argument for input from buffer/string (or nil for none). :output keyword argument ...
ideasman42's user avatar
  • 8,786
1 vote

Troubleshooting a hanging `list-processes`

If this happens it means that Emacs is having trouble communicating with some subprocess. It is a good idea to leave Emacs and look at its subprocesses from the hosting operating system. For example, ...
Matthew Piziak's user avatar
1 vote
Accepted

Multi-processing via TRAMP with asynchronous shell commands

The quoted limitation does not exist any longer. Moreover, the function tramp-adb-handle-shell-command does not exist any longer. All different implementations of shell-command in Tramp have been ...
Michael Albinus's user avatar
1 vote

How to let make-process prompt user in echo area

TRAMP does a pretty ugly hack to detect a network process prompting for input, it uses regex matching to detect a printed prompt, then asks for user input using tramp-read-passwd. This will obviously ...
wasamasa's user avatar
  • 22.2k
1 vote
Accepted

How to run a command via elisp, completely ignoring its output and status? (fire and forget)

call-process, despite normally being used for synchronous process calls: call-process is a built-in function in `C source code'. (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &...
npostavs's user avatar
  • 9,203
1 vote
Accepted

redirect stderr to a file in call-process-region

You don't need the (:file ) just give the error file as second element in the list. BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, REAL-BUFFER says what to do with standard ...
jue's user avatar
  • 4,576
1 vote

Cleanly terminating asynchronous process after it reads stdin

Turns out I was doing this correctly, and the process was correctly returning a 1 result. So the posted code is the correct thing to do.
abingham's user avatar
  • 927
1 vote
Accepted

Wait for (tex-file) to execute before go on with an elisp script

I found a solution to my problem here: https://stackoverflow.com/questions/23021875/wait-on-shell-command-to-finish-before-executing-another-elisp-command I resolved by using: (call-process-shell-...
Gabriele's user avatar
  • 1,554
1 vote

How can Emacs set an environment/shell variable in a subordinate shell?

You can use the with-environment-variables macro. (let ((buffer-auto-save-file-name "test-file.txt")) (with-environment-variables (("BUFFER_AUTO_SAVE_FILE_NAME" buffer-auto-save-...
flonic's user avatar
  • 41
1 vote

How can Emacs set an environment/shell variable in a subordinate shell?

(let ((process-environment `(,(concat "BUFFER_AUTO_SAVE_FILE_NAME=" buffer-auto-save-file-name) ,@process-environment))) (shell))
politza's user avatar
  • 3,336
1 vote

How can Emacs set an environment/shell variable in a subordinate shell?

Add the following to the end of your lambda() routine: (goto-char (point-max)) (insert (concat "export EMACS_AS_FILE=" buffer-auto-save-file-name)) The shell command to assign your variable will ...
GLRoman's user avatar
  • 146

Only top scored, non community-wiki answers of a minimum length are eligible