Alfredo Di Napoli committed 197b39a

Only the process who started or attached to Beduino can close it

Comments (0)

Files changed (1)


 "Connect to repl
 fun! BeduinoConnect()
+  "Setup the Vim who own the beduino session. Only him
+  "can shutdown Beduino
+  let g:beduino_owner = getpid()
   let w:sessions = system("tmux list-session | grep beduino")
   if (w:sessions != "")
     "Attach to an already running session
     call system(g:beduino_default_terminal ." -e tmux attach-session -t beduino &")
     echo "Connected."
+    "Change the Beduino owner to be this one
+    let g:beduino_owner = getpid()
     echo "Starting a new Beduino session..."
     call system(g:beduino_default_terminal ." -e tmux new-session -s beduino -n toplevel 'rlwrap ocaml' &")
     echo "Connected."
   call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
+fun! BeduinoCloseTopLevel()
+  if g:beduino_owner == getpid()
+    "Gracefully shutdown the session.
+    let g:selected_text = "#quit"
+    python write_to_buffer()
+    call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
+  endif
 fun! BeduinoCloseSession()
-  call system("tmux kill-session -t beduino")
+  if g:beduino_owner == getpid()
+    call system("tmux kill-session -t beduino")
+  endif
 "Mnemonic: Beduino Connect
 map <LocalLeader>bv :call BeduinoEvalVisual()<RETURN>
 "Kill Beduino before exiting Vim
-autocmd VimLeavePre * call BeduinoCloseSession()<RETURN>
+autocmd VimLeavePre * call BeduinoCloseTopLevel()<RETURN>
+autocmd VimLeave * call BeduinoCloseSession()<RETURN>
 " vim:sw=2