I have this snippet of code:
(async-shell-command
(concat "perl myscript.pl " (buffer-name))
(read-string "RETURN: ")
(with-temp-file "file.new"
(insert-file-contents "file.new")
(perform-replace "REGEXP"
"REPLACEMENT"
nil nil nil 1 nil (point-min) (point-max))))
This makes my perl
script run on the file visited by buffer and returns a file file.new
. I can see the stdout
displayed dynamically in the buffer \*Async Shell Command\*
, step by step. Then I need to perform some replacements in file.new
. Because of the asyncronicity of the process I need to put a read-string
to pause my elisp program.
I'd like to sobstitute the async-shell-command
with a synchronous command but keeping the dynamically diplayed buffer.
Addedum. Here's another little example of what I mean:
(async-shell-command "echo \"bye\"; sleep 3; echo \"bye\"")
this code will display the first "bye" string in the *Async Shell Command* buffer, than the second "bye" string will be displayed after 3 seconds.
I'd like to have shell-command
behaving the same, e.g.:
(shell-command "echo \"bye\"; sleep 3; echo \"bye\"")
I tried to modify the async-shell-command
this way:
(defun my-sync-shell-command (command &optional output-buffer error-buffer)
"DocString"
(interactive
(list
(read-shell-command "Sync shell command: " nil nil
(let ((filename
(cond
(buffer-file-name)
((eq major-mode 'dired-mode)
(dired-get-filename nil t)))))
(and filename (file-relative-name filename))))
current-prefix-arg
shell-command-default-error-buffer))
;; I commented these lines to remove the ending "&" sign:
;; (unless (string-match "&[ \t]*\\'" command)
;; (setq command (concat command)))
(shell-command command output-buffer error-buffer))
but it didn't work.