Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Emacs run command in background

Tags:

emacs

elisp

I have an Emacs command like following:

(defun query-lisp (word)
  (interactive "sType a word to query:")
  (message "%s" (query word)))

The query operation is a time-consuming operation. When this command is running Emacs blocks the whole frame. Is there a way to make Emacs run this command in the background or block only a single window such as the minibuffer?

like image 551
DouO Avatar asked Dec 28 '11 08:12

DouO


People also ask

How do I run commands in Emacs?

You can run any Emacs command by name using M-x , whether or not any keys are bound to it. If you use M-x to run a command which also has a key binding, it displays a message to tell you about the key binding, before running the command.

How do I run a shell command in Emacs?

You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.

How do I run a buffer in Emacs?

Emacs displays the buffer in a full-screen window. If you want to display one of the buffers in place of the buffer list, you can press f. To put a buffer in another window (i.e., one not occupied by the buffer list), type o. Emacs displays the buffer in the other window and puts the cursor there.

How to exit Emacs?

When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt. To quit Emacs permanently, type C-x C-c.


1 Answers

If you plan to use an external process (which you have indicated in a comment to another question), you can use the following:

 (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)

This will return a process object. You can either send the output to a buffer, or you could attach a filter function to the process. In the latter case, this is a function that is called every time your process emits any output.

In addition, you could attach a sentinel function to your process. This function is called everytime the status of your process changes, this is useful to find out when it has exited.

There are several examples of the above in the source code of Emacs, one such example is compile.el.

like image 52
Lindydancer Avatar answered Sep 20 '22 06:09

Lindydancer