Skip to content

Commit 9960430

Browse files
jalvesaqvim-scripts
authored andcommitted
Version 1.2.5
* New command to evaluate selection and get output in newtab: \so * The command \ao no longer blocks Vim. * New command (\rv) and new options (vimrplugin_csv_warn, vimrplugin_csv_app and vimrplugin_df_viewer). * Bring back the "echo" send commands because some users need them.
1 parent c294964 commit 9960430

13 files changed

+414
-253
lines changed

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This is a mirror of http://www.vim.org/scripts/script.php?script_id=2628
22

3-
This plugin improves Vim's support for editing R code and makes it possible to integrate Vim with R. The functionality is similar to what you can find in Tinn-R and ESS mode of Emacs. This filetype plugin uses Tmux (Linux, OS X, or other Unix) or Python (Microsoft Windows) or Apple Script (Mac OS X) to send commands to R. The communication with R also depends on the R package vimcom.
3+
This plugin improves Vim's support for editing R code and makes it possible to integrate Vim with R. The functionality is similar to what you can find in Tinn-R and ESS mode of Emacs. This filetype plugin uses Tmux (Linux, OS X, or other Unix) or a C library (Microsoft Windows) or Apple Script (Mac OS X) to send commands to R. The communication with R also depends on the R package vimcom.
44

55
Screenshots and Debian package: http://www.lepem.ufc.br/jaa/vim-r-plugin.html
66
Comments and general questions: https://groups.google.com/forum/#!forum/vim-r-plugin

doc/r-plugin.txt

+118-72
Large diffs are not rendered by default.

ftplugin/r_rplugin.vim

+26-25
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,39 @@ function! ShowRout()
3030
call delete(b:routfile)
3131
endif
3232

33-
if !exists("b:rplugin_R")
34-
call SetRPath()
35-
endif
36-
3733
" if not silent, the user will have to type <Enter>
3834
silent update
3935

4036
if has("win32") || has("win64")
4137
let rcmd = 'Rcmd.exe BATCH --no-restore --no-save "' . expand("%") . '" "' . b:routfile . '"'
4238
else
43-
let rcmd = b:rplugin_R . " CMD BATCH --no-restore --no-save '" . expand("%") . "' '" . b:routfile . "'"
39+
let rcmd = g:rplugin_R . " CMD BATCH --no-restore --no-save '" . expand("%") . "' '" . b:routfile . "'"
4440
endif
4541

46-
echon "Please wait for: " . rcmd
47-
redraw
48-
let rlog = system(rcmd)
49-
if v:shell_error && rlog != ""
50-
call RWarningMsg('Error: "' . rlog . '"')
51-
sleep 1
52-
endif
53-
if filereadable(b:routfile)
54-
if g:vimrplugin_routnotab == 1
55-
exe "split " . b:routfile
42+
if has("win32") || has("win64") || v:servername == ""
43+
echon "Please wait for: " . rcmd
44+
redraw
45+
let rlog = system(rcmd)
46+
if v:shell_error && rlog != ""
47+
call RWarningMsg('Error: "' . rlog . '"')
48+
sleep 1
49+
endif
50+
if filereadable(b:routfile)
51+
if g:vimrplugin_routnotab == 1
52+
exe "split " . b:routfile
53+
else
54+
exe "tabnew " . b:routfile
55+
endif
56+
set filetype=rout
5657
else
57-
exe "tabnew " . b:routfile
58+
call RWarningMsg("The file '" . b:routfile . "' is not readable.")
5859
endif
59-
set filetype=rout
6060
else
61-
call RWarningMsg("The file '" . b:routfile . "' is not readable.")
61+
let shlines = [rcmd,
62+
\ 'vim --servername ' . v:servername . " --remote-expr '" . 'GetROutput("' . b:routfile . '")' . "'",
63+
\ 'rm "' . g:rplugin_tmpdir . '/runRcmdbatch.sh' . '"']
64+
call writefile(shlines, g:rplugin_tmpdir . '/runRcmdbatch.sh')
65+
call system('sh "' . g:rplugin_tmpdir . '/runRcmdbatch.sh" >/dev/null 2>/dev/null &')
6266
endif
6367
endfunction
6468

@@ -75,18 +79,15 @@ endfunction
7579

7680
let b:IsInRCode = function("DefaultIsInRCode")
7781

78-
" Pointer to function that must be different if the plugin is used as a
79-
" global one:
80-
let b:SourceLines = function("RSourceLines")
81-
8282
"==========================================================================
8383
" Key bindings and menu items
8484

8585
call RCreateStartMaps()
8686
call RCreateEditMaps()
8787

8888
" Only .R files are sent to R
89-
call RCreateMaps("ni", '<Plug>RSendFile', 'aa', ':call SendFileToR()')
89+
call RCreateMaps("ni", '<Plug>RSendFile', 'aa', ':call SendFileToR("silent")')
90+
call RCreateMaps("ni", '<Plug>RESendFile', 'ae', ':call SendFileToR("echo")')
9091
call RCreateMaps("ni", '<Plug>RShowRout', 'ao', ':call ShowRout()')
9192

9293
" Knitr::spin
@@ -107,7 +108,7 @@ endif
107108
call RSourceOtherScripts()
108109

109110
if exists("b:undo_ftplugin")
110-
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:SourceLines"
111+
let b:undo_ftplugin .= " | unlet! b:IsInRCode"
111112
else
112-
let b:undo_ftplugin = "unlet! b:IsInRCode b:SourceLines"
113+
let b:undo_ftplugin = "unlet! b:IsInRCode"
113114
endif

ftplugin/rbrowser.vim

-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ unlet s:envstring
355355

356356
call setline(1, ".GlobalEnv | Libraries")
357357

358-
let b:SourceLines = function("RSourceLines")
359-
360358
call RSourceOtherScripts()
361359

362360
let &cpo = s:cpo_save

ftplugin/rdoc.vim

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function! RdocIsInRCode(vrb)
101101
endfunction
102102

103103
let b:IsInRCode = function("RdocIsInRCode")
104-
let b:SourceLines = function("RSourceLines")
105104

106105
"==========================================================================
107106
" Key bindings and menu items

ftplugin/rhelp_rplugin.vim

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function! RhelpIsInRCode(vrb)
3535
endfunction
3636

3737
let b:IsInRCode = function("RhelpIsInRCode")
38-
let b:SourceLines = function("RSourceLines")
3938

4039
"==========================================================================
4140
" Key bindings and menu items
@@ -55,7 +54,7 @@ endif
5554
call RSourceOtherScripts()
5655

5756
if exists("b:undo_ftplugin")
58-
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:SourceLines"
57+
let b:undo_ftplugin .= " | unlet! b:IsInRCode"
5958
else
60-
let b:undo_ftplugin = " | unlet! b:IsInRCode b:SourceLines"
59+
let b:undo_ftplugin = " | unlet! b:IsInRCode"
6160
endif

ftplugin/rmd_rplugin.vim

+8-7
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ function! RMakeRmd(t)
105105
endfunction
106106

107107
" Send Rmd chunk to R
108-
function! SendRmdChunkToR(m)
108+
function! SendRmdChunkToR(e, m)
109109
if RmdIsInRCode(0) == 0
110110
call RWarningMsg("Not inside an R code chunk.")
111111
return
112112
endif
113113
let chunkline = search("^[ \t]*```[ ]*{r", "bncW") + 1
114114
let docline = search("^[ \t]*```", "ncW") - 1
115115
let lines = getline(chunkline, docline)
116-
let ok = RSourceLines(lines)
116+
let ok = RSourceLines(lines, a:e)
117117
if ok == 0
118118
return
119119
endif
@@ -126,7 +126,6 @@ let b:IsInRCode = function("RmdIsInRCode")
126126
let b:PreviousRChunk = function("RmdPreviousChunk")
127127
let b:NextRChunk = function("RmdNextChunk")
128128
let b:SendChunkToR = function("SendRmdChunkToR")
129-
let b:SourceLines = function("RSourceLines")
130129

131130
"==========================================================================
132131
" Key bindings and menu items
@@ -144,8 +143,10 @@ call RCreateMaps("nvi", '<Plug>RMakePDFK', 'kp', ':call RMakeRmd("pdf_docum
144143
call RCreateMaps("nvi", '<Plug>RMakePDFKb', 'kl', ':call RMakeRmd("beamer_presentation")')
145144
call RCreateMaps("nvi", '<Plug>RMakeHTML', 'kh', ':call RMakeRmd("html_document")')
146145
call RCreateMaps("nvi", '<Plug>RMakeODT', 'ko', ':call RMakeRmd("odt")')
147-
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("stay")')
148-
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("down")')
146+
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")')
147+
call RCreateMaps("ni", '<Plug>RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")')
148+
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")')
149+
call RCreateMaps("ni", '<Plug>REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")')
149150
call RCreateMaps("n", '<Plug>RNextRChunk', 'gn', ':call b:NextRChunk()')
150151
call RCreateMaps("n", '<Plug>RPreviousRChunk', 'gN', ':call b:PreviousRChunk()')
151152

@@ -163,7 +164,7 @@ call RSetPDFViewer()
163164
call RSourceOtherScripts()
164165

165166
if exists("b:undo_ftplugin")
166-
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
167+
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
167168
else
168-
let b:undo_ftplugin = " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
169+
let b:undo_ftplugin = " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
169170
endif

ftplugin/rnoweb_rplugin.vim

+34-31
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ function! RMakePDF(bibtex, knit)
208208
endfunction
209209

210210
" Send Sweave chunk to R
211-
function! RnwSendChunkToR(m)
211+
function! RnwSendChunkToR(e, m)
212212
if RnwIsInRCode(0) == 0
213213
call RWarningMsg("Not inside an R code chunk.")
214214
return
215215
endif
216216
let chunkline = search("^<<", "bncW") + 1
217217
let docline = search("^@", "ncW") - 1
218218
let lines = getline(chunkline, docline)
219-
let ok = RSourceLines(lines)
219+
let ok = RSourceLines(lines, a:e)
220220
if ok == 0
221221
return
222222
endif
@@ -254,10 +254,6 @@ let b:PreviousRChunk = function("RnwPreviousChunk")
254254
let b:NextRChunk = function("RnwNextChunk")
255255
let b:SendChunkToR = function("RnwSendChunkToR")
256256

257-
" Pointers to functions that must be different if the plugin is used as a
258-
" global one:
259-
let b:SourceLines = function("RSourceLines")
260-
261257
let b:pdf_opened = 0
262258

263259

@@ -281,8 +277,10 @@ call RCreateMaps("nvi", '<Plug>RKnit', 'kn', ':call RKnitRnw()')
281277
call RCreateMaps("nvi", '<Plug>RMakePDFK', 'kp', ':call RMakePDF("nobib", 1)')
282278
call RCreateMaps("nvi", '<Plug>RBibTeXK', 'kb', ':call RMakePDF("bibtex", 1)')
283279
call RCreateMaps("nvi", '<Plug>RIndent', 'si', ':call RnwToggleIndentSty()')
284-
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("stay")')
285-
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("down")')
280+
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")')
281+
call RCreateMaps("ni", '<Plug>RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")')
282+
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")')
283+
call RCreateMaps("ni", '<Plug>REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")')
286284
call RCreateMaps("nvi", '<Plug>ROpenPDF', 'op', ':call ROpenPDF("Get Master")')
287285
if g:vimrplugin_synctex
288286
call RCreateMaps("ni", '<Plug>RSyncFor', 'gp', ':call SyncTeX_forward()')
@@ -597,28 +595,33 @@ function! SyncTeX_SetPID(spid)
597595
exe 'autocmd VimLeave * call system("kill ' . a:spid . '")'
598596
endfunction
599597

600-
function! Run_SyncTeX()
601-
if $DISPLAY == "" || g:rplugin_pdfviewer == "none" || exists("b:did_synctex")
602-
return
603-
endif
604-
let b:did_synctex = 1
605-
598+
function! Run_EvinceBackward()
606599
let olddir = getcwd()
607600
if olddir != expand("%:p:h")
608-
exe "cd " . substitute(expand("%:p:h"), ' ', '\\ ', 'g')
601+
try
602+
exe "cd " . substitute(expand("%:p:h"), ' ', '\\ ', 'g')
603+
catch /.*/
604+
return
605+
endtry
609606
endif
610-
611-
if g:rplugin_pdfviewer == "evince"
612-
let [basenm, basedir] = SyncTeX_GetMaster()
613-
if basedir != '.'
614-
exe "cd " . substitute(basedir, ' ', '\\ ', 'g')
615-
endif
616-
if v:servername != ""
617-
call system("python " . g:rplugin_home . "/r-plugin/synctex_evince_backward.py '" . basenm . ".pdf' " . v:servername . " &")
618-
endif
619-
if basedir != '.'
620-
cd -
621-
endif
607+
let [basenm, basedir] = SyncTeX_GetMaster()
608+
if basedir != '.'
609+
exe "cd " . substitute(basedir, ' ', '\\ ', 'g')
610+
endif
611+
let did_evince = 0
612+
if !exists("g:rplugin_evince_list")
613+
let g:rplugin_evince_list = []
614+
else
615+
for bb in g:rplugin_evince_list
616+
if bb == basenm
617+
let did_evince = 1
618+
break
619+
endif
620+
endfor
621+
endif
622+
if !did_evince
623+
call add(g:rplugin_evince_list, basenm)
624+
call system("python " . g:rplugin_home . "/r-plugin/synctex_evince_backward.py '" . basenm . ".pdf' " . v:servername . " &")
622625
endif
623626
exe "cd " . substitute(olddir, ' ', '\\ ', 'g')
624627
endfunction
@@ -642,15 +645,15 @@ if g:rplugin_pdfviewer != "none"
642645
unlet s:key_list
643646
unlet s:has_key
644647
endif
645-
if g:vimrplugin_synctex
646-
call Run_SyncTeX()
648+
if g:vimrplugin_synctex && g:rplugin_pdfviewer == "evince" && $DISPLAY != "" && v:servername != ""
649+
call Run_EvinceBackward()
647650
endif
648651
endif
649652

650653
call RSourceOtherScripts()
651654

652655
if exists("b:undo_ftplugin")
653-
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
656+
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
654657
else
655-
let b:undo_ftplugin = " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
658+
let b:undo_ftplugin = " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
656659
endif

ftplugin/rrst_rplugin.vim

+8-7
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ function! RMakePDFrrst()
144144
endfunction
145145

146146
" Send Rrst chunk to R
147-
function! SendRrstChunkToR(m)
147+
function! SendRrstChunkToR(e, m)
148148
if RrstIsInRCode(0) == 0
149149
call RWarningMsg("Not inside an R code chunk.")
150150
return
151151
endif
152152
let chunkline = search("^\\.\\. {r", "bncW") + 1
153153
let docline = search("^\\.\\. \\.\\.", "ncW") - 1
154154
let lines = getline(chunkline, docline)
155-
let ok = RSourceLines(lines)
155+
let ok = RSourceLines(lines, a:e)
156156
if ok == 0
157157
return
158158
endif
@@ -165,7 +165,6 @@ let b:IsInRCode = function("RrstIsInRCode")
165165
let b:PreviousRChunk = function("RrstPreviousChunk")
166166
let b:NextRChunk = function("RrstNextChunk")
167167
let b:SendChunkToR = function("SendRrstChunkToR")
168-
let b:SourceLines = function("RSourceLines")
169168

170169
"==========================================================================
171170
" Key bindings and menu items
@@ -182,8 +181,10 @@ call RCreateMaps("nvi", '<Plug>RMakePDFK', 'kp', ':call RMakePDFrrst()')
182181
call RCreateMaps("nvi", '<Plug>RMakeHTML', 'kh', ':call RMakeHTMLrrst("html")')
183182
call RCreateMaps("nvi", '<Plug>RMakeODT', 'ko', ':call RMakeHTMLrrst("odt")')
184183
call RCreateMaps("nvi", '<Plug>RIndent', 'si', ':call RrstToggleIndentSty()')
185-
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("stay")')
186-
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("down")')
184+
call RCreateMaps("ni", '<Plug>RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")')
185+
call RCreateMaps("ni", '<Plug>RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")')
186+
call RCreateMaps("ni", '<Plug>RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")')
187+
call RCreateMaps("ni", '<Plug>REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")')
187188
call RCreateMaps("n", '<Plug>RNextRChunk', 'gn', ':call b:NextRChunk()')
188189
call RCreateMaps("n", '<Plug>RPreviousRChunk', 'gN', ':call b:PreviousRChunk()')
189190

@@ -198,7 +199,7 @@ let g:rplugin_has_rst2pdf = 0
198199
call RSourceOtherScripts()
199200

200201
if exists("b:undo_ftplugin")
201-
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
202+
let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
202203
else
203-
let b:undo_ftplugin = " | unlet! b:IsInRCode b:SourceLines b:PreviousRChunk b:NextRChunk b:SendChunkToR"
204+
let b:undo_ftplugin = " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR"
204205
endif

0 commit comments

Comments
 (0)