hyperlogic
hyperlogic

Reputation: 7745

How do I speed up emacs output from an asynchronous shell-command?

I'm running the output of an application in an emacs buffer using shell-command.

(shell-command "verbose-app &" "*verbose-app*")

The problem is this command is extremely verbose. So much so, that it sometimes takes several seconds for the emacs buffer to catch up. It lags by several seconds with the actual output.

Is there any way I can speed up the output scrolling by disabling something? Like regex-matching or syntax highlighting?

For future reference:

The verbose app is adb logcat. I changed my existing function:

(defun adb-logcat ()
  (interactive)
  (shell-command "adb logcat -v threadtime&" "*adb-logcat*")
  (pop-to-buffer "*adb-logcat*")
  (buffer-disable-undo))

To the following:

(defun adb-logcat ()
  (interactive)
  (start-process "*adb-logcat*" "*adb-logcat*" "/bin/sh" "-c" "adb logcat -v threadtime")
  (pop-to-buffer "*adb-logcat*")
  (buffer-disable-undo))

It scrolls way faster now. Yay!

Upvotes: 19

Views: 1317

Answers (2)

tripleee
tripleee

Reputation: 189809

Like the documentation says, shell-command runs the command in an inferior shell, implying shell-mode. If you just want the output and none of the features, running the command with start-process may be closer to what you want.

(start-process "*verbose-app*" "*verbose-app*"
 "/bin/sh" "-c" "verbose-app")

Wrapping this into a function should not be too hard. You might want to look at how shell-command implements async commands; for example, it will ask whether it should terminate an existing process if you attempt to create one when another already exists. http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/simple.el#n2447 might be a good starting point. (In case the link goes bad, this is a link to inside defun shell-command, pointing to a a comment about handling the ampersand. If it's there, the command will be run asynchronously.)

Upvotes: 10

Ryan C. Thompson
Ryan C. Thompson

Reputation: 42090

If the command is that verbose, is there any use in capturing the full output in real time? Maybe you could run verbose-app > app.log in the background and then run something like while true; do tail -n50 app.log; sleep 1; done within emacs to keep updating the buffer to view the last few lines of the log file. Later when you want the full output you can open the log file in emacs.

Upvotes: 0

Related Questions