I'm looking for a way to create a buffer and immediately hide it. It is a buffer for technical information, not interesting to the user, and it is used with shell-command
to process the output.
kill-buffer
- is not what I need, because I need that buffer to be live.
delete-window
- doesn't do it either because there's no way to make sure how exactly the buffer will open (it may create a new window or may take over another window).
It doesn't help if I create the buffer before supplying it to shell-command
Regardless of whether it existed before, it will bring it to front and, if there was only one window at the time it did it, it will create an additional window, but if there were more windows, then it basically does something random. Some times it will create a new window... other times it won't.
EDIT:
The example below illustrates the problem:
(defun haxe-start-waiting-server (&optional compiler host port)
"Starts Haxe `haxe-compiler' on `haxe-server-host':`haxe-server-port'
with \"--wait\" for the future requests made by autocompletion
or flymake.
This function is bound to \\[haxe-start-waiting-server]"
(interactive
(let ((compiler-i
(read-string "Haxe compiler: "
haxe-compiler t haxe-compiler))
(host-i
(read-string "Haxe server host: "
haxe-server-host t haxe-server-host))
(port-i
(read-number "Haxe server port: " haxe-server-port)))
(list compiler-i host-i port-i)))
(unless (called-interactively-p 'interactive)
(unless compiler (setq compiler haxe-compiler))
(unless host (setq compiler haxe-server-host))
(unless port (setq compiler haxe-server-port)))
(save-excursion
(let ((new-buffer
(get-buffer-create
(generate-new-buffer-name
" *haxe-waiting-server*"))))
(async-shell-command
(concat compiler " --wait "
host ":" (number-to-string port))
new-buffer)
(bury-buffer new-buffer))))
If you want everything to happen in the background, you may need save-window-excursion
instead of save-excursion
.