Alfredo Di Napoli avatar Alfredo Di Napoli committed 76038ca

Fixed a couple of bugs that halted vim

Comments (0)

Files changed (1)

ftplugin/ocaml.vim

   let g:beduino_default_terminal = "xterm"
 endif
 
+if !exists("g:beduino_buffer_location")
+  let g:beduino_buffer_location = system("echo $PWD")_. "/.beduino.buff"
+endif
+
 python << EOF
 import vim
 import os
+import subprocess
 
 def write_to_buffer():
   f = open("beduino.buff", "w")
   f.write(";;")
   f.write(os.linesep)
   f.close()
+
+def beduino_eval_visual():
+  #First write the content of the visual selection in a buffer
+  write_to_buffer()
+
+  #For each line, paste in in Tmux (can be very slow, let's try)
+  f = open("beduino.buff", "r+")
+  lines = f.readlines()
+  for l in lines:
+    #Paste in tmux
+    f.write(l)
+    subprocess.call(["tmux", "load-buffer", "beduino.buff"])
+    subprocess.call(["tmux", "pasteb", "-t", "beduino"])
+
+  f.close()
 EOF
 
 "Connect to repl
   endif
 endfun
 
+fun! BeduinoSessionExists()
+  let w:sessions = system("tmux list-session | grep beduino")
+  if (w:sessions != "")
+    return 1
+  else
+    return 0
+  endif
+endfun
+
 fun! BeduinoEvalBuffer()
   let b:buffer_name = expand("%:p")
   let b:use_cmd = "#use \"". b:buffer_name ."\";;"
   call system("echo \"". escape(b:use_cmd,"\"") ."\" > beduino.buff")
-  call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
+  if BeduinoSessionExists()
+    call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
+  endif
 endfun
 
 function! s:NumSort(a, b)
 endfunction
 
 fun! BeduinoEvalVisual()
-  let g:selected_text = s:GetVisualSelection()
-  python write_to_buffer()
-  call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
-endfun
-
-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")
+  if BeduinoSessionExists()
+    let g:selected_text = s:GetVisualSelection()
+    python beduino_eval_visual()
   endif
 endfun
 
 fun! BeduinoCloseSession()
-  if g:beduino_owner == getpid()
-    call system("tmux kill-session -t beduino")
+  if BeduinoSessionExists()
+    if g:beduino_owner == getpid()
+      call system("tmux kill-session -t beduino")
+    endif
   endif
 endfun
 
 map <LocalLeader>bb :call BeduinoEvalBuffer()<RETURN>
 
 "Mnemonic: Beduino (Eval) Visual (Selection)
-map <LocalLeader>bv :call BeduinoEvalVisual()<RETURN>
+vmap <LocalLeader>bv :call BeduinoEvalVisual()<RETURN>
 
 "Kill Beduino before exiting Vim
-autocmd VimLeavePre * call BeduinoCloseTopLevel()<RETURN>
-autocmd VimLeave * call BeduinoCloseSession()<RETURN>
+autocmd VimLeavePre * call BeduinoCloseSession()<RETURN>
 
 " vim:sw=2
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.