dtach emacs

I like using emacs as a launcher for other programs. However, it's inconvenient when Emacs crashes for some reason, and all your programs die as well.

So, here is an example how to use dtach to avoid having the program die, and be recovered by emacs next time around.

 1(defun bankid ()
 2  (interactive)
 3  ;;important! check if there is a process already
 4  (if  (get-process "bankid-process")
 5      (message "already running")
 6    (start-process-dtach "bankid-process" "bankid-process" "qemu-kvm"
 7	   "-m"
 8	   "512"
 9	   "-hda"
10	   "/home/joakim/android-x86/joakim-bankid2.img"
11	   "-vga"
12	   "std"
13	   "-usbdevice"
14	   "tablet"
15	   )))
16
17(defun start-process-dtach ( name buffer program &rest program-args)
18;; start program and create a dtach socket for it, with name .emacs.d/dtach/name
19;; if the socket exists, attach to it
20  (eval  `(start-process ,name ,buffer "dtach" "-A" ,(expand-file-name (concat user-emacs-directory "dtach/" name)) ,program  ,@program-args)))