dtach emacs

Share on:

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.

(defun bankid ()
  (interactive)
  ;;important! check if there is a process already
  (if  (get-process "bankid-process")
      (message "already running")
    (start-process-dtach "bankid-process" "bankid-process" "qemu-kvm"
           "-m"
           "512"
           "-hda"
           "/home/joakim/android-x86/joakim-bankid2.img"
           "-vga"
           "std"
           "-usbdevice"
           "tablet"
           )))

(defun start-process-dtach ( name buffer program &rest program-args)
;; start program and create a dtach socket for it, with name .emacs.d/dtach/name
;; if the socket exists, attach to it
  (eval  `(start-process ,name ,buffer "dtach" "-A" ,(expand-file-name (concat user-emacs-directory "dtach/" name)) ,program  ,@program-args)))