From d0960305e0606817ce620c3dee240e668521388b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 21 Oct 2021 00:31:03 +0200 Subject: Emacs: Improve launch-program --- .emacs.d/init.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 6d27d71..6405bf1 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -270,11 +270,16 @@ the only window in the frame." ;;; Processes (defun launch-program (command) + "Launch program in the background (or foreground if COMMAND ends with semicolon)." (interactive (list (read-shell-command "Launch program: "))) - (make-process :name command - :buffer "*launch-program*" - :filter #'launch-program-filter - :command (list shell-file-name shell-command-switch command)) + (let ((name command)) + (when (not (string= ";" (substring command -1 nil))) + (setq name (concat command "&")) + (setq command (concat "which " (car (split-string command)) ">/dev/null&&" command "&"))) + (make-process :name name + :buffer "*launch-program*" + :filter #'launch-program-filter + :command (list shell-file-name shell-command-switch command))) (switch-to-buffer "*launch-program*") (bury-buffer "*launch-program*")) (defun launch-program-filter (proc string) -- cgit v1.2.3