Commits

Alfredo Di Napoli committed 606e079

Found the problem with visual selection, need to find a way to fix it

Comments (0)

Files changed (1)

ftplugin/ocaml.vim

 endif
 
 if !exists("g:beduino_buffer_location")
-  let g:beduino_buffer_location = system("echo $PWD")_. "/.beduino.buff"
+  let g:beduino_buffer_location = substitute(system("echo $PWD"), "\n", "", "g") . "/.beduino.buff"
 endif
 
 python << EOF
 import subprocess
 
 def write_to_buffer():
-  f = open("beduino.buff", "w")
-  f.write(vim.eval("g:selected_text"))
+  beduino_buff = vim.eval("g:beduino_buffer_location") 
+  text_to_write = vim.eval("g:selected_text")
+  print text_to_write
+  f = open(beduino_buff, "w")
+  f.write(text_to_write)
   f.write(";;")
   f.write(os.linesep)
   f.close()
 
 def beduino_eval_visual():
+  beduino_buff = vim.eval("g:beduino_buffer_location") 
   #First write the content of the visual selection in a buffer
   write_to_buffer()
+  subprocess.call(["tmux", "load-buffer", beduino_buff ])
+  subprocess.call(["tmux", "pasteb", "-t", "beduino"])
 
-  #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"])
+def beduino_kill():
+  subprocess.call(["tmux", "kill-session", "-t", "beduino"])
 
-  f.close()
 EOF
 
 "Connect to repl
 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("echo \"". escape(b:use_cmd,"\"") ."\" > ". g:beduino_buffer_location)
   if BeduinoSessionExists()
-    call system("tmux load-buffer beduino.buff; tmux pasteb -t beduino")
+    call system("tmux load-buffer ". g:beduino_buffer_location ."; tmux pasteb -t beduino")
   endif
 endfun
 
   let [lnum1, col1] = getpos("'<")[1:2]
   let [lnum2, col2] = getpos("'>")[1:2]
   let lines = getline(lnum1, lnum2)
-  let lines[-1] = lines[-1][: col2 - 2]
-  let lines[0] = lines[0][col1 - 1:]
-  return join(lines, "\n")
+  "let lines[-1] = lines[-1][: col2 - 2]
+  "let lines[0] = lines[0][col1 - 1:]
+  return join(lines)
 endfunction
 
+" BUGGED: The problem is that is executed for
+" every bloody line in the visual selection,
+" which is no good!
 fun! BeduinoEvalVisual()
   if BeduinoSessionExists()
     let g:selected_text = s:GetVisualSelection()
 fun! BeduinoCloseSession()
   if BeduinoSessionExists()
     if g:beduino_owner == getpid()
-      call system("tmux kill-session -t beduino")
+      python beduino_kill()
+      ""call system("tmux kill-session -t beduino")
     endif
   endif
 endfun