├── README ├── autoload └── rcomplete.vim ├── doc └── r-plugin.txt ├── ftdetect └── r.vim ├── ftplugin ├── r_rplugin.vim ├── rbrowser.vim ├── rdoc.vim ├── rhelp_rplugin.vim ├── rmd_rplugin.vim ├── rnoweb_rplugin.vim └── rrst_rplugin.vim ├── r-plugin ├── common_buffer.vim ├── common_global.vim ├── functions.vim ├── gui_running.vim ├── osx.vim ├── r.snippets ├── rmd.snippets ├── setcompldir.vim ├── synctex_evince_backward.py ├── synctex_evince_forward.py └── windows.vim └── syntax ├── rbrowser.vim ├── rdoc.vim └── rout.vim /README: -------------------------------------------------------------------------------- 1 | This is a mirror of http://www.vim.org/scripts/script.php?script_id=2628 2 | 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. 4 | 5 | Screenshots and Debian package: http://www.lepem.ufc.br/jaa/vim-r-plugin.html 6 | Comments and general questions: https://groups.google.com/forum/#!forum/vim-r-plugin 7 | Development code and bug report: https://github.com/jcfaria/Vim-R-plugin 8 | 9 | MAIN FEATURES: 10 | 11 | * Communication with R. 12 | * Omni completion (auto-completion) for R objects and function arguments. 13 | * Ability to see R's documentation in a Vim's buffer. 14 | * Object Browser. 15 | * Syntax highlighting for R, RHelp, RMarkdown and RreStructuredText code. 16 | * Smart indentation for R, RHelp, RMarkdown and RreStructuredText syntax. 17 | * Most of the plugin's behavior is customizable. 18 | 19 | For a detailed list of features, see: http://www.lepem.ufc.br/jaa/r-plugin.html#r-plugin-features 20 | 21 | USE: 22 | 23 | See http://www.lepem.ufc.br/jaa/r-plugin.html#r-plugin-use 24 | 25 | FILES: 26 | 27 | See http://www.lepem.ufc.br/jaa/r-plugin.html#r-plugin-files 28 | 29 | -------------------------------------------------------------------------------- /autoload/rcomplete.vim: -------------------------------------------------------------------------------- 1 | " Vim completion script 2 | " Language: R 3 | " Maintainer: Jakson Alves de Aquino 4 | " 5 | 6 | " Tell R to create a list of objects file listing all currently available 7 | " objects in its environment. The file is necessary for omni completion. 8 | function BuildROmniList(pattern) 9 | if string(g:SendCmdToR) == "function('SendCmdToR_fake')" 10 | return 11 | endif 12 | 13 | let omnilistcmd = 'vimcom:::vim.bol("' . g:rplugin_tmpdir . "/GlobalEnvList_" . $VIMINSTANCEID . '"' 14 | if g:vimrplugin_allnames == 1 15 | let omnilistcmd = omnilistcmd . ', allnames = TRUE' 16 | endif 17 | let omnilistcmd = omnilistcmd . ', pattern = "' . a:pattern . '")' 18 | 19 | call delete(g:rplugin_tmpdir . "/vimbol_finished") 20 | call delete(g:rplugin_tmpdir . "/eval_reply") 21 | call SendToVimCom("\x08" . $VIMINSTANCEID . omnilistcmd) 22 | if g:rplugin_vimcomport == 0 23 | sleep 500m 24 | return 25 | endif 26 | let g:rplugin_lastev = ReadEvalReply() 27 | if g:rplugin_lastev == "R is busy." || g:rplugin_lastev == "No reply" 28 | call RWarningMsg(g:rplugin_lastev) 29 | sleep 800m 30 | return 31 | endif 32 | sleep 20m 33 | let ii = 0 34 | while !filereadable(g:rplugin_tmpdir . "/vimbol_finished") && ii < 5 35 | let ii += 1 36 | sleep 37 | endwhile 38 | echon "\r " 39 | if ii == 5 40 | call RWarningMsg("No longer waiting...") 41 | return 42 | endif 43 | 44 | let g:rplugin_globalenvlines = readfile(g:rplugin_tmpdir . "/GlobalEnvList_" . $VIMINSTANCEID) 45 | endfunction 46 | 47 | fun! rcomplete#CompleteR(findstart, base) 48 | if (&filetype == "rnoweb" || &filetype == "rmd" || &filetype == "rrst" || &filetype == "rhelp") && b:IsInRCode(0) == 0 && b:rplugin_nonr_omnifunc != "" 49 | let Ofun = function(b:rplugin_nonr_omnifunc) 50 | let thebegin = Ofun(a:findstart, a:base) 51 | return thebegin 52 | endif 53 | if a:findstart 54 | let line = getline('.') 55 | let start = col('.') - 1 56 | while start > 0 && (line[start - 1] =~ '\w' || line[start - 1] =~ '\.' || line[start - 1] =~ '\$' || line[start - 1] =~ '@') 57 | let start -= 1 58 | endwhile 59 | return start 60 | else 61 | call BuildROmniList(a:base) 62 | let resp = [] 63 | if strlen(a:base) == 0 64 | return resp 65 | endif 66 | 67 | if len(g:rplugin_omni_lines) == 0 68 | call add(resp, {'word': a:base, 'menu': " [ List is empty. Did you load vimcom package? ]"}) 69 | endif 70 | 71 | let flines = g:rplugin_omni_lines + g:rplugin_globalenvlines 72 | " The char '$' at the end of 'a:base' is treated as end of line, and 73 | " the pattern is never found in 'line'. 74 | let newbase = '^' . substitute(a:base, "\\$$", "", "") 75 | for line in flines 76 | if line =~ newbase 77 | " Skip cols of data frames unless the user is really looking for them. 78 | if a:base !~ '\$' && line =~ '\$' 79 | continue 80 | endif 81 | " Skip slots of S4 objects unless the user is really looking for them. 82 | if a:base !~ '@' && line =~ '@' 83 | continue 84 | endif 85 | let tmp1 = split(line, "\x06", 1) 86 | if g:vimrplugin_show_args 87 | let info = tmp1[4] 88 | let info = substitute(info, "\t", ", ", "g") 89 | let info = substitute(info, "\x07", " = ", "g") 90 | let tmp2 = {'word': tmp1[0], 'menu': tmp1[1] . ' ' . tmp1[3], 'info': info} 91 | else 92 | let tmp2 = {'word': tmp1[0], 'menu': tmp1[1] . ' ' . tmp1[3]} 93 | endif 94 | call add(resp, tmp2) 95 | endif 96 | endfor 97 | 98 | return resp 99 | endif 100 | endfun 101 | 102 | -------------------------------------------------------------------------------- /ftdetect/r.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("disable_r_ftplugin") 3 | finish 4 | endif 5 | 6 | autocmd BufNewFile,BufRead *.Rprofile set ft=r 7 | autocmd BufRead *.Rhistory set ft=r 8 | autocmd BufNewFile,BufRead *.r set ft=r 9 | autocmd BufNewFile,BufRead *.R set ft=r 10 | autocmd BufNewFile,BufRead *.s set ft=r 11 | autocmd BufNewFile,BufRead *.S set ft=r 12 | 13 | autocmd BufNewFile,BufRead *.Rout set ft=rout 14 | autocmd BufNewFile,BufRead *.Rout.save set ft=rout 15 | autocmd BufNewFile,BufRead *.Rout.fail set ft=rout 16 | 17 | autocmd BufNewFile,BufRead *.Rrst set ft=rrst 18 | autocmd BufNewFile,BufRead *.rrst set ft=rrst 19 | 20 | autocmd BufNewFile,BufRead *.Rmd set ft=rmd 21 | autocmd BufNewFile,BufRead *.rmd set ft=rmd 22 | -------------------------------------------------------------------------------- /ftplugin/r_rplugin.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("g:disable_r_ftplugin") || has("nvim") 3 | finish 4 | endif 5 | 6 | " Source scripts common to R, Rnoweb, Rhelp, Rmd, Rrst and rdoc files: 7 | runtime r-plugin/common_global.vim 8 | if exists("g:rplugin_failed") 9 | finish 10 | endif 11 | 12 | " Some buffer variables common to R, Rnoweb, Rhelp, Rmd, Rrst and rdoc files 13 | " need be defined after the global ones: 14 | runtime r-plugin/common_buffer.vim 15 | 16 | if !exists("b:did_ftplugin") && !exists("g:rplugin_runtime_warn") 17 | runtime ftplugin/r.vim 18 | if !exists("b:did_ftplugin") 19 | call RWarningMsgInp("Your runtime files seems to be outdated.\nSee: https://github.com/jalvesaq/R-Vim-runtime") 20 | endif 21 | let g:rplugin_runtime_warn = 1 22 | endif 23 | 24 | " Run R CMD BATCH on current file and load the resulting .Rout in a split 25 | " window 26 | function! ShowRout() 27 | let b:routfile = expand("%:r") . ".Rout" 28 | if bufloaded(b:routfile) 29 | exe "bunload " . b:routfile 30 | call delete(b:routfile) 31 | endif 32 | 33 | " if not silent, the user will have to type 34 | silent update 35 | 36 | if has("win32") || has("win64") 37 | let rcmd = 'Rcmd.exe BATCH --no-restore --no-save "' . expand("%") . '" "' . b:routfile . '"' 38 | else 39 | let rcmd = g:rplugin_R . " CMD BATCH --no-restore --no-save '" . expand("%") . "' '" . b:routfile . "'" 40 | endif 41 | 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 57 | else 58 | call RWarningMsg("The file '" . b:routfile . "' is not readable.") 59 | endif 60 | else 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 &') 66 | endif 67 | endfunction 68 | 69 | " Convert R script into Rmd, md and, then, html. 70 | function! RSpin() 71 | update 72 | call g:SendCmdToR('require(knitr); .vim_oldwd <- getwd(); setwd("' . expand("%:p:h") . '"); spin("' . expand("%:t") . '"); setwd(.vim_oldwd); rm(.vim_oldwd)') 73 | endfunction 74 | 75 | " Default IsInRCode function when the plugin is used as a global plugin 76 | function! DefaultIsInRCode(vrb) 77 | return 1 78 | endfunction 79 | 80 | let b:IsInRCode = function("DefaultIsInRCode") 81 | 82 | "========================================================================== 83 | " Key bindings and menu items 84 | 85 | call RCreateStartMaps() 86 | call RCreateEditMaps() 87 | 88 | " Only .R files are sent to R 89 | call RCreateMaps("ni", 'RSendFile', 'aa', ':call SendFileToR("silent")') 90 | call RCreateMaps("ni", 'RESendFile', 'ae', ':call SendFileToR("echo")') 91 | call RCreateMaps("ni", 'RShowRout', 'ao', ':call ShowRout()') 92 | 93 | " Knitr::spin 94 | " ------------------------------------- 95 | call RCreateMaps("ni", 'RSpinFile', 'ks', ':call RSpin()') 96 | 97 | call RCreateSendMaps() 98 | call RControlMaps() 99 | call RCreateMaps("nvi", 'RSetwd', 'rd', ':call RSetWD()') 100 | 101 | 102 | " Menu R 103 | if has("gui_running") 104 | runtime r-plugin/gui_running.vim 105 | call MakeRMenu() 106 | endif 107 | 108 | call RSourceOtherScripts() 109 | 110 | if exists("b:undo_ftplugin") 111 | let b:undo_ftplugin .= " | unlet! b:IsInRCode" 112 | else 113 | let b:undo_ftplugin = "unlet! b:IsInRCode" 114 | endif 115 | -------------------------------------------------------------------------------- /ftplugin/rbrowser.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin file 2 | " Language: R Browser (generated by the Vim-R-plugin) 3 | " Maintainer: Jakson Alves de Aquino 4 | 5 | 6 | " Only do this when not yet done for this buffer 7 | if exists("b:did_ftplugin") || has("nvim") 8 | finish 9 | endif 10 | 11 | let g:rplugin_upobcnt = 0 12 | 13 | " Don't load another plugin for this buffer 14 | let b:did_ftplugin = 1 15 | 16 | let s:cpo_save = &cpo 17 | set cpo&vim 18 | 19 | " Source scripts common to R, Rnoweb, Rhelp and rdoc files: 20 | runtime r-plugin/common_global.vim 21 | 22 | " Some buffer variables common to R, Rnoweb, Rhelp and rdoc file need be 23 | " defined after the global ones: 24 | runtime r-plugin/common_buffer.vim 25 | 26 | setlocal noswapfile 27 | setlocal buftype=nofile 28 | setlocal nowrap 29 | setlocal iskeyword=@,48-57,_,. 30 | setlocal nolist 31 | 32 | if !exists("g:rplugin_hasmenu") 33 | let g:rplugin_hasmenu = 0 34 | endif 35 | 36 | " Popup menu 37 | if !exists("g:rplugin_hasbrowsermenu") 38 | let g:rplugin_hasbrowsermenu = 0 39 | endif 40 | 41 | " Current view of the object browser: .GlobalEnv X loaded libraries 42 | let g:rplugin_curview = "GlobalEnv" 43 | 44 | function! UpdateOB(what) 45 | if a:what == "both" 46 | let wht = g:rplugin_curview 47 | else 48 | let wht = a:what 49 | endif 50 | if g:rplugin_curview != wht 51 | return "curview != what" 52 | endif 53 | if g:rplugin_upobcnt 54 | echoerr "OB called twice" 55 | return "OB called twice" 56 | endif 57 | let g:rplugin_upobcnt = 1 58 | 59 | let rplugin_switchedbuf = 0 60 | if g:vimrplugin_tmux_ob == 0 61 | redir => s:bufl 62 | silent buffers 63 | redir END 64 | if s:bufl !~ "Object_Browser" 65 | let g:rplugin_upobcnt = 0 66 | return "Object_Browser not listed" 67 | endif 68 | if exists("g:rplugin_curbuf") && g:rplugin_curbuf != "Object_Browser" 69 | let savesb = &switchbuf 70 | set switchbuf=useopen,usetab 71 | sil noautocmd sb Object_Browser 72 | let rplugin_switchedbuf = 1 73 | endif 74 | endif 75 | 76 | setlocal modifiable 77 | let curline = line(".") 78 | let curcol = col(".") 79 | if !exists("curline") 80 | let curline = 3 81 | endif 82 | if !exists("curcol") 83 | let curcol = 1 84 | endif 85 | let save_unnamed_reg = @@ 86 | sil normal! ggdG 87 | let @@ = save_unnamed_reg 88 | if wht == "GlobalEnv" 89 | let fcntt = readfile(g:rplugin_tmpdir . "/globenv_" . $VIMINSTANCEID) 90 | else 91 | let fcntt = readfile(g:rplugin_tmpdir . "/liblist_" . $VIMINSTANCEID) 92 | endif 93 | call setline(1, fcntt) 94 | call cursor(curline, curcol) 95 | if bufname("%") =~ "Object_Browser" || b:rplugin_extern_ob 96 | setlocal nomodifiable 97 | endif 98 | if rplugin_switchedbuf 99 | exe "sil noautocmd sb " . g:rplugin_curbuf 100 | exe "set switchbuf=" . savesb 101 | endif 102 | let g:rplugin_upobcnt = 0 103 | return "End of UpdateOB()" 104 | endfunction 105 | 106 | function! RBrowserDoubleClick() 107 | " Toggle view: Objects in the workspace X List of libraries 108 | if line(".") == 1 109 | if g:rplugin_curview == "libraries" 110 | let g:rplugin_curview = "GlobalEnv" 111 | call UpdateOB("GlobalEnv") 112 | else 113 | let g:rplugin_curview = "libraries" 114 | call UpdateOB("libraries") 115 | endif 116 | return 117 | endif 118 | 119 | " Toggle state of list or data.frame: open X closed 120 | let key = RBrowserGetName(0, 1) 121 | if g:rplugin_curview == "GlobalEnv" 122 | if getline(".") =~ "&#.*\t" 123 | call SendToVimCom("\006&" . key) 124 | else 125 | call SendToVimCom("\006" . key) 126 | endif 127 | else 128 | let key = substitute(key, '`', '', "g") 129 | if key !~ "^package:" 130 | let key = "package:" . RBGetPkgName() . '-' . key 131 | endif 132 | call SendToVimCom("\006" . key) 133 | endif 134 | endfunction 135 | 136 | function! RBrowserRightClick() 137 | if line(".") == 1 138 | return 139 | endif 140 | 141 | let key = RBrowserGetName(1, 0) 142 | if key == "" 143 | return 144 | endif 145 | 146 | let line = getline(".") 147 | if line =~ "^ ##" 148 | return 149 | endif 150 | let isfunction = 0 151 | if line =~ "(#.*\t" 152 | let isfunction = 1 153 | endif 154 | 155 | if g:rplugin_hasbrowsermenu == 1 156 | aunmenu ]RBrowser 157 | endif 158 | let key = substitute(key, '\.', '\\.', "g") 159 | let key = substitute(key, ' ', '\\ ', "g") 160 | 161 | exe 'amenu ]RBrowser.summary('. key . ') :call RAction("summary")' 162 | exe 'amenu ]RBrowser.str('. key . ') :call RAction("str")' 163 | exe 'amenu ]RBrowser.names('. key . ') :call RAction("names")' 164 | exe 'amenu ]RBrowser.plot('. key . ') :call RAction("plot")' 165 | exe 'amenu ]RBrowser.print(' . key . ') :call RAction("print")' 166 | amenu ]RBrowser.-sep01- 167 | exe 'amenu ]RBrowser.example('. key . ') :call RAction("example")' 168 | exe 'amenu ]RBrowser.help('. key . ') :call RAction("help")' 169 | if isfunction 170 | exe 'amenu ]RBrowser.args('. key . ') :call RAction("args")' 171 | endif 172 | popup ]RBrowser 173 | let g:rplugin_hasbrowsermenu = 1 174 | endfunction 175 | 176 | function! RBGetPkgName() 177 | let lnum = line(".") 178 | while lnum > 0 179 | let line = getline(lnum) 180 | if line =~ '.*##[0-9a-zA-Z\.]*\t' 181 | let line = substitute(line, '.*##\(.*\)\t', '\1', "") 182 | return line 183 | endif 184 | let lnum -= 1 185 | endwhile 186 | return "" 187 | endfunction 188 | 189 | function! RBrowserFindParent(word, curline, curpos) 190 | let curline = a:curline 191 | let curpos = a:curpos 192 | while curline > 1 && curpos >= a:curpos 193 | let curline -= 1 194 | let line = substitute(getline(curline), " .*", "", "") 195 | let curpos = stridx(line, '[#') 196 | if curpos == -1 197 | let curpos = stridx(line, '<#') 198 | if curpos == -1 199 | let curpos = a:curpos 200 | endif 201 | endif 202 | endwhile 203 | 204 | if g:rplugin_curview == "GlobalEnv" 205 | let spacelimit = 3 206 | else 207 | if s:isutf8 208 | let spacelimit = 10 209 | else 210 | let spacelimit = 6 211 | endif 212 | endif 213 | if curline > 1 214 | let line = substitute(line, '^.\{-}\(.\)#', '\1#', "") 215 | let line = substitute(line, '^ *', '', "") 216 | if line =~ " " || line =~ '^.#[0-9]' 217 | let line = substitute(line, '\(.\)#\(.*\)$', '\1#`\2`', "") 218 | endif 219 | if line =~ '<#' 220 | let word = substitute(line, '.*<#', "", "") . '@' . a:word 221 | else 222 | let word = substitute(line, '.*\[#', "", "") . '$' . a:word 223 | endif 224 | if curpos != spacelimit 225 | let word = RBrowserFindParent(word, line("."), curpos) 226 | endif 227 | return word 228 | else 229 | " Didn't find the parent: should never happen. 230 | let msg = "R-plugin Error: " . a:word . ":" . curline 231 | echoerr msg 232 | endif 233 | return "" 234 | endfunction 235 | 236 | function! RBrowserCleanTailTick(word, cleantail, cleantick) 237 | let nword = a:word 238 | if a:cleantick 239 | let nword = substitute(nword, "`", "", "g") 240 | endif 241 | if a:cleantail 242 | let nword = substitute(nword, '[\$@]$', '', '') 243 | let nword = substitute(nword, '[\$@]`$', '`', '') 244 | endif 245 | return nword 246 | endfunction 247 | 248 | function! RBrowserGetName(cleantail, cleantick) 249 | let line = getline(".") 250 | if line =~ "^$" 251 | return "" 252 | endif 253 | 254 | let curpos = stridx(line, "#") 255 | let word = substitute(line, '.\{-}\(.#\)\(.\{-}\)\t.*', '\2\1', '') 256 | let word = substitute(word, '\[#$', '$', '') 257 | let word = substitute(word, '<#$', '@', '') 258 | let word = substitute(word, '.#$', '', '') 259 | 260 | if word =~ ' ' || word =~ '^[0-9]' 261 | let word = '`' . word . '`' 262 | endif 263 | 264 | if (g:rplugin_curview == "GlobalEnv" && curpos == 4) || (g:rplugin_curview == "libraries" && curpos == 3) 265 | " top level object 266 | let word = substitute(word, '\$\[\[', '[[', "g") 267 | let word = RBrowserCleanTailTick(word, a:cleantail, a:cleantick) 268 | if g:rplugin_curview == "libraries" 269 | return "package:" . substitute(word, "#", "", "") 270 | else 271 | return word 272 | endif 273 | else 274 | if g:rplugin_curview == "libraries" 275 | if s:isutf8 276 | if curpos == 11 277 | let word = RBrowserCleanTailTick(word, a:cleantail, a:cleantick) 278 | let word = substitute(word, '\$\[\[', '[[', "g") 279 | return word 280 | endif 281 | elseif curpos == 7 282 | let word = RBrowserCleanTailTick(word, a:cleantail, a:cleantick) 283 | let word = substitute(word, '\$\[\[', '[[', "g") 284 | return word 285 | endif 286 | endif 287 | if curpos > 4 288 | " Find the parent data.frame or list 289 | let word = RBrowserFindParent(word, line("."), curpos - 1) 290 | let word = RBrowserCleanTailTick(word, a:cleantail, a:cleantick) 291 | let word = substitute(word, '\$\[\[', '[[', "g") 292 | return word 293 | else 294 | " Wrong object name delimiter: should never happen. 295 | let msg = "R-plugin Error: (curpos = " . curpos . ") " . word 296 | echoerr msg 297 | return "" 298 | endif 299 | endif 300 | endfunction 301 | 302 | function! ObBrBufUnload() 303 | if exists("g:rplugin_editor_sname") 304 | call system("tmux select-pane -t " . g:rplugin_vim_pane) 305 | endif 306 | endfunction 307 | 308 | function! SourceObjBrLines() 309 | exe "source " . substitute(g:rplugin_tmpdir, ' ', '\\ ', 'g') . "/objbrowserInit" 310 | endfunction 311 | 312 | nmap :call RBrowserDoubleClick() 313 | nmap <2-LeftMouse> :call RBrowserDoubleClick() 314 | nmap :call RBrowserRightClick() 315 | 316 | call RControlMaps() 317 | 318 | setlocal winfixwidth 319 | setlocal bufhidden=wipe 320 | 321 | if has("gui_running") 322 | runtime r-plugin/gui_running.vim 323 | call RControlMenu() 324 | call RBrowserMenu() 325 | endif 326 | 327 | au BufEnter stopinsert 328 | 329 | if g:vimrplugin_tmux_ob 330 | au BufUnload call ObBrBufUnload() 331 | " Fix problems caused by some plugins 332 | if exists("g:loaded_surround") && mapcheck("ds", "n") != "" 333 | nunmap ds 334 | endif 335 | if exists("g:loaded_showmarks ") 336 | autocmd! ShowMarks 337 | endif 338 | else 339 | au BufUnload call SendToVimCom("\004Stop updating info [OB BufUnload].") 340 | endif 341 | 342 | let s:envstring = tolower($LC_MESSAGES . $LC_ALL . $LANG) 343 | if s:envstring =~ "utf-8" || s:envstring =~ "utf8" 344 | let s:isutf8 = 1 345 | else 346 | let s:isutf8 = 0 347 | endif 348 | unlet s:envstring 349 | 350 | call setline(1, ".GlobalEnv | Libraries") 351 | 352 | call RSourceOtherScripts() 353 | 354 | let &cpo = s:cpo_save 355 | unlet s:cpo_save 356 | 357 | " vim: sw=4 358 | -------------------------------------------------------------------------------- /ftplugin/rdoc.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin file 2 | " Language: R Documentation (generated by the Vim-R-plugin) 3 | " Maintainer: Jakson Alves de Aquino 4 | 5 | 6 | " Only do this when not yet done for this buffer 7 | if exists("b:did_ftplugin") || has("nvim") 8 | finish 9 | endif 10 | 11 | " Don't load another plugin for this buffer 12 | let b:did_ftplugin = 1 13 | 14 | let s:cpo_save = &cpo 15 | set cpo&vim 16 | 17 | " Source scripts common to R, Rnoweb, Rhelp and rdoc files: 18 | runtime r-plugin/common_global.vim 19 | 20 | " Some buffer variables common to R, Rnoweb, Rhelp and rdoc file need be 21 | " defined after the global ones: 22 | runtime r-plugin/common_buffer.vim 23 | 24 | setlocal iskeyword=@,48-57,_,. 25 | 26 | " Prepare R documentation output to be displayed by Vim 27 | function! FixRdoc() 28 | let lnr = line("$") 29 | for ii in range(1, lnr) 30 | call setline(ii, substitute(getline(ii), "_\010", "", "g")) 31 | endfor 32 | 33 | " Mark the end of Examples 34 | let ii = search("^Examples:$", "nw") 35 | if ii 36 | if getline("$") !~ "^###$" 37 | let lnr = line("$") + 1 38 | call setline(lnr, '###') 39 | endif 40 | endif 41 | 42 | " Add a tab character at the end of the Arguments section to mark its end. 43 | let ii = search("^Arguments:$", "nw") 44 | if ii 45 | " A space after 'Arguments:' is necessary for correct syntax highlight 46 | " of the first argument 47 | call setline(ii, "Arguments: ") 48 | let doclength = line("$") 49 | let ii += 2 50 | let lin = getline(ii) 51 | while lin !~ "^[A-Z].*:$" && ii < doclength 52 | let ii += 1 53 | let lin = getline(ii) 54 | endwhile 55 | if ii < doclength 56 | let ii -= 1 57 | if getline(ii) =~ "^$" 58 | call setline(ii, "\t") 59 | endif 60 | endif 61 | endif 62 | 63 | " Add a tab character at the end of the Usage section to mark its end. 64 | let ii = search("^Usage:$", "nw") 65 | if ii 66 | let doclength = line("$") 67 | let ii += 2 68 | let lin = getline(ii) 69 | while lin !~ "^[A-Z].*:" && ii < doclength 70 | let ii += 1 71 | let lin = getline(ii) 72 | endwhile 73 | if ii < doclength 74 | let ii -= 1 75 | if getline(ii) =~ "^ *$" 76 | call setline(ii, "\t") 77 | endif 78 | endif 79 | endif 80 | 81 | normal! gg 82 | 83 | " Clear undo history 84 | let old_undolevels = &undolevels 85 | set undolevels=-1 86 | exe "normal a \\" 87 | let &undolevels = old_undolevels 88 | unlet old_undolevels 89 | endfunction 90 | 91 | function! RdocIsInRCode(vrb) 92 | let exline = search("^Examples:$", "bncW") 93 | if exline > 0 && line(".") > exline 94 | return 1 95 | else 96 | if a:vrb 97 | call RWarningMsg('Not in the "Examples" section.') 98 | endif 99 | return 0 100 | endif 101 | endfunction 102 | 103 | let b:IsInRCode = function("RdocIsInRCode") 104 | 105 | "========================================================================== 106 | " Key bindings and menu items 107 | 108 | call RCreateSendMaps() 109 | call RControlMaps() 110 | 111 | " Menu R 112 | if has("gui_running") 113 | runtime r-plugin/gui_running.vim 114 | call MakeRMenu() 115 | endif 116 | 117 | call RSourceOtherScripts() 118 | 119 | function! RDocExSection() 120 | let ii = search("^Examples:$", "nW") 121 | if ii == 0 122 | call RWarningMsg("No example section below.") 123 | return 124 | else 125 | call cursor(ii+1, 1) 126 | endif 127 | endfunction 128 | 129 | nmap ge :call RDocExSection() 130 | nmap q :q 131 | 132 | setlocal bufhidden=wipe 133 | setlocal noswapfile 134 | set buftype=nofile 135 | autocmd VimResized let g:vimrplugin_newsize = 1 136 | call FixRdoc() 137 | autocmd FileType rdoc call FixRdoc() 138 | 139 | let &cpo = s:cpo_save 140 | unlet s:cpo_save 141 | 142 | " vim: sw=4 143 | -------------------------------------------------------------------------------- /ftplugin/rhelp_rplugin.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("g:disable_r_ftplugin") || has("nvim") 3 | finish 4 | endif 5 | 6 | " Source scripts common to R, Rnoweb, Rhelp and rdoc files: 7 | runtime r-plugin/common_global.vim 8 | if exists("g:rplugin_failed") 9 | finish 10 | endif 11 | 12 | " Some buffer variables common to R, Rnoweb, Rhelp and rdoc file need be 13 | " defined after the global ones: 14 | runtime r-plugin/common_buffer.vim 15 | 16 | if !exists("b:did_ftplugin") && !exists("g:rplugin_runtime_warn") 17 | runtime ftplugin/rhelp.vim 18 | if !exists("b:did_ftplugin") 19 | call RWarningMsgInp("Your runtime files seems to be outdated.\nSee: https://github.com/jalvesaq/R-Vim-runtime") 20 | let g:rplugin_runtime_warn = 1 21 | endif 22 | endif 23 | 24 | function! RhelpIsInRCode(vrb) 25 | let lastsec = search('^\\[a-z][a-z]*{', "bncW") 26 | let secname = getline(lastsec) 27 | if line(".") > lastsec && (secname =~ '^\\usage{' || secname =~ '^\\examples{' || secname =~ '^\\dontshow{' || secname =~ '^\\dontrun{' || secname =~ '^\\donttest{' || secname =~ '^\\testonly{') 28 | return 1 29 | else 30 | if a:vrb 31 | call RWarningMsg("Not inside an R section.") 32 | endif 33 | return 0 34 | endif 35 | endfunction 36 | 37 | function! RhelpComplete(findstart, base) 38 | if a:findstart 39 | let line = getline('.') 40 | let start = col('.') - 1 41 | while start > 0 && (line[start - 1] =~ '\w' || line[start - 1] == '\') 42 | let start -= 1 43 | endwhile 44 | return start 45 | else 46 | let resp = [] 47 | let hwords = ['\Alpha', '\Beta', '\Chi', '\Delta', '\Epsilon', 48 | \ '\Eta', '\Gamma', '\Iota', '\Kappa', '\Lambda', '\Mu', '\Nu', 49 | \ '\Omega', '\Omicron', '\Phi', '\Pi', '\Psi', '\R', '\Rdversion', 50 | \ '\Rho', '\S4method', '\Sexpr', '\Sigma', '\Tau', '\Theta', '\Upsilon', 51 | \ '\Xi', '\Zeta', '\acronym', '\alias', '\alpha', '\arguments', 52 | \ '\author', '\beta', '\bold', '\chi', '\cite', '\code', '\command', 53 | \ '\concept', '\cr', '\dQuote', '\delta', '\deqn', '\describe', 54 | \ '\description', '\details', '\dfn', '\docType', '\dontrun', '\dontshow', 55 | \ '\donttest', '\dots', '\email', '\emph', '\encoding', '\enumerate', 56 | \ '\env', '\epsilon', '\eqn', '\eta', '\examples', '\file', '\format', 57 | \ '\gamma', '\ge', '\href', '\iota', '\item', '\itemize', '\kappa', 58 | \ '\kbd', '\keyword', '\lambda', '\ldots', '\le', 59 | \ '\link', '\linkS4class', '\method', '\mu', '\name', '\newcommand', 60 | \ '\note', '\nu', '\omega', '\omicron', '\option', '\phi', '\pi', 61 | \ '\pkg', '\preformatted', '\psi', '\references', '\renewcommand', '\rho', 62 | \ '\sQuote', '\samp', '\section', '\seealso', '\sigma', '\source', 63 | \ '\special', '\strong', '\subsection', '\synopsis', '\tab', '\tabular', 64 | \ '\tau', '\testonly', '\theta', '\title', '\upsilon', '\url', '\usage', 65 | \ '\value', '\var', '\verb', '\xi', '\zeta'] 66 | for word in hwords 67 | if word =~ '^' . escape(a:base, '\') 68 | call add(resp, {'word': word}) 69 | endif 70 | endfor 71 | return resp 72 | endif 73 | endfunction 74 | 75 | let b:IsInRCode = function("RhelpIsInRCode") 76 | let b:rplugin_nonr_omnifunc = "RhelpComplete" 77 | 78 | "========================================================================== 79 | " Key bindings and menu items 80 | 81 | call RCreateStartMaps() 82 | call RCreateEditMaps() 83 | call RCreateSendMaps() 84 | call RControlMaps() 85 | call RCreateMaps("nvi", 'RSetwd', 'rd', ':call RSetWD()') 86 | 87 | " Menu R 88 | if has("gui_running") 89 | runtime r-plugin/gui_running.vim 90 | call MakeRMenu() 91 | endif 92 | 93 | call RSourceOtherScripts() 94 | 95 | if exists("b:undo_ftplugin") 96 | let b:undo_ftplugin .= " | unlet! b:IsInRCode" 97 | else 98 | let b:undo_ftplugin = "unlet! b:IsInRCode" 99 | endif 100 | -------------------------------------------------------------------------------- /ftplugin/rmd_rplugin.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("g:disable_r_ftplugin") || has("nvim") 3 | finish 4 | endif 5 | 6 | 7 | " Source scripts common to R, Rrst, Rnoweb, Rhelp and Rdoc: 8 | runtime r-plugin/common_global.vim 9 | if exists("g:rplugin_failed") 10 | finish 11 | endif 12 | 13 | " Some buffer variables common to R, Rmd, Rrst, Rnoweb, Rhelp and Rdoc need to 14 | " be defined after the global ones: 15 | runtime r-plugin/common_buffer.vim 16 | 17 | if !exists("b:did_ftplugin") && !exists("g:rplugin_runtime_warn") 18 | runtime ftplugin/rmd.vim 19 | if !exists("b:did_ftplugin") 20 | call RWarningMsgInp("Your runtime files seems to be outdated.\nSee: https://github.com/jalvesaq/R-Vim-runtime") 21 | let g:rplugin_runtime_warn = 1 22 | endif 23 | endif 24 | 25 | function! RmdIsInRCode(vrb) 26 | let chunkline = search("^[ \t]*```[ ]*{r", "bncW") 27 | let docline = search("^[ \t]*```$", "bncW") 28 | if chunkline > docline && chunkline != line(".") 29 | return 1 30 | else 31 | if a:vrb 32 | call RWarningMsg("Not inside an R code chunk.") 33 | endif 34 | return 0 35 | endif 36 | endfunction 37 | 38 | function! RmdPreviousChunk() range 39 | let rg = range(a:firstline, a:lastline) 40 | let chunk = len(rg) 41 | for var in range(1, chunk) 42 | let curline = line(".") 43 | if RmdIsInRCode(0) 44 | let i = search("^[ \t]*```[ ]*{r", "bnW") 45 | if i != 0 46 | call cursor(i-1, 1) 47 | endif 48 | endif 49 | let i = search("^[ \t]*```[ ]*{r", "bnW") 50 | if i == 0 51 | call cursor(curline, 1) 52 | call RWarningMsg("There is no previous R code chunk to go.") 53 | return 54 | else 55 | call cursor(i+1, 1) 56 | endif 57 | endfor 58 | return 59 | endfunction 60 | 61 | function! RmdNextChunk() range 62 | let rg = range(a:firstline, a:lastline) 63 | let chunk = len(rg) 64 | for var in range(1, chunk) 65 | let i = search("^[ \t]*```[ ]*{r", "nW") 66 | if i == 0 67 | call RWarningMsg("There is no next R code chunk to go.") 68 | return 69 | else 70 | call cursor(i+1, 1) 71 | endif 72 | endfor 73 | return 74 | endfunction 75 | 76 | function! RMakeRmd(t) 77 | update 78 | 79 | if a:t == "odt" 80 | if has("win32") || has("win64") 81 | let g:rplugin_soffbin = "soffice.exe" 82 | else 83 | let g:rplugin_soffbin = "soffice" 84 | endif 85 | if !executable(g:rplugin_soffbin) 86 | call RWarningMsg("Is Libre Office installed? Cannot convert into ODT: '" . g:rplugin_soffbin . "' not found.") 87 | return 88 | endif 89 | endif 90 | 91 | let rmddir = expand("%:p:h") 92 | if has("win32") || has("win64") 93 | let rmddir = substitute(rmddir, '\\', '/', 'g') 94 | endif 95 | if a:t == "default" 96 | let rcmd = 'vim.interlace.rmd("' . expand("%:t") . '", rmddir = "' . rmddir . '"' 97 | else 98 | let rcmd = 'vim.interlace.rmd("' . expand("%:t") . '", outform = "' . a:t .'", rmddir = "' . rmddir . '"' 99 | endif 100 | if (g:vimrplugin_openhtml == 0 && a:t == "html_document") || (g:vimrplugin_openpdf == 0 && (a:t == "pdf_document" || a:t == "beamer_presentation")) 101 | let rcmd .= ", view = FALSE" 102 | endif 103 | let rcmd = rcmd . ', envir = ' . g:vimrplugin_rmd_environment . ')' 104 | call g:SendCmdToR(rcmd) 105 | endfunction 106 | 107 | " Send Rmd chunk to R 108 | function! SendRmdChunkToR(e, m) 109 | if RmdIsInRCode(0) == 0 110 | call RWarningMsg("Not inside an R code chunk.") 111 | return 112 | endif 113 | let chunkline = search("^[ \t]*```[ ]*{r", "bncW") + 1 114 | let docline = search("^[ \t]*```", "ncW") - 1 115 | let lines = getline(chunkline, docline) 116 | let ok = RSourceLines(lines, a:e) 117 | if ok == 0 118 | return 119 | endif 120 | if a:m == "down" 121 | call RmdNextChunk() 122 | endif 123 | endfunction 124 | 125 | let b:IsInRCode = function("RmdIsInRCode") 126 | let b:PreviousRChunk = function("RmdPreviousChunk") 127 | let b:NextRChunk = function("RmdNextChunk") 128 | let b:SendChunkToR = function("SendRmdChunkToR") 129 | 130 | "========================================================================== 131 | " Key bindings and menu items 132 | 133 | call RCreateStartMaps() 134 | call RCreateEditMaps() 135 | call RCreateSendMaps() 136 | call RControlMaps() 137 | call RCreateMaps("nvi", 'RSetwd', 'rd', ':call RSetWD()') 138 | 139 | " Only .Rmd files use these functions: 140 | call RCreateMaps("nvi", 'RKnit', 'kn', ':call RKnit()') 141 | call RCreateMaps("nvi", 'RMakeRmd', 'kr', ':call RMakeRmd("default")') 142 | call RCreateMaps("nvi", 'RMakePDFK', 'kp', ':call RMakeRmd("pdf_document")') 143 | call RCreateMaps("nvi", 'RMakePDFKb', 'kl', ':call RMakeRmd("beamer_presentation")') 144 | call RCreateMaps("nvi", 'RMakeHTML', 'kh', ':call RMakeRmd("html_document")') 145 | call RCreateMaps("nvi", 'RMakeODT', 'ko', ':call RMakeRmd("odt")') 146 | call RCreateMaps("ni", 'RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")') 147 | call RCreateMaps("ni", 'RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")') 148 | call RCreateMaps("ni", 'RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")') 149 | call RCreateMaps("ni", 'REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")') 150 | call RCreateMaps("n", 'RNextRChunk', 'gn', ':call b:NextRChunk()') 151 | call RCreateMaps("n", 'RPreviousRChunk', 'gN', ':call b:PreviousRChunk()') 152 | 153 | " Menu R 154 | if has("gui_running") 155 | runtime r-plugin/gui_running.vim 156 | call MakeRMenu() 157 | endif 158 | 159 | let g:rplugin_has_pandoc = 0 160 | let g:rplugin_has_soffice = 0 161 | 162 | call RSetPDFViewer() 163 | 164 | call RSourceOtherScripts() 165 | 166 | if exists("b:undo_ftplugin") 167 | let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 168 | else 169 | let b:undo_ftplugin = "unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 170 | endif 171 | -------------------------------------------------------------------------------- /ftplugin/rnoweb_rplugin.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("g:disable_r_ftplugin") || has("nvim") 3 | finish 4 | endif 5 | 6 | " Source scripts common to R, Rnoweb, Rhelp and Rdoc: 7 | runtime r-plugin/common_global.vim 8 | if exists("g:rplugin_failed") 9 | finish 10 | endif 11 | 12 | " Some buffer variables common to R, Rnoweb, Rhelp and Rdoc need to be defined 13 | " after the global ones: 14 | runtime r-plugin/common_buffer.vim 15 | 16 | if !exists("b:did_ftplugin") && !exists("g:rplugin_runtime_warn") 17 | runtime ftplugin/rnoweb.vim 18 | if !exists("b:did_ftplugin") 19 | call RWarningMsgInp("Your runtime files seems to be outdated.\nSee: https://github.com/jalvesaq/R-Vim-runtime") 20 | let g:rplugin_runtime_warn = 1 21 | endif 22 | endif 23 | 24 | if has("win32") || has("win64") 25 | call RSetDefaultValue("g:vimrplugin_latexmk", 0) 26 | else 27 | call RSetDefaultValue("g:vimrplugin_latexmk", 1) 28 | endif 29 | if !exists("g:rplugin_has_latexmk") 30 | if g:vimrplugin_latexmk && executable("latexmk") && executable("perl") 31 | let g:rplugin_has_latexmk = 1 32 | else 33 | let g:rplugin_has_latexmk = 0 34 | endif 35 | endif 36 | 37 | function! RWriteChunk() 38 | if getline(".") =~ "^\\s*$" && RnwIsInRCode(0) == 0 39 | call setline(line("."), "<<>>=") 40 | exe "normal! o@" 41 | exe "normal! 0kl" 42 | else 43 | exe "normal! a<" 44 | endif 45 | endfunction 46 | 47 | function! RnwIsInRCode(vrb) 48 | let chunkline = search("^<<", "bncW") 49 | let docline = search("^@", "bncW") 50 | if chunkline > docline && chunkline != line(".") 51 | return 1 52 | else 53 | if a:vrb 54 | call RWarningMsg("Not inside an R code chunk.") 55 | endif 56 | return 0 57 | endif 58 | endfunction 59 | 60 | function! RnwPreviousChunk() range 61 | let rg = range(a:firstline, a:lastline) 62 | let chunk = len(rg) 63 | for var in range(1, chunk) 64 | let curline = line(".") 65 | if RnwIsInRCode(0) 66 | let i = search("^<<.*$", "bnW") 67 | if i != 0 68 | call cursor(i-1, 1) 69 | endif 70 | endif 71 | let i = search("^<<.*$", "bnW") 72 | if i == 0 73 | call cursor(curline, 1) 74 | call RWarningMsg("There is no previous R code chunk to go.") 75 | return 76 | else 77 | call cursor(i+1, 1) 78 | endif 79 | endfor 80 | return 81 | endfunction 82 | 83 | function! RnwNextChunk() range 84 | let rg = range(a:firstline, a:lastline) 85 | let chunk = len(rg) 86 | for var in range(1, chunk) 87 | let i = search("^<<.*$", "nW") 88 | if i == 0 89 | call RWarningMsg("There is no next R code chunk to go.") 90 | return 91 | else 92 | call cursor(i+1, 1) 93 | endif 94 | endfor 95 | return 96 | endfunction 97 | 98 | 99 | " Because this function delete files, it will not be documented. 100 | " If you want to try it, put in your vimrc: 101 | " 102 | " let vimrplugin_rm_knit_cache = 1 103 | " 104 | " If don't want to answer the question about deleting files, and 105 | " if you trust this code more than I do, put in your vimrc: 106 | " 107 | " let vimrplugin_ask_rm_knitr_cache = 0 108 | " 109 | " Note that if you have the string "cache.path=" in more than one place only 110 | " the first one above the cursor position will be found. The path must be 111 | " surrounded by quotes; if it's an R object, it will not be recognized. 112 | function! RKnitRmCache() 113 | let lnum = search('\\s*=', 'bnwc') 114 | if lnum == 0 115 | let pathdir = "cache/" 116 | else 117 | let pathregexpr = '.*\\s*=\s*[' . "'" . '"]\(.\{-}\)[' . "'" . '"].*' 118 | let pathdir = substitute(getline(lnum), pathregexpr, '\1', '') 119 | if pathdir !~ '/$' 120 | let pathdir .= '/' 121 | endif 122 | endif 123 | if exists("g:vimrplugin_ask_rm_knitr_cache") && g:vimrplugin_ask_rm_knitr_cache == 0 124 | let cleandir = 1 125 | else 126 | call inputsave() 127 | let answer = input('Delete all files from "' . pathdir . '"? [y/n]: ') 128 | call inputrestore() 129 | if answer == "y" 130 | let cleandir = 1 131 | else 132 | let cleandir = 0 133 | endif 134 | endif 135 | normal! : 136 | if cleandir 137 | call g:SendCmdToR('rm(list=ls(all.names=TRUE)); unlink("' . pathdir . '*")') 138 | endif 139 | endfunction 140 | 141 | " knit the current buffer content 142 | function! RKnitRnw() 143 | update 144 | let rnwdir = expand("%:p:h") 145 | if has("win32") || has("win64") 146 | let rnwdir = substitute(rnwdir, '\\', '/', 'g') 147 | endif 148 | if g:vimrplugin_synctex == 0 149 | call g:SendCmdToR('vim.interlace.rnoweb("' . expand("%:t") . '", rnwdir = "' . rnwdir . '", buildpdf = FALSE, synctex = FALSE)') 150 | else 151 | call g:SendCmdToR('vim.interlace.rnoweb("' . expand("%:t") . '", rnwdir = "' . rnwdir . '", buildpdf = FALSE)') 152 | endif 153 | endfunction 154 | 155 | " Sweave and compile the current buffer content 156 | function! RMakePDF(bibtex, knit) 157 | if g:rplugin_vimcomport == 0 158 | call RWarningMsg("The vimcom package is required to make and open the PDF.") 159 | endif 160 | update 161 | let rnwdir = expand("%:p:h") 162 | if has("win32") || has("win64") 163 | let rnwdir = substitute(rnwdir, '\\', '/', 'g') 164 | endif 165 | let pdfcmd = 'vim.interlace.rnoweb("' . expand("%:t") . '", rnwdir = "' . rnwdir . '"' 166 | 167 | if a:knit == 0 168 | let pdfcmd = pdfcmd . ', knit = FALSE' 169 | endif 170 | 171 | if g:rplugin_has_latexmk == 0 172 | let pdfcmd = pdfcmd . ', latexmk = FALSE' 173 | endif 174 | 175 | if g:vimrplugin_latexcmd != "default" 176 | let pdfcmd = pdfcmd . ", latexcmd = '" . g:vimrplugin_latexcmd . "'" 177 | endif 178 | 179 | if g:vimrplugin_synctex == 0 180 | let pdfcmd = pdfcmd . ", synctex = FALSE" 181 | endif 182 | 183 | if a:bibtex == "bibtex" 184 | let pdfcmd = pdfcmd . ", bibtex = TRUE" 185 | endif 186 | 187 | if g:vimrplugin_openpdf == 0 188 | let pdfcmd = pdfcmd . ", view = FALSE" 189 | else 190 | if g:vimrplugin_openpdf == 1 191 | if b:pdf_opened == 0 192 | let b:pdf_opened = 1 193 | else 194 | let pdfcmd = pdfcmd . ", view = FALSE" 195 | endif 196 | endif 197 | endif 198 | 199 | if a:knit == 0 && exists("g:vimrplugin_sweaveargs") 200 | let pdfcmd = pdfcmd . ", " . g:vimrplugin_sweaveargs 201 | endif 202 | 203 | let pdfcmd = pdfcmd . ")" 204 | let ok = g:SendCmdToR(pdfcmd) 205 | if ok == 0 206 | return 207 | endif 208 | endfunction 209 | 210 | " Send Sweave chunk to R 211 | function! RnwSendChunkToR(e, m) 212 | if RnwIsInRCode(0) == 0 213 | call RWarningMsg("Not inside an R code chunk.") 214 | return 215 | endif 216 | let chunkline = search("^<<", "bncW") + 1 217 | let docline = search("^@", "ncW") - 1 218 | let lines = getline(chunkline, docline) 219 | let ok = RSourceLines(lines, a:e) 220 | if ok == 0 221 | return 222 | endif 223 | if a:m == "down" 224 | call RnwNextChunk() 225 | endif 226 | endfunction 227 | 228 | " Sweave the current buffer content 229 | function! RSweave() 230 | update 231 | let rnwdir = expand("%:p:h") 232 | if has("win32") || has("win64") 233 | let rnwdir = substitute(rnwdir, '\\', '/', 'g') 234 | endif 235 | let scmd = 'vim.interlace.rnoweb("' . expand("%:t") . '", rnwdir = "' . rnwdir . '", knit = FALSE, buildpdf = FALSE' 236 | if exists("g:vimrplugin_sweaveargs") 237 | let scmd .= ', ' . g:vimrplugin_sweaveargs 238 | endif 239 | if g:vimrplugin_synctex == 0 240 | let scmd .= ", synctex = FALSE" 241 | endif 242 | call g:SendCmdToR(scmd . ')') 243 | endfunction 244 | 245 | if g:vimrplugin_rnowebchunk == 1 246 | " Write code chunk in rnoweb files 247 | inoremap < :call RWriteChunk()a 248 | endif 249 | 250 | " Pointers to functions whose purposes are the same in rnoweb, rrst, rmd, 251 | " rhelp and rdoc and which are called at common_global.vim 252 | let b:IsInRCode = function("RnwIsInRCode") 253 | let b:PreviousRChunk = function("RnwPreviousChunk") 254 | let b:NextRChunk = function("RnwNextChunk") 255 | let b:SendChunkToR = function("RnwSendChunkToR") 256 | 257 | let b:pdf_opened = 0 258 | 259 | 260 | "========================================================================== 261 | " Key bindings and menu items 262 | 263 | call RCreateStartMaps() 264 | call RCreateEditMaps() 265 | call RCreateSendMaps() 266 | call RControlMaps() 267 | call RCreateMaps("nvi", 'RSetwd', 'rd', ':call RSetWD()') 268 | 269 | " Only .Rnw files use these functions: 270 | call RCreateMaps("nvi", 'RSweave', 'sw', ':call RSweave()') 271 | call RCreateMaps("nvi", 'RMakePDF', 'sp', ':call RMakePDF("nobib", 0)') 272 | call RCreateMaps("nvi", 'RBibTeX', 'sb', ':call RMakePDF("bibtex", 0)') 273 | if exists("g:vimrplugin_rm_knit_cache") && g:vimrplugin_rm_knit_cache == 1 274 | call RCreateMaps("nvi", 'RKnitRmCache', 'kr', ':call RKnitRmCache()') 275 | endif 276 | call RCreateMaps("nvi", 'RKnit', 'kn', ':call RKnitRnw()') 277 | call RCreateMaps("nvi", 'RMakePDFK', 'kp', ':call RMakePDF("nobib", 1)') 278 | call RCreateMaps("nvi", 'RBibTeXK', 'kb', ':call RMakePDF("bibtex", 1)') 279 | call RCreateMaps("nvi", 'RIndent', 'si', ':call RnwToggleIndentSty()') 280 | call RCreateMaps("ni", 'RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")') 281 | call RCreateMaps("ni", 'RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")') 282 | call RCreateMaps("ni", 'RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")') 283 | call RCreateMaps("ni", 'REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")') 284 | call RCreateMaps("nvi", 'ROpenPDF', 'op', ':call ROpenPDF("Get Master")') 285 | if g:vimrplugin_synctex 286 | call RCreateMaps("ni", 'RSyncFor', 'gp', ':call SyncTeX_forward()') 287 | call RCreateMaps("ni", 'RGoToTeX', 'gt', ':call SyncTeX_forward(1)') 288 | endif 289 | call RCreateMaps("n", 'RNextRChunk', 'gn', ':call b:NextRChunk()') 290 | call RCreateMaps("n", 'RPreviousRChunk', 'gN', ':call b:PreviousRChunk()') 291 | 292 | " Menu R 293 | if has("gui_running") 294 | runtime r-plugin/gui_running.vim 295 | call MakeRMenu() 296 | endif 297 | 298 | "========================================================================== 299 | " SyncTeX support: 300 | 301 | function! SyncTeX_GetMaster() 302 | if filereadable(expand("%:t:r") . "-concordance.tex") 303 | return [expand("%:t:r"), "."] 304 | endif 305 | 306 | let ischild = search('% *!Rnw *root *=', 'bwn') 307 | if ischild 308 | let mfile = substitute(getline(ischild), '.*% *!Rnw *root *= *\(.*\) *', '\1', '') 309 | if mfile =~ "/" 310 | let mdir = substitute(mfile, '\(.*\)/.*', '\1', '') 311 | let mfile = substitute(mfile, '.*/', '', '') 312 | if mdir == '..' 313 | let mdir = expand("%:p:h:h") 314 | endif 315 | else 316 | let mdir = "." 317 | endif 318 | let basenm = substitute(mfile, '\....$', '', '') 319 | return [basenm, mdir] 320 | endif 321 | 322 | " Maybe this buffer is a master Rnoweb not compiled yet. 323 | return [expand("%:t:r"), "."] 324 | endfunction 325 | 326 | " See http://www.stats.uwo.ca/faculty/murdoch/9864/Sweave.pdf page 25 327 | function! SyncTeX_readconc(basenm) 328 | let texidx = 0 329 | let rnwidx = 0 330 | let ntexln = len(readfile(a:basenm . ".tex")) 331 | let lstexln = range(1, ntexln) 332 | let lsrnwf = range(1, ntexln) 333 | let lsrnwl = range(1, ntexln) 334 | let conc = readfile(a:basenm . "-concordance.tex") 335 | let idx = 0 336 | let maxidx = len(conc) 337 | while idx < maxidx && texidx < ntexln && conc[idx] =~ "Sconcordance" 338 | let texf = substitute(conc[idx], '\\Sconcordance{concordance:\(.\{-}\):.*', '\1', "g") 339 | let rnwf = substitute(conc[idx], '\\Sconcordance{concordance:.\{-}:\(.\{-}\):.*', '\1', "g") 340 | let idx += 1 341 | let concnum = "" 342 | while idx < maxidx && conc[idx] !~ "Sconcordance" 343 | let concnum = concnum . conc[idx] 344 | let idx += 1 345 | endwhile 346 | let concnum = substitute(concnum, '%', '', 'g') 347 | let concnum = substitute(concnum, '}', '', '') 348 | let concl = split(concnum) 349 | let ii = 0 350 | let maxii = len(concl) - 2 351 | let rnwl = str2nr(concl[0]) 352 | let lsrnwl[texidx] = rnwl 353 | let lsrnwf[texidx] = rnwf 354 | let texidx += 1 355 | while ii < maxii && texidx < ntexln 356 | let ii += 1 357 | let lnrange = range(1, concl[ii]) 358 | let ii += 1 359 | for iii in lnrange 360 | if texidx >= ntexln 361 | break 362 | endif 363 | let rnwl += concl[ii] 364 | let lsrnwl[texidx] = rnwl 365 | let lsrnwf[texidx] = rnwf 366 | let texidx += 1 367 | endfor 368 | endwhile 369 | endwhile 370 | return {"texlnum": lstexln, "rnwfile": lsrnwf, "rnwline": lsrnwl} 371 | endfunction 372 | 373 | function! GoToBuf(rnwbn, rnwf, basedir, rnwln) 374 | if bufname("%") != a:rnwbn 375 | if bufloaded(a:basedir . '/' . a:rnwf) 376 | let savesb = &switchbuf 377 | set switchbuf=useopen,usetab 378 | exe "sb " . substitute(a:basedir . '/' . a:rnwf, ' ', '\\ ', 'g') 379 | exe "set switchbuf=" . savesb 380 | elseif bufloaded(a:rnwf) 381 | let savesb = &switchbuf 382 | set switchbuf=useopen,usetab 383 | exe "sb " . substitute(a:rnwf, ' ', '\\ ', 'g') 384 | exe "set switchbuf=" . savesb 385 | else 386 | if filereadable(a:basedir . '/' . a:rnwf) 387 | exe "tabnew " . substitute(a:basedir . '/' . a:rnwf, ' ', '\\ ', 'g') 388 | elseif filereadable(a:rnwf) 389 | exe "tabnew " . substitute(a:rnwf, ' ', '\\ ', 'g') 390 | else 391 | call RWarningMsg('Could not find either "' . a:rnwbn . ' or "' . a:rnwf . '" in "' . a:basedir . '".') 392 | return 0 393 | endif 394 | endif 395 | endif 396 | exe a:rnwln 397 | redraw 398 | return 1 399 | endfunction 400 | 401 | function! SyncTeX_backward(fname, ln) 402 | let flnm = substitute(a:fname, '/\./', '/', '') " Okular 403 | let basenm = substitute(flnm, "\....$", "", "") " Delete extension 404 | if basenm =~ "/" 405 | let basedir = substitute(basenm, '\(.*\)/.*', '\1', '') 406 | else 407 | let basedir = '.' 408 | endif 409 | if filereadable(basenm . "-concordance.tex") 410 | if !filereadable(basenm . ".tex") 411 | call RWarningMsg('SyncTeX [Vim-R-plugin]: "' . basenm . '.tex" not found.') 412 | return 413 | endif 414 | let concdata = SyncTeX_readconc(basenm) 415 | let texlnum = concdata["texlnum"] 416 | let rnwfile = concdata["rnwfile"] 417 | let rnwline = concdata["rnwline"] 418 | let rnwln = 0 419 | for ii in range(len(texlnum)) 420 | if texlnum[ii] >= a:ln 421 | let rnwf = rnwfile[ii] 422 | let rnwln = rnwline[ii] 423 | break 424 | endif 425 | endfor 426 | if rnwln == 0 427 | call RWarningMsg("Could not find Rnoweb source line.") 428 | return 429 | endif 430 | else 431 | if filereadable(basenm . ".Rnw") || filereadable(basenm . ".rnw") 432 | call RWarningMsg('SyncTeX [Vim-R-plugin]: "' . basenm . '-concordance.tex" not found.') 433 | return 434 | elseif filereadable(flnm) 435 | let rnwf = flnm 436 | let rnwln = a:ln 437 | else 438 | call RWarningMsg("Could not find '" . basenm . ".Rnw'.") 439 | endif 440 | endif 441 | 442 | let rnwbn = substitute(rnwf, '.*/', '', '') 443 | let rnwf = substitute(rnwf, '^\./', '', '') 444 | 445 | if GoToBuf(rnwbn, rnwf, basedir, rnwln) 446 | if g:rplugin_has_wmctrl && v:windowid != 0 447 | call system("wmctrl -ia " . v:windowid) 448 | elseif has("gui_running") 449 | call foreground() 450 | endif 451 | endif 452 | endfunction 453 | 454 | function! SyncTeX_forward(...) 455 | let basenm = expand("%:t:r") 456 | let lnum = 0 457 | let rnwf = expand("%:t") 458 | 459 | let olddir = getcwd() 460 | if olddir != expand("%:p:h") 461 | exe "cd " . substitute(expand("%:p:h"), ' ', '\\ ', 'g') 462 | endif 463 | 464 | if filereadable(basenm . "-concordance.tex") 465 | let lnum = line(".") 466 | else 467 | let ischild = search('% *!Rnw *root *=', 'bwn') 468 | if ischild 469 | let mfile = substitute(getline(ischild), '.*% *!Rnw *root *= *\(.*\) *', '\1', '') 470 | let basenm = substitute(mfile, '\....$', '', '') 471 | if filereadable(basenm . "-concordance.tex") 472 | let mlines = readfile(mfile) 473 | for ii in range(len(mlines)) 474 | " Sweave has detailed child information 475 | if mlines[ii] =~ 'SweaveInput.*' . bufname("%") 476 | let lnum = line(".") 477 | break 478 | endif 479 | " Knitr does not include detailed child information 480 | if mlines[ii] =~ '<<.*child *=.*' . bufname("%") . '["' . "']" 481 | let lnum = ii + 1 482 | let rnwf = substitute(mfile, '.*/', '', '') 483 | break 484 | endif 485 | endfor 486 | if lnum == 0 487 | call RWarningMsg('Could not find "child=' . bufname("%") . '" in ' . mfile . '.') 488 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 489 | return 490 | endif 491 | else 492 | call RWarningMsg('Vim-R-plugin [SyncTeX]: "' . basenm . '-concordance.tex" not found.') 493 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 494 | return 495 | endif 496 | else 497 | call RWarningMsg('SyncTeX [Vim-R-plugin]: "' . basenm . '-concordance.tex" not found.') 498 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 499 | return 500 | endif 501 | endif 502 | 503 | if !filereadable(basenm . ".tex") 504 | call RWarningMsg('"' . basenm . '.tex" not found.') 505 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 506 | return 507 | endif 508 | let concdata = SyncTeX_readconc(basenm) 509 | let texlnum = concdata["texlnum"] 510 | let rnwfile = concdata["rnwfile"] 511 | let rnwline = concdata["rnwline"] 512 | let texln = 0 513 | for ii in range(len(texlnum)) 514 | if rnwfile[ii] =~ rnwf && rnwline[ii] >= lnum 515 | let texln = texlnum[ii] 516 | break 517 | endif 518 | endfor 519 | 520 | if texln == 0 521 | call RWarningMsg("Error: did not find LaTeX line.") 522 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 523 | return 524 | endif 525 | if basenm =~ '/' 526 | let basedir = substitute(basenm, '\(.*\)/.*', '\1', '') 527 | let basenm = substitute(basenm, '.*/', '', '') 528 | exe "cd " . substitute(basedir, ' ', '\\ ', 'g') 529 | else 530 | let basedir = '' 531 | endif 532 | 533 | if a:0 && a:1 534 | call GoToBuf(basenm . ".tex", basenm . ".tex", basedir, texln) 535 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 536 | return 537 | endif 538 | 539 | if !filereadable(basenm . ".pdf") 540 | call RWarningMsg('SyncTeX forward cannot be done because the file "' . basenm . '.pdf" is missing.') 541 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 542 | return 543 | endif 544 | if !filereadable(basenm . ".synctex.gz") 545 | call RWarningMsg('SyncTeX forward cannot be done because the file "' . basenm . '.synctex.gz" is missing.') 546 | if g:vimrplugin_latexcmd != "default" && g:vimrplugin_latexcmd !~ "synctex" 547 | call RWarningMsg('Note: The string "-synctex=1" is not in your vimrplugin_latexcmd. Please check your vimrc.') 548 | endif 549 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 550 | return 551 | endif 552 | 553 | if g:rplugin_pdfviewer == "okular" 554 | call system("okular --unique " . basenm . ".pdf#src:" . texln . substitute(expand("%:p:h"), ' ', '\\ ', 'g') . "/./" . substitute(basenm, ' ', '\\ ', 'g') . ".tex 2> /dev/null >/dev/null &") 555 | elseif g:rplugin_pdfviewer == "evince" 556 | call system("python " . g:rplugin_home . "/r-plugin/synctex_evince_forward.py '" . basenm . ".pdf' " . texln . " '" . basenm . ".tex' 2> /dev/null >/dev/null &") 557 | if g:rplugin_has_wmctrl 558 | call system("wmctrl -a '" . basenm . ".pdf'") 559 | endif 560 | elseif g:rplugin_pdfviewer == "zathura" 561 | if system("wmctrl -xl") =~ 'Zathura.*' . basenm . '.pdf' && g:rplugin_zathura_pid[basenm] != 0 562 | if g:rplugin_has_dbussend 563 | let result = system('dbus-send --print-reply --session --dest=org.pwmt.zathura.PID-' . g:rplugin_zathura_pid[basenm] . ' /org/pwmt/zathura org.pwmt.zathura.SynctexView string:"' . basenm . '.tex' . '" uint32:' . texln . ' uint32:1') 564 | else 565 | let result = system("zathura --synctex-forward=" . texln . ":1:" . basenm . ".tex --synctex-pid=" . g:rplugin_zathura_pid[basenm] . " " . basenm . ".pdf") 566 | endif 567 | if v:shell_error 568 | let g:rplugin_zathura_pid[basenm] = 0 569 | call RWarningMsg(result) 570 | endif 571 | else 572 | let g:rplugin_zathura_pid[basenm] = 0 573 | call RStart_Zathura(basenm) 574 | endif 575 | call system("wmctrl -a '" . basenm . ".pdf'") 576 | elseif g:rplugin_pdfviewer == "sumatra" 577 | if g:rplugin_sumatra_path != "" || FindSumatra() 578 | silent exe '!start "' . g:rplugin_sumatra_path . '" -reuse-instance -forward-search ' . basenm . '.tex ' . texln . ' -inverse-search "vim --servername ' . v:servername . " --remote-expr SyncTeX_backward('\\%f',\\%l)" . '" "' . basenm . '.pdf"' 579 | endif 580 | elseif g:rplugin_pdfviewer == "skim" 581 | " This command is based on macvim-skim 582 | call system(g:macvim_skim_app_path . '/Contents/SharedSupport/displayline -r ' . texln . ' "' . basenm . '.pdf" "' . basenm . '.tex" 2> /dev/null >/dev/null &') 583 | else 584 | call RWarningMsg('SyncTeX support for "' . g:rplugin_pdfviewer . '" not implemented.') 585 | endif 586 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 587 | endfunction 588 | 589 | function! SyncTeX_SetPID(spid) 590 | exe 'autocmd VimLeave * call system("kill ' . a:spid . '")' 591 | endfunction 592 | 593 | function! Run_EvinceBackward() 594 | let olddir = getcwd() 595 | if olddir != expand("%:p:h") 596 | try 597 | exe "cd " . substitute(expand("%:p:h"), ' ', '\\ ', 'g') 598 | catch /.*/ 599 | return 600 | endtry 601 | endif 602 | let [basenm, basedir] = SyncTeX_GetMaster() 603 | if basedir != '.' 604 | exe "cd " . substitute(basedir, ' ', '\\ ', 'g') 605 | endif 606 | let did_evince = 0 607 | if !exists("g:rplugin_evince_list") 608 | let g:rplugin_evince_list = [] 609 | else 610 | for bb in g:rplugin_evince_list 611 | if bb == basenm 612 | let did_evince = 1 613 | break 614 | endif 615 | endfor 616 | endif 617 | if !did_evince 618 | call add(g:rplugin_evince_list, basenm) 619 | call system("python " . g:rplugin_home . "/r-plugin/synctex_evince_backward.py '" . basenm . ".pdf' " . v:servername . " &") 620 | endif 621 | exe "cd " . substitute(olddir, ' ', '\\ ', 'g') 622 | endfunction 623 | 624 | call RSetPDFViewer() 625 | if g:rplugin_pdfviewer != "none" 626 | if g:rplugin_pdfviewer == "zathura" 627 | let s:this_master = SyncTeX_GetMaster()[0] 628 | let s:key_list = keys(g:rplugin_zathura_pid) 629 | let s:has_key = 0 630 | for kk in s:key_list 631 | if kk == s:this_master 632 | let s:has_key = 1 633 | break 634 | endif 635 | endfor 636 | if s:has_key == 0 637 | let g:rplugin_zathura_pid[s:this_master] = 0 638 | endif 639 | unlet s:this_master 640 | unlet s:key_list 641 | unlet s:has_key 642 | endif 643 | if g:vimrplugin_synctex && g:rplugin_pdfviewer == "evince" && $DISPLAY != "" && v:servername != "" 644 | call Run_EvinceBackward() 645 | endif 646 | endif 647 | 648 | call RSourceOtherScripts() 649 | 650 | if exists("b:undo_ftplugin") 651 | let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 652 | else 653 | let b:undo_ftplugin = "unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 654 | endif 655 | -------------------------------------------------------------------------------- /ftplugin/rrst_rplugin.vim: -------------------------------------------------------------------------------- 1 | 2 | if exists("g:disable_r_ftplugin") || has("nvim") 3 | finish 4 | endif 5 | 6 | " Source scripts common to R, Rrst, Rnoweb, Rhelp and Rdoc: 7 | runtime r-plugin/common_global.vim 8 | if exists("g:rplugin_failed") 9 | finish 10 | endif 11 | 12 | " Some buffer variables common to R, Rrst, Rnoweb, Rhelp and Rdoc need to be 13 | " defined after the global ones: 14 | runtime r-plugin/common_buffer.vim 15 | 16 | if !exists("b:did_ftplugin") && !exists("g:rplugin_runtime_warn") 17 | runtime ftplugin/rrst.vim 18 | if !exists("b:did_ftplugin") 19 | call RWarningMsgInp("Your runtime files seems to be outdated.\nSee: https://github.com/jalvesaq/R-Vim-runtime") 20 | let g:rplugin_runtime_warn = 1 21 | endif 22 | endif 23 | 24 | function! RrstIsInRCode(vrb) 25 | let chunkline = search("^\\.\\. {r", "bncW") 26 | let docline = search("^\\.\\. \\.\\.", "bncW") 27 | if chunkline > docline && chunkline != line(".") 28 | return 1 29 | else 30 | if a:vrb 31 | call RWarningMsg("Not inside an R code chunk.") 32 | endif 33 | return 0 34 | endif 35 | endfunction 36 | 37 | function! RrstPreviousChunk() range 38 | let rg = range(a:firstline, a:lastline) 39 | let chunk = len(rg) 40 | for var in range(1, chunk) 41 | let curline = line(".") 42 | if RrstIsInRCode(0) 43 | let i = search("^\\.\\. {r", "bnW") 44 | if i != 0 45 | call cursor(i-1, 1) 46 | endif 47 | endif 48 | let i = search("^\\.\\. {r", "bnW") 49 | if i == 0 50 | call cursor(curline, 1) 51 | call RWarningMsg("There is no previous R code chunk to go.") 52 | return 53 | else 54 | call cursor(i+1, 1) 55 | endif 56 | endfor 57 | return 58 | endfunction 59 | 60 | function! RrstNextChunk() range 61 | let rg = range(a:firstline, a:lastline) 62 | let chunk = len(rg) 63 | for var in range(1, chunk) 64 | let i = search("^\\.\\. {r", "nW") 65 | if i == 0 66 | call RWarningMsg("There is no next R code chunk to go.") 67 | return 68 | else 69 | call cursor(i+1, 1) 70 | endif 71 | endfor 72 | return 73 | endfunction 74 | 75 | function! RMakeHTMLrrst(t) 76 | call RSetWD() 77 | update 78 | if g:rplugin_has_rst2pdf == 0 79 | if executable("rst2pdf") 80 | let g:rplugin_has_rst2pdf = 1 81 | else 82 | call RWarningMsg("Is 'rst2pdf' application installed? Cannot convert into HTML/ODT: 'rst2pdf' executable not found.") 83 | return 84 | endif 85 | endif 86 | 87 | let rcmd = 'require(knitr)' 88 | if g:vimrplugin_strict_rst 89 | let rcmd = rcmd . '; render_rst(strict=TRUE)' 90 | endif 91 | let rcmd = rcmd . '; knit("' . expand("%:t") . '")' 92 | 93 | if a:t == "odt" 94 | let rcmd = rcmd . '; system("rst2odt ' . expand("%:r:t") . ".rst " . expand("%:r:t") . '.odt")' 95 | else 96 | let rcmd = rcmd . '; system("rst2html ' . expand("%:r:t") . ".rst " . expand("%:r:t") . '.html")' 97 | endif 98 | 99 | if g:vimrplugin_openhtml && a:t == "html" 100 | let rcmd = rcmd . '; browseURL("' . expand("%:r:t") . '.html")' 101 | endif 102 | call g:SendCmdToR(rcmd) 103 | endfunction 104 | 105 | function! RMakePDFrrst() 106 | if g:rplugin_vimcomport == 0 107 | call RWarningMsg("The vimcom package is required to make and open the PDF.") 108 | endif 109 | update 110 | call RSetWD() 111 | if g:rplugin_has_rst2pdf == 0 112 | if exists("g:vimrplugin_rst2pdfpath") && executable(g:vimrplugin_rst2pdfpath) 113 | let g:rplugin_has_rst2pdf = 1 114 | elseif executable("rst2pdf") 115 | let g:rplugin_has_rst2pdf = 1 116 | else 117 | call RWarningMsg("Is 'rst2pdf' application installed? Cannot convert into PDF: 'rst2pdf' executable not found.") 118 | return 119 | endif 120 | endif 121 | 122 | let rrstdir = expand("%:p:h") 123 | if has("win32") || has("win64") 124 | let rrstdir = substitute(rrstdir, '\\', '/', 'g') 125 | endif 126 | let pdfcmd = 'vim.interlace.rrst("' . expand("%:t") . '", rrstdir = "' . rrstdir . '"' 127 | if exists("g:vimrplugin_rrstcompiler") 128 | let pdfcmd = pdfcmd . ", compiler='" . g:vimrplugin_rrstcompiler . "'" 129 | endif 130 | if exists("g:vimrplugin_knitargs") 131 | let pdfcmd = pdfcmd . ", " . g:vimrplugin_knitargs 132 | endif 133 | if exists("g:vimrplugin_rst2pdfpath") 134 | let pdfcmd = pdfcmd . ", rst2pdfpath='" . g:vimrplugin_rst2pdfpath . "'" 135 | endif 136 | if exists("g:vimrplugin_rst2pdfargs") 137 | let pdfcmd = pdfcmd . ", " . g:vimrplugin_rst2pdfargs 138 | endif 139 | let pdfcmd = pdfcmd . ")" 140 | let ok = g:SendCmdToR(pdfcmd) 141 | if ok == 0 142 | return 143 | endif 144 | endfunction 145 | 146 | " Send Rrst chunk to R 147 | function! SendRrstChunkToR(e, m) 148 | if RrstIsInRCode(0) == 0 149 | call RWarningMsg("Not inside an R code chunk.") 150 | return 151 | endif 152 | let chunkline = search("^\\.\\. {r", "bncW") + 1 153 | let docline = search("^\\.\\. \\.\\.", "ncW") - 1 154 | let lines = getline(chunkline, docline) 155 | let ok = RSourceLines(lines, a:e) 156 | if ok == 0 157 | return 158 | endif 159 | if a:m == "down" 160 | call RrstNextChunk() 161 | endif 162 | endfunction 163 | 164 | let b:IsInRCode = function("RrstIsInRCode") 165 | let b:PreviousRChunk = function("RrstPreviousChunk") 166 | let b:NextRChunk = function("RrstNextChunk") 167 | let b:SendChunkToR = function("SendRrstChunkToR") 168 | 169 | "========================================================================== 170 | " Key bindings and menu items 171 | 172 | call RCreateStartMaps() 173 | call RCreateEditMaps() 174 | call RCreateSendMaps() 175 | call RControlMaps() 176 | call RCreateMaps("nvi", 'RSetwd', 'rd', ':call RSetWD()') 177 | 178 | " Only .Rrst files use these functions: 179 | call RCreateMaps("nvi", 'RKnit', 'kn', ':call RKnit()') 180 | call RCreateMaps("nvi", 'RMakePDFK', 'kp', ':call RMakePDFrrst()') 181 | call RCreateMaps("nvi", 'RMakeHTML', 'kh', ':call RMakeHTMLrrst("html")') 182 | call RCreateMaps("nvi", 'RMakeODT', 'ko', ':call RMakeHTMLrrst("odt")') 183 | call RCreateMaps("nvi", 'RIndent', 'si', ':call RrstToggleIndentSty()') 184 | call RCreateMaps("ni", 'RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")') 185 | call RCreateMaps("ni", 'RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")') 186 | call RCreateMaps("ni", 'RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")') 187 | call RCreateMaps("ni", 'REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")') 188 | call RCreateMaps("n", 'RNextRChunk', 'gn', ':call b:NextRChunk()') 189 | call RCreateMaps("n", 'RPreviousRChunk', 'gN', ':call b:PreviousRChunk()') 190 | 191 | " Menu R 192 | if has("gui_running") 193 | runtime r-plugin/gui_running.vim 194 | call MakeRMenu() 195 | endif 196 | 197 | let g:rplugin_has_rst2pdf = 0 198 | 199 | call RSourceOtherScripts() 200 | 201 | if exists("b:undo_ftplugin") 202 | let b:undo_ftplugin .= " | unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 203 | else 204 | let b:undo_ftplugin = "unlet! b:IsInRCode b:PreviousRChunk b:NextRChunk b:SendChunkToR" 205 | endif 206 | -------------------------------------------------------------------------------- /r-plugin/common_buffer.vim: -------------------------------------------------------------------------------- 1 | " This program is free software; you can redistribute it and/or modify 2 | " it under the terms of the GNU General Public License as published by 3 | " the Free Software Foundation; either version 2 of the License, or 4 | " (at your option) any later version. 5 | " 6 | " This program is distributed in the hope that it will be useful, 7 | " but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | " GNU General Public License for more details. 10 | " 11 | " A copy of the GNU General Public License is available at 12 | " http://www.r-project.org/Licenses/ 13 | 14 | "========================================================================== 15 | " ftplugin for R files 16 | " 17 | " Authors: Jakson Alves de Aquino 18 | " Jose Claudio Faria 19 | " 20 | " Based on previous work by Johannes Ranke 21 | " 22 | " Please see doc/r-plugin.txt for usage details. 23 | "========================================================================== 24 | 25 | 26 | " Set completion with CTRL-X CTRL-O to autoloaded function. 27 | if exists('&ofu') 28 | if &filetype == "rnoweb" || &filetype == "rrst" || &filetype == "rmd" 29 | let b:rplugin_nonr_omnifunc = &omnifunc 30 | endif 31 | if &filetype == "r" || &filetype == "rnoweb" || &filetype == "rdoc" || &filetype == "rhelp" || &filetype == "rrst" || &filetype == "rmd" 32 | setlocal omnifunc=rcomplete#CompleteR 33 | endif 34 | endif 35 | 36 | " This isn't the Object Browser running externally 37 | let b:rplugin_extern_ob = 0 38 | 39 | " Set the name of the Object Browser caption if not set yet 40 | let s:tnr = tabpagenr() 41 | if !exists("b:objbrtitle") 42 | if s:tnr == 1 43 | let b:objbrtitle = "Object_Browser" 44 | else 45 | let b:objbrtitle = "Object_Browser" . s:tnr 46 | endif 47 | unlet s:tnr 48 | endif 49 | 50 | let g:rplugin_lastft = &filetype 51 | 52 | if !exists("g:SendCmdToR") 53 | let g:SendCmdToR = function('SendCmdToR_fake') 54 | endif 55 | 56 | " Were new libraries loaded by R? 57 | if !exists("b:rplugin_new_libs") 58 | let b:rplugin_new_libs = 0 59 | endif 60 | " When using as a global plugin for non R files, RCheckLibList will not exist 61 | if exists("*RCheckLibList") 62 | autocmd BufEnter call RCheckLibList() 63 | endif 64 | 65 | -------------------------------------------------------------------------------- /r-plugin/functions.vim: -------------------------------------------------------------------------------- 1 | 2 | if has("nvim") 3 | finish 4 | endif 5 | 6 | " Only source this once 7 | if exists("*RmFromRLibList") 8 | if len(g:rplugin_lists_to_load) > 0 9 | for s:lib in g:rplugin_lists_to_load 10 | call SourceRFunList(s:lib) 11 | endfor 12 | unlet s:lib 13 | endif 14 | finish 15 | endif 16 | 17 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 18 | " Set global variables when this script is called for the first time 19 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 20 | 21 | " Users may define the value of g:vimrplugin_start_libs 22 | if !exists("g:vimrplugin_start_libs") 23 | let g:vimrplugin_start_libs = "base,stats,graphics,grDevices,utils,methods" 24 | endif 25 | 26 | let g:rplugin_lists_to_load = split(g:vimrplugin_start_libs, ",") 27 | let g:rplugin_debug_lists = [] 28 | let g:rplugin_loaded_lists = [] 29 | let g:rplugin_Rhelp_list = [] 30 | let g:rplugin_omni_lines = [] 31 | let g:rplugin_new_libs = 0 32 | 33 | " syntax/r.vim may have being called before ftplugin/r.vim 34 | if !exists("g:rplugin_compldir") 35 | runtime r-plugin/setcompldir.vim 36 | endif 37 | 38 | 39 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 40 | " Function for highlighting rFunction 41 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 42 | 43 | " Must be run for each buffer 44 | function SourceRFunList(lib) 45 | if isdirectory(g:rplugin_compldir) 46 | let fnf = split(globpath(g:rplugin_compldir, 'fun_' . a:lib . '_*'), "\n") 47 | if len(fnf) == 1 48 | " Highlight R functions 49 | exe "source " . substitute(fnf[0], ' ', '\\ ', 'g') 50 | elseif len(fnf) == 0 51 | let g:rplugin_debug_lists += ['Function list for "' . a:lib . '" not found.'] 52 | elseif len(fnf) > 1 53 | let g:rplugin_debug_lists += ['There is more than one function list for "' . a:lib . '".'] 54 | for obl in fnf 55 | let g:rplugin_debug_lists += [obl] 56 | endfor 57 | endif 58 | endif 59 | endfunction 60 | 61 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 62 | " Omnicompletion functions 63 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 64 | 65 | function RLisObjs(arglead, cmdline, curpos) 66 | let lob = [] 67 | let rkeyword = '^' . a:arglead 68 | for xx in g:rplugin_Rhelp_list 69 | if xx =~ rkeyword 70 | call add(lob, xx) 71 | endif 72 | endfor 73 | return lob 74 | endfunction 75 | 76 | function RmFromRLibList(lib) 77 | for idx in range(len(g:rplugin_loaded_lists)) 78 | if g:rplugin_loaded_lists[idx] == a:lib 79 | call remove(g:rplugin_loaded_lists, idx) 80 | break 81 | endif 82 | endfor 83 | for idx in range(len(g:rplugin_lists_to_load)) 84 | if g:rplugin_lists_to_load[idx] == a:lib 85 | call remove(g:rplugin_lists_to_load, idx) 86 | break 87 | endif 88 | endfor 89 | endfunction 90 | 91 | function AddToRLibList(lib) 92 | if isdirectory(g:rplugin_compldir) 93 | let omf = split(globpath(g:rplugin_compldir, 'omnils_' . a:lib . '_*'), "\n") 94 | if len(omf) == 1 95 | let g:rplugin_loaded_lists += [a:lib] 96 | 97 | " List of objects for omni completion 98 | let olist = readfile(omf[0]) 99 | let g:rplugin_omni_lines += olist 100 | 101 | " List of objects for :Rhelp completion 102 | for xx in olist 103 | let xxx = split(xx, "\x06") 104 | if len(xxx) > 0 && xxx[0] !~ '\$' 105 | call add(g:rplugin_Rhelp_list, xxx[0]) 106 | endif 107 | endfor 108 | elseif len(omf) == 0 109 | let g:rplugin_debug_lists += ['Omnils list for "' . a:lib . '" not found.'] 110 | call RmFromRLibList(a:lib) 111 | return 112 | elseif len(omf) > 1 113 | let g:rplugin_debug_lists += ['There is more than one omnils and function list for "' . a:lib . '".'] 114 | for obl in omf 115 | let g:rplugin_debug_lists += [obl] 116 | endfor 117 | call RmFromRLibList(a:lib) 118 | return 119 | endif 120 | endif 121 | endfunction 122 | 123 | 124 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 125 | " Function called by vimcom 126 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 127 | 128 | function FillRLibList() 129 | " Avoid crash (segmentation fault) 130 | if g:rplugin_starting_R 131 | let g:rplugin_fillrliblist_called = 1 132 | return 133 | endif 134 | 135 | " Update the list of objects for omnicompletion 136 | if filereadable(g:rplugin_tmpdir . "/libnames_" . $VIMINSTANCEID) 137 | let g:rplugin_lists_to_load = readfile(g:rplugin_tmpdir . "/libnames_" . $VIMINSTANCEID) 138 | for lib in g:rplugin_lists_to_load 139 | let isloaded = 0 140 | for olib in g:rplugin_loaded_lists 141 | if lib == olib 142 | let isloaded = 1 143 | break 144 | endif 145 | endfor 146 | if isloaded == 0 147 | call AddToRLibList(lib) 148 | endif 149 | endfor 150 | endif 151 | " Now we need to update the syntax in all R files. There should be a 152 | " better solution than setting a flag to let other buffers know that they 153 | " also need to update the syntax on CursorMoved event: 154 | " https://github.com/neovim/neovim/issues/901 155 | let g:rplugin_new_libs = len(g:rplugin_loaded_lists) 156 | silent exe 'set filetype=' . &filetype 157 | let b:rplugin_new_libs = g:rplugin_new_libs 158 | endfunction 159 | 160 | 161 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 162 | " Update the buffer syntax if necessary 163 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 164 | 165 | function RCheckLibList() 166 | if b:rplugin_new_libs == g:rplugin_new_libs 167 | return 168 | endif 169 | silent exe 'set filetype=' . &filetype 170 | let b:rplugin_new_libs = g:rplugin_new_libs 171 | endfunction 172 | 173 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 174 | " Source the Syntax scripts for the first time and Load omnilists 175 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 176 | 177 | for s:lib in g:rplugin_lists_to_load 178 | call SourceRFunList(s:lib) 179 | call AddToRLibList(s:lib) 180 | endfor 181 | 182 | unlet s:lib 183 | -------------------------------------------------------------------------------- /r-plugin/gui_running.vim: -------------------------------------------------------------------------------- 1 | " This file contains code used only if has("gui_running") 2 | 3 | if exists("g:did_r_plugin_gui_running") 4 | finish 5 | endif 6 | let g:did_r_plugin_gui_running = 1 7 | 8 | if exists('g:maplocalleader') 9 | let s:tll = '' . g:maplocalleader 10 | else 11 | let s:tll = '\\' 12 | endif 13 | 14 | function RCreateMenuItem(type, label, plug, combo, target) 15 | if a:type =~ '0' 16 | let tg = a:target . '0' 17 | let il = 'i' 18 | else 19 | let tg = a:target . '' 20 | let il = 'a' 21 | endif 22 | if a:type =~ "n" 23 | if hasmapto(a:plug, "n") 24 | let boundkey = RNMapCmd(a:plug) 25 | exec 'nmenu &R.' . a:label . '' . boundkey . ' ' . tg 26 | else 27 | exec 'nmenu &R.' . a:label . s:tll . a:combo . ' ' . tg 28 | endif 29 | endif 30 | if a:type =~ "v" 31 | if hasmapto(a:plug, "v") 32 | let boundkey = RVMapCmd(a:plug) 33 | exec 'vmenu &R.' . a:label . '' . boundkey . ' ' . '' . tg 34 | else 35 | exec 'vmenu &R.' . a:label . s:tll . a:combo . ' ' . '' . tg 36 | endif 37 | endif 38 | if a:type =~ "i" 39 | if hasmapto(a:plug, "i") 40 | let boundkey = RIMapCmd(a:plug) 41 | exec 'imenu &R.' . a:label . '' . boundkey . ' ' . '' . tg . il 42 | else 43 | exec 'imenu &R.' . a:label . s:tll . a:combo . ' ' . '' . tg . il 44 | endif 45 | endif 46 | endfunction 47 | 48 | function RBrowserMenu() 49 | call RCreateMenuItem("nvi", 'Object\ browser.Show/Update', 'RUpdateObjBrowser', 'ro', ':call RObjBrowser()') 50 | call RCreateMenuItem("nvi", 'Object\ browser.Expand\ (all\ lists)', 'ROpenLists', 'r=', ':call g:RBrOpenCloseLs(1)') 51 | call RCreateMenuItem("nvi", 'Object\ browser.Collapse\ (all\ lists)', 'RCloseLists', 'r-', ':call g:RBrOpenCloseLs(0)') 52 | if &filetype == "rbrowser" 53 | imenu R.Object\ browser.Toggle\ (cur)Enter :call RBrowserDoubleClick() 54 | nmenu R.Object\ browser.Toggle\ (cur)Enter :call RBrowserDoubleClick() 55 | endif 56 | let g:rplugin_hasmenu = 1 57 | endfunction 58 | 59 | function RControlMenu() 60 | call RCreateMenuItem("nvi", 'Command.List\ space', 'RListSpace', 'rl', ':call g:SendCmdToR("ls()")') 61 | call RCreateMenuItem("nvi", 'Command.Clear\ console\ screen', 'RClearConsole', 'rr', ':call RClearConsole()') 62 | call RCreateMenuItem("nvi", 'Command.Clear\ all', 'RClearAll', 'rm', ':call RClearAll()') 63 | "------------------------------- 64 | menu R.Command.-Sep1- 65 | call RCreateMenuItem("nvi", 'Command.Print\ (cur)', 'RObjectPr', 'rp', ':call RAction("print")') 66 | call RCreateMenuItem("nvi", 'Command.Names\ (cur)', 'RObjectNames', 'rn', ':call RAction("vim.names")') 67 | call RCreateMenuItem("nvi", 'Command.Structure\ (cur)', 'RObjectStr', 'rt', ':call RAction("str")') 68 | call RCreateMenuItem("nvi", 'Command.View\ data\.frame\ (cur)', 'RViewDF', 'rv', ':call RAction("viewdf")') 69 | "------------------------------- 70 | menu R.Command.-Sep2- 71 | call RCreateMenuItem("nvi", 'Command.Arguments\ (cur)', 'RShowArgs', 'ra', ':call RAction("args")') 72 | call RCreateMenuItem("nvi", 'Command.Example\ (cur)', 'RShowEx', 're', ':call RAction("example")') 73 | call RCreateMenuItem("nvi", 'Command.Help\ (cur)', 'RHelp', 'rh', ':call RAction("help")') 74 | "------------------------------- 75 | menu R.Command.-Sep3- 76 | call RCreateMenuItem("nvi", 'Command.Summary\ (cur)', 'RSummary', 'rs', ':call RAction("summary")') 77 | call RCreateMenuItem("nvi", 'Command.Plot\ (cur)', 'RPlot', 'rg', ':call RAction("plot")') 78 | call RCreateMenuItem("nvi", 'Command.Plot\ and\ summary\ (cur)', 'RSPlot', 'rb', ':call RAction("plotsumm")') 79 | let g:rplugin_hasmenu = 1 80 | endfunction 81 | 82 | function MakeRMenu() 83 | if g:rplugin_hasmenu == 1 84 | return 85 | endif 86 | 87 | " Do not translate "File": 88 | menutranslate clear 89 | 90 | "---------------------------------------------------------------------------- 91 | " Start/Close 92 | "---------------------------------------------------------------------------- 93 | call RCreateMenuItem("nvi", 'Start/Close.Start\ R\ (default)', 'RStart', 'rf', ':call StartR("R")') 94 | call RCreateMenuItem("nvi", 'Start/Close.Start\ R\ (custom)', 'RCustomStart', 'rc', ':call StartR("custom")') 95 | "------------------------------- 96 | menu R.Start/Close.-Sep1- 97 | call RCreateMenuItem("nvi", 'Start/Close.Close\ R\ (no\ save)', 'RClose', 'rq', ":call RQuit('no')") 98 | menu R.Start/Close.-Sep2- 99 | 100 | nmenu R.Start/Close.Stop\ R:RStop :RStop 101 | 102 | "---------------------------------------------------------------------------- 103 | " Send 104 | "---------------------------------------------------------------------------- 105 | if &filetype == "r" || g:vimrplugin_never_unmake_menu 106 | call RCreateMenuItem("ni", 'Send.File', 'RSendFile', 'aa', ':call SendFileToR("silent")') 107 | call RCreateMenuItem("ni", 'Send.File\ (echo)', 'RESendFile', 'ae', ':call SendFileToR("echo")') 108 | call RCreateMenuItem("ni", 'Send.File\ (open\ \.Rout)', 'RShowRout', 'ao', ':call ShowRout()') 109 | endif 110 | "------------------------------- 111 | menu R.Send.-Sep1- 112 | call RCreateMenuItem("ni", 'Send.Block\ (cur)', 'RSendMBlock', 'bb', ':call SendMBlockToR("silent", "stay")') 113 | call RCreateMenuItem("ni", 'Send.Block\ (cur,\ echo)', 'RESendMBlock', 'be', ':call SendMBlockToR("echo", "stay")') 114 | call RCreateMenuItem("ni", 'Send.Block\ (cur,\ down)', 'RDSendMBlock', 'bd', ':call SendMBlockToR("silent", "down")') 115 | call RCreateMenuItem("ni", 'Send.Block\ (cur,\ echo\ and\ down)', 'REDSendMBlock', 'ba', ':call SendMBlockToR("echo", "down")') 116 | "------------------------------- 117 | if &filetype == "rnoweb" || &filetype == "rmd" || &filetype == "rrst" || g:vimrplugin_never_unmake_menu 118 | menu R.Send.-Sep2- 119 | call RCreateMenuItem("ni", 'Send.Chunk\ (cur)', 'RSendChunk', 'cc', ':call b:SendChunkToR("silent", "stay")') 120 | call RCreateMenuItem("ni", 'Send.Chunk\ (cur,\ echo)', 'RESendChunk', 'ce', ':call b:SendChunkToR("echo", "stay")') 121 | call RCreateMenuItem("ni", 'Send.Chunk\ (cur,\ down)', 'RDSendChunk', 'cd', ':call b:SendChunkToR("silent", "down")') 122 | call RCreateMenuItem("ni", 'Send.Chunk\ (cur,\ echo\ and\ down)', 'REDSendChunk', 'ca', ':call b:SendChunkToR("echo", "down")') 123 | call RCreateMenuItem("ni", 'Send.Chunk\ (from\ first\ to\ here)', 'RSendChunkFH', 'ch', ':call SendFHChunkToR()') 124 | endif 125 | "------------------------------- 126 | menu R.Send.-Sep3- 127 | call RCreateMenuItem("ni", 'Send.Function\ (cur)', 'RSendFunction', 'ff', ':call SendFunctionToR("silent", "stay")') 128 | call RCreateMenuItem("ni", 'Send.Function\ (cur,\ echo)', 'RESendFunction', 'fe', ':call SendFunctionToR("echo", "stay")') 129 | call RCreateMenuItem("ni", 'Send.Function\ (cur\ and\ down)', 'RDSendFunction', 'fd', ':call SendFunctionToR("silent", "down")') 130 | call RCreateMenuItem("ni", 'Send.Function\ (cur,\ echo\ and\ down)', 'REDSendFunction', 'fa', ':call SendFunctionToR("echo", "down")') 131 | "------------------------------- 132 | menu R.Send.-Sep4- 133 | call RCreateMenuItem("v", 'Send.Selection', 'RSendSelection', 'ss', ':call SendSelectionToR("silent", "stay")') 134 | call RCreateMenuItem("v", 'Send.Selection\ (echo)', 'RESendSelection', 'se', ':call SendSelectionToR("echo", "stay")') 135 | call RCreateMenuItem("v", 'Send.Selection\ (and\ down)', 'RDSendSelection', 'sd', ':call SendSelectionToR("silent", "down")') 136 | call RCreateMenuItem("v", 'Send.Selection\ (echo\ and\ down)', 'REDSendSelection', 'sa', ':call SendSelectionToR("echo", "down")') 137 | call RCreateMenuItem("v", 'Send.Selection\ (and\ insert\ output)', 'RSendSelAndInsertOutput', 'so', ':call SendSelectionToR("echo", "stay", "NewtabInsert")') 138 | "------------------------------- 139 | menu R.Send.-Sep5- 140 | call RCreateMenuItem("ni", 'Send.Paragraph', 'RSendParagraph', 'pp', ':call SendParagraphToR("silent", "stay")') 141 | call RCreateMenuItem("ni", 'Send.Paragraph\ (echo)', 'RESendParagraph', 'pe', ':call SendParagraphToR("echo", "stay")') 142 | call RCreateMenuItem("ni", 'Send.Paragraph\ (and\ down)', 'RDSendParagraph', 'pd', ':call SendParagraphToR("silent", "down")') 143 | call RCreateMenuItem("ni", 'Send.Paragraph\ (echo\ and\ down)', 'REDSendParagraph', 'pa', ':call SendParagraphToR("echo", "down")') 144 | "------------------------------- 145 | menu R.Send.-Sep6- 146 | call RCreateMenuItem("ni0", 'Send.Line', 'RSendLine', 'l', ':call SendLineToR("stay")') 147 | call RCreateMenuItem("ni0", 'Send.Line\ (and\ down)', 'RDSendLine', 'd', ':call SendLineToR("down")') 148 | call RCreateMenuItem("ni0", 'Send.Line\ (and\ insert\ output)', 'RDSendLineAndInsertOutput', 'o', ':call SendLineToRAndInsertOutput()') 149 | call RCreateMenuItem("i", 'Send.Line\ (and\ new\ one)', 'RSendLAndOpenNewOne', 'q', ':call SendLineToR("newline")') 150 | call RCreateMenuItem("n", 'Send.Left\ part\ of\ line\ (cur)', 'RNLeftPart', 'r', ':call RSendPartOfLine("left", 0)') 151 | call RCreateMenuItem("n", 'Send.Right\ part\ of\ line\ (cur)', 'RNRightPart', 'r', ':call RSendPartOfLine("right", 0)') 152 | call RCreateMenuItem("i", 'Send.Left\ part\ of\ line\ (cur)', 'RILeftPart', 'r', 'l:call RSendPartOfLine("left", 1)') 153 | call RCreateMenuItem("i", 'Send.Right\ part\ of\ line\ (cur)', 'RIRightPart', 'r', 'l:call RSendPartOfLine("right", 1)') 154 | 155 | "---------------------------------------------------------------------------- 156 | " Control 157 | "---------------------------------------------------------------------------- 158 | call RControlMenu() 159 | "------------------------------- 160 | menu R.Command.-Sep4- 161 | if &filetype != "rdoc" 162 | call RCreateMenuItem("nvi", 'Command.Set\ working\ directory\ (cur\ file\ path)', 'RSetwd', 'rd', ':call RSetWD()') 163 | endif 164 | "------------------------------- 165 | if &filetype == "rnoweb" || &filetype == "rmd" || &filetype == "rrst" || g:vimrplugin_never_unmake_menu 166 | if &filetype == "rnoweb" || g:vimrplugin_never_unmake_menu 167 | menu R.Command.-Sep5- 168 | call RCreateMenuItem("nvi", 'Command.Sweave\ (cur\ file)', 'RSweave', 'sw', ':call RSweave()') 169 | call RCreateMenuItem("nvi", 'Command.Sweave\ and\ PDF\ (cur\ file)', 'RMakePDF', 'sp', ':call RMakePDF("nobib", 0)') 170 | call RCreateMenuItem("nvi", 'Command.Sweave,\ BibTeX\ and\ PDF\ (cur\ file)', 'RBibTeX', 'sb', ':call RMakePDF("bibtex", 0)') 171 | endif 172 | menu R.Command.-Sep6- 173 | if &filetype == "rnoweb" 174 | call RCreateMenuItem("nvi", 'Command.Knit\ (cur\ file)', 'RKnit', 'kn', ':call RKnitRnw()') 175 | else 176 | call RCreateMenuItem("nvi", 'Command.Knit\ (cur\ file)', 'RKnit', 'kn', ':call RKnit()') 177 | endif 178 | if &filetype == "rnoweb" || g:vimrplugin_never_unmake_menu 179 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ PDF\ (cur\ file)', 'RMakePDFK', 'kp', ':call RMakePDF("nobib", 1)') 180 | call RCreateMenuItem("nvi", 'Command.Knit,\ BibTeX\ and\ PDF\ (cur\ file)', 'RBibTeXK', 'kb', ':call RMakePDF("bibtex", 1)') 181 | endif 182 | if &filetype == "rmd" || g:vimrplugin_never_unmake_menu 183 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ PDF\ (cur\ file)', 'RMakePDFK', 'kp', ':call RMakeRmd("pdf_document")') 184 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ Beamer\ PDF\ (cur\ file)', 'RMakePDFKb', 'kl', ':call RMakeRmd("beamer_presentation")') 185 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ HTML\ (cur\ file)', 'RMakeHTML', 'kh', ':call RMakeRmd("html_document")') 186 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ ODT\ (cur\ file)', 'RMakeODT', 'ko', ':call RMakeRmd("odt")') 187 | endif 188 | if &filetype == "rrst" || g:vimrplugin_never_unmake_menu 189 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ PDF\ (cur\ file)', 'RMakePDFK', 'kp', ':call RMakePDFrrst()') 190 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ HTML\ (cur\ file)', 'RMakeHTML', 'kh', ':call RMakeHTMLrrst("html")') 191 | call RCreateMenuItem("nvi", 'Command.Knit\ and\ ODT\ (cur\ file)', 'RMakeODT', 'ko', ':call RMakeHTMLrrst("odt")') 192 | endif 193 | menu R.Command.-Sep61- 194 | call RCreateMenuItem("nvi", 'Command.Open\ PDF\ (cur\ file)', 'ROpenPDF', 'op', ':call ROpenPDF("Get Master")') 195 | if ($DISPLAY != "" && g:vimrplugin_synctex && &filetype == "rnoweb") || g:vimrplugin_never_unmake_menu 196 | call RCreateMenuItem("nvi", 'Command.Search\ forward\ (SyncTeX)', 'RSyncFor', 'gp', ':call SyncTeX_forward()') 197 | call RCreateMenuItem("nvi", 'Command.Go\ to\ LaTeX\ (SyncTeX)', 'RSyncTex', 'gt', ':call SyncTeX_forward(1)') 198 | endif 199 | endif 200 | "------------------------------- 201 | if &filetype == "r" || g:vimrplugin_never_unmake_menu 202 | menu R.Command.-Sep71- 203 | call RCreateMenuItem("nvi", 'Command.Spin\ (cur\ file)', 'RSpinFile', 'ks', ':call RSpin()') 204 | endif 205 | menu R.Command.-Sep72- 206 | if &filetype == "r" || &filetype == "rnoweb" || g:vimrplugin_never_unmake_menu 207 | nmenu R.Command.Build\ tags\ file\ (cur\ dir):RBuildTags :call g:SendCmdToR('rtags(ofile = "TAGS")') 208 | imenu R.Command.Build\ tags\ file\ (cur\ dir):RBuildTags :call g:SendCmdToR('rtags(ofile = "TAGS")')a 209 | endif 210 | 211 | menu R.-Sep7- 212 | 213 | "---------------------------------------------------------------------------- 214 | " Edit 215 | "---------------------------------------------------------------------------- 216 | if &filetype == "r" || &filetype == "rnoweb" || &filetype == "rrst" || &filetype == "rhelp" || g:vimrplugin_never_unmake_menu 217 | if g:vimrplugin_assign == 1 || g:vimrplugin_assign == 2 218 | silent exe 'imenu R.Edit.Insert\ \"\ <-\ \"' . g:vimrplugin_assign_map . ' :call ReplaceUnderS()a' 219 | endif 220 | imenu R.Edit.Complete\ object\ name^X^O 221 | if hasmapto("RCompleteArgs", "i") 222 | let boundkey = RIMapCmd("RCompleteArgs") 223 | exe "imenu R.Edit.Complete\\ function\\ arguments" . boundkey . " " . boundkey 224 | else 225 | imenu R.Edit.Complete\ function\ arguments^X^A 226 | endif 227 | menu R.Edit.-Sep71- 228 | nmenu R.Edit.Indent\ (line)== == 229 | vmenu R.Edit.Indent\ (selected\ lines)= = 230 | nmenu R.Edit.Indent\ (whole\ buffer)gg=G gg=G 231 | menu R.Edit.-Sep72- 232 | call RCreateMenuItem("ni", 'Edit.Toggle\ comment\ (line/sel)', 'RToggleComment', 'xx', ':call RComment("normal")') 233 | call RCreateMenuItem("v", 'Edit.Toggle\ comment\ (line/sel)', 'RToggleComment', 'xx', ':call RComment("selection")') 234 | call RCreateMenuItem("ni", 'Edit.Comment\ (line/sel)', 'RSimpleComment', 'xc', ':call RSimpleCommentLine("normal", "c")') 235 | call RCreateMenuItem("v", 'Edit.Comment\ (line/sel)', 'RSimpleComment', 'xc', ':call RSimpleCommentLine("selection", "c")') 236 | call RCreateMenuItem("ni", 'Edit.Uncomment\ (line/sel)', 'RSimpleUnComment', 'xu', ':call RSimpleCommentLine("normal", "u")') 237 | call RCreateMenuItem("v", 'Edit.Uncomment\ (line/sel)', 'RSimpleUnComment', 'xu', ':call RSimpleCommentLine("selection", "u")') 238 | call RCreateMenuItem("ni", 'Edit.Add/Align\ right\ comment\ (line,\ sel)', 'RRightComment', ';', ':call MovePosRCodeComment("normal")') 239 | call RCreateMenuItem("v", 'Edit.Add/Align\ right\ comment\ (line,\ sel)', 'RRightComment', ';', ':call MovePosRCodeComment("selection")') 240 | if &filetype == "rnoweb" || &filetype == "rrst" || &filetype == "rmd" || g:vimrplugin_never_unmake_menu 241 | menu R.Edit.-Sep73- 242 | call RCreateMenuItem("n", 'Edit.Go\ (next\ R\ chunk)', 'RNextRChunk', 'gn', ':call b:NextRChunk()') 243 | call RCreateMenuItem("n", 'Edit.Go\ (previous\ R\ chunk)', '', 'gN', ':call b:PreviousRChunk()') 244 | endif 245 | endif 246 | 247 | "---------------------------------------------------------------------------- 248 | " Object Browser 249 | "---------------------------------------------------------------------------- 250 | call RBrowserMenu() 251 | 252 | "---------------------------------------------------------------------------- 253 | " Help 254 | "---------------------------------------------------------------------------- 255 | menu R.-Sep8- 256 | amenu R.Help\ (plugin).Overview :help r-plugin-overview 257 | amenu R.Help\ (plugin).Main\ features :help r-plugin-features 258 | amenu R.Help\ (plugin).Installation :help r-plugin-installation 259 | amenu R.Help\ (plugin).Use :help r-plugin-use 260 | amenu R.Help\ (plugin).Known\ bugs\ and\ workarounds :help r-plugin-known-bugs 261 | 262 | amenu R.Help\ (plugin).Options.Assignment\ operator\ and\ Rnoweb\ code :help vimrplugin_assign 263 | amenu R.Help\ (plugin).Options.Object\ Browser :help vimrplugin_objbr_place 264 | amenu R.Help\ (plugin).Options.Vim\ as\ pager\ for\ R\ help :help vimrplugin_vimpager 265 | if !(has("gui_win32") || has("gui_win64")) 266 | amenu R.Help\ (plugin).Options.Terminal\ emulator :help vimrplugin_term 267 | endif 268 | if g:rplugin_is_darwin 269 | amenu R.Help\ (plugin).Options.Integration\ with\ Apple\ Script :help vimrplugin_applescript 270 | endif 271 | if has("gui_win32") || has("gui_win64") 272 | amenu R.Help\ (plugin).Options.Use\ 32\ bit\ version\ of\ R :help vimrplugin_i386 273 | endif 274 | amenu R.Help\ (plugin).Options.R\ path :help vimrplugin_r_path 275 | amenu R.Help\ (plugin).Options.Arguments\ to\ R :help vimrplugin_r_args 276 | amenu R.Help\ (plugin).Options.Omni\ completion\ when\ R\ not\ running :help vimrplugin_start_libs 277 | amenu R.Help\ (plugin).Options.Syntax\ highlighting\ of\ \.Rout\ files :help vimrplugin_routmorecolors 278 | amenu R.Help\ (plugin).Options.Automatically\ open\ the\ \.Rout\ file :help vimrplugin_routnotab 279 | amenu R.Help\ (plugin).Options.Special\ R\ functions :help vimrplugin_listmethods 280 | amenu R.Help\ (plugin).Options.Indent\ commented\ lines :help vimrplugin_indent_commented 281 | amenu R.Help\ (plugin).Options.LaTeX\ command :help vimrplugin_latexcmd 282 | amenu R.Help\ (plugin).Options.Never\ unmake\ the\ R\ menu :help vimrplugin_never_unmake_menu 283 | 284 | amenu R.Help\ (plugin).Custom\ key\ bindings :help r-plugin-key-bindings 285 | amenu R.Help\ (plugin).Files :help r-plugin-files 286 | amenu R.Help\ (plugin).FAQ\ and\ tips.All\ tips :help r-plugin-tips 287 | amenu R.Help\ (plugin).FAQ\ and\ tips.Indenting\ setup :help r-plugin-indenting 288 | amenu R.Help\ (plugin).FAQ\ and\ tips.Folding\ setup :help r-plugin-folding 289 | amenu R.Help\ (plugin).FAQ\ and\ tips.Remap\ LocalLeader :help r-plugin-localleader 290 | amenu R.Help\ (plugin).FAQ\ and\ tips.Customize\ key\ bindings :help r-plugin-bindings 291 | amenu R.Help\ (plugin).FAQ\ and\ tips.ShowMarks :help r-plugin-showmarks 292 | amenu R.Help\ (plugin).FAQ\ and\ tips.SnipMate :help r-plugin-snippets 293 | amenu R.Help\ (plugin).FAQ\ and\ tips.LaTeX-Box :help r-plugin-latex-box 294 | amenu R.Help\ (plugin).FAQ\ and\ tips.Highlight\ marks :help r-plugin-showmarks 295 | amenu R.Help\ (plugin).FAQ\ and\ tips.Global\ plugin :help r-plugin-global 296 | amenu R.Help\ (plugin).FAQ\ and\ tips.Jump\ to\ function\ definitions :help r-plugin-tagsfile 297 | amenu R.Help\ (plugin).News :help r-plugin-news 298 | 299 | amenu R.Help\ (R):Rhelp :call g:SendCmdToR("help.start()") 300 | let g:rplugin_hasmenu = 1 301 | 302 | "---------------------------------------------------------------------------- 303 | " ToolBar 304 | "---------------------------------------------------------------------------- 305 | if g:rplugin_has_icons 306 | " Buttons 307 | amenu ToolBar.RStart :call StartR("R") 308 | amenu ToolBar.RClose :call RQuit('no') 309 | "--------------------------- 310 | if &filetype == "r" || g:vimrplugin_never_unmake_menu 311 | nmenu ToolBar.RSendFile :call SendFileToR("echo") 312 | imenu ToolBar.RSendFile :call SendFileToR("echo") 313 | let g:rplugin_hasRSFbutton = 1 314 | endif 315 | nmenu ToolBar.RSendBlock :call SendMBlockToR("echo", "down") 316 | imenu ToolBar.RSendBlock :call SendMBlockToR("echo", "down") 317 | nmenu ToolBar.RSendFunction :call SendFunctionToR("echo", "down") 318 | imenu ToolBar.RSendFunction :call SendFunctionToR("echo", "down") 319 | vmenu ToolBar.RSendSelection :call SendSelectionToR("echo", "down") 320 | nmenu ToolBar.RSendParagraph :call SendParagraphToR("echo", "down") 321 | imenu ToolBar.RSendParagraph :call SendParagraphToR("echo", "down") 322 | nmenu ToolBar.RSendLine :call SendLineToR("down") 323 | imenu ToolBar.RSendLine :call SendLineToR("down") 324 | "--------------------------- 325 | nmenu ToolBar.RListSpace :call g:SendCmdToR("ls()") 326 | imenu ToolBar.RListSpace :call g:SendCmdToR("ls()") 327 | nmenu ToolBar.RClear :call RClearConsole() 328 | imenu ToolBar.RClear :call RClearConsole() 329 | nmenu ToolBar.RClearAll :call RClearAll() 330 | imenu ToolBar.RClearAll :call RClearAll() 331 | 332 | " Hints 333 | tmenu ToolBar.RStart Start R (default) 334 | tmenu ToolBar.RClose Close R (no save) 335 | if &filetype == "r" || g:vimrplugin_never_unmake_menu 336 | tmenu ToolBar.RSendFile Send file (echo) 337 | endif 338 | tmenu ToolBar.RSendBlock Send block (cur, echo and down) 339 | tmenu ToolBar.RSendFunction Send function (cur, echo and down) 340 | tmenu ToolBar.RSendSelection Send selection (cur, echo and down) 341 | tmenu ToolBar.RSendParagraph Send paragraph (cur, echo and down) 342 | tmenu ToolBar.RSendLine Send line (cur and down) 343 | tmenu ToolBar.RListSpace List objects 344 | tmenu ToolBar.RClear Clear the console screen 345 | tmenu ToolBar.RClearAll Remove objects from workspace and clear the console screen 346 | let g:rplugin_hasbuttons = 1 347 | else 348 | let g:rplugin_hasbuttons = 0 349 | endif 350 | endfunction 351 | 352 | function UnMakeRMenu() 353 | if g:rplugin_hasmenu == 0 || g:vimrplugin_never_unmake_menu == 1 || &previewwindow || (&buftype == "nofile" && &filetype != "rbrowser") 354 | return 355 | endif 356 | aunmenu R 357 | let g:rplugin_hasmenu = 0 358 | if g:rplugin_hasbuttons 359 | aunmenu ToolBar.RClearAll 360 | aunmenu ToolBar.RClear 361 | aunmenu ToolBar.RListSpace 362 | aunmenu ToolBar.RSendLine 363 | aunmenu ToolBar.RSendSelection 364 | aunmenu ToolBar.RSendParagraph 365 | aunmenu ToolBar.RSendFunction 366 | aunmenu ToolBar.RSendBlock 367 | if g:rplugin_hasRSFbutton 368 | aunmenu ToolBar.RSendFile 369 | let g:rplugin_hasRSFbutton = 0 370 | endif 371 | aunmenu ToolBar.RClose 372 | aunmenu ToolBar.RStart 373 | let g:rplugin_hasbuttons = 0 374 | endif 375 | endfunction 376 | 377 | function MakeRBrowserMenu() 378 | let g:rplugin_curbuf = bufname("%") 379 | if g:rplugin_hasmenu == 1 380 | return 381 | endif 382 | menutranslate clear 383 | call RControlMenu() 384 | call RBrowserMenu() 385 | endfunction 386 | 387 | -------------------------------------------------------------------------------- /r-plugin/osx.vim: -------------------------------------------------------------------------------- 1 | " This file contains code used only on OS X 2 | 3 | function StartR_OSX() 4 | if IsSendCmdToRFake() 5 | return 6 | endif 7 | if g:rplugin_r64app && g:vimrplugin_i386 == 0 8 | let rcmd = "/Applications/R64.app" 9 | else 10 | let rcmd = "/Applications/R.app" 11 | endif 12 | 13 | if b:rplugin_r_args != " " 14 | " https://github.com/jcfaria/Vim-R-plugin/issues/63 15 | " https://stat.ethz.ch/pipermail/r-sig-mac/2013-February/009978.html 16 | call RWarningMsg('R.app does not support command line arguments. To pass "' . b:rplugin_r_args . '" to R, you must run it in a console. Set "vimrplugin_applescript = 0"') 17 | endif 18 | let rlog = system("open " . rcmd) 19 | if v:shell_error 20 | call RWarningMsg(rlog) 21 | endif 22 | let g:SendCmdToR = function('SendCmdToR_OSX') 23 | if WaitVimComStart() 24 | call SendToVimCom("\005B Update OB [StartR]") 25 | sleep 200m 26 | if g:vimrplugin_after_start != '' 27 | call system(g:vimrplugin_after_start) 28 | endif 29 | endif 30 | endfunction 31 | 32 | function SendCmdToR_OSX(cmd) 33 | if g:vimrplugin_ca_ck 34 | let cmd = "\001" . "\013" . a:cmd 35 | else 36 | let cmd = a:cmd 37 | endif 38 | 39 | if g:rplugin_r64app && g:vimrplugin_i386 == 0 40 | let rcmd = "R64" 41 | else 42 | let rcmd = "R" 43 | endif 44 | 45 | " for some reason it doesn't like "\025" 46 | let cmd = a:cmd 47 | let cmd = substitute(cmd, "\\", '\\\', 'g') 48 | let cmd = substitute(cmd, '"', '\\"', "g") 49 | let cmd = substitute(cmd, "'", "'\\\\''", "g") 50 | call system("osascript -e 'tell application \"".rcmd."\" to cmd \"" . cmd . "\"'") 51 | return 1 52 | endfunction 53 | 54 | -------------------------------------------------------------------------------- /r-plugin/r.snippets: -------------------------------------------------------------------------------- 1 | # library() 2 | snippet li 3 | library(${1:}) 4 | # If Condition 5 | snippet if 6 | if(${1:condition}){ 7 | ${2:} 8 | } 9 | snippet el 10 | else { 11 | ${1:} 12 | } 13 | snippet wh 14 | while(${1:condition}){ 15 | ${2:} 16 | } 17 | # For Loop 18 | snippet for 19 | for(${1:i} in ${2:range}){ 20 | ${3:} 21 | } 22 | # Function 23 | snippet fun 24 | ${1:funname} <- function(${2:}) 25 | { 26 | ${3:} 27 | } 28 | # repeat 29 | snippet re 30 | repeat{ 31 | ${2:} 32 | if(${1:condition}) break 33 | } 34 | -------------------------------------------------------------------------------- /r-plugin/rmd.snippets: -------------------------------------------------------------------------------- 1 | # 2 | # Snipmate Snippets for Pandoc Markdown 3 | # 4 | # Many snippets have starred versions, i.e., versions 5 | # that end with an asterisk (`*`). These snippets use 6 | # vim's `"*` register---i.e., the contents of the 7 | # system clipboard---to insert text. 8 | 9 | # Insert Title Block 10 | snippet %% 11 | % ${1:`Filename('', 'title')`} 12 | % ${2:`g:snips_author`} 13 | % ${3:`strftime("%d %B %Y")`} 14 | 15 | ${4} 16 | snippet %%* 17 | % ${1:`Filename('', @*)`} 18 | % ${2:`g:snips_author`} 19 | % ${3:`strftime("%d %b %Y")`} 20 | 21 | ${4} 22 | 23 | # Insert Definition List 24 | snippet :: 25 | ${1:term} 26 | ~ ${2:definition} 27 | 28 | # Underline with `=`s or `-`s 29 | snippet === 30 | `repeat('=', strlen(getline(line(".") - 1)))` 31 | 32 | ${1} 33 | snippet --- 34 | `repeat('-', strlen(getline(line(".") - 1)))` 35 | 36 | ${1} 37 | 38 | # Links and their kin 39 | # ------------------- 40 | # 41 | # (These don't play very well with delimitMate) 42 | # 43 | 44 | snippet [ 45 | [${1:link}](http://${2:url} "${3:title}")${4} 46 | snippet [* 47 | [${1:link}](${2:`@*`} "${3:title}")${4} 48 | 49 | snippet [: 50 | [${1:id}]: http://${2:url} "${3:title}" 51 | snippet [:* 52 | [${1:id}]: ${2:`@*`} "${3:title}" 53 | 54 | snippet [@ 55 | [${1:link}](mailto:${2:email})${3} 56 | snippet [@* 57 | [${1:link}](mailto:${2:`@*`})${3} 58 | 59 | snippet [:@ 60 | [${1:id}]: mailto:${2:email} "${3:title}" 61 | snippet [:@* 62 | [${1:id}]: mailto:${2:`@*`} "${3:title}" 63 | 64 | snippet ![ 65 | ![${1:alt}](${2:url} "${3:title}")${4} 66 | snippet ![* 67 | ![${1:alt}](${2:`@*`} "${3:title}")${4} 68 | 69 | snippet ![: 70 | ![${1:id}]: ${2:url} "${3:title}" 71 | snippet ![:* 72 | ![${1:id}]: ${2:`@*`} "${3:title}" 73 | 74 | snippet [^: 75 | [^${1:id}]: ${2:note} 76 | snippet [^:* 77 | [^${1:id}]: ${2:`@*`} 78 | 79 | # 80 | 81 | # library() 82 | snippet req 83 | require(${1:}, quietly = TRUE) 84 | # If Condition 85 | snippet if 86 | if ( ${1:condition} ) 87 | { 88 | ${2:} 89 | } 90 | snippet el 91 | else 92 | { 93 | ${1:} 94 | } 95 | 96 | # Function 97 | snippet fun 98 | ${1:funname} <- # ${2:} 99 | function 100 | ( 101 | ${3:} 102 | ) 103 | { 104 | ${4:} 105 | } 106 | # repeat 107 | snippet re 108 | repeat{ 109 | ${2:} 110 | if(${1:condition}) break 111 | } 112 | 113 | # matrix 114 | snippet ma 115 | matrix(NA, nrow = ${1:}, ncol = ${2:}) 116 | 117 | # data frame 118 | snippet df 119 | data.frame(${1:}, header = TRUE) 120 | 121 | snippet cmdarg 122 | args <- commandArgs(TRUE) 123 | if (length(args) == 0) 124 | stop("Please give ${1:}!") 125 | if (!all(file.exists(args))) 126 | stop("Couln't find input files!") 127 | 128 | snippet getopt 129 | require('getopt', quietly = TRUE) 130 | opt_spec <- matrix(c( 131 | 'help', 'h', 0, "logical", "Getting help", 132 | 'file', 'f', 1, "character","File to process" 133 | ), ncol = 5, byrow = TRUE) 134 | opt <- getopt(spec = opt_spec) 135 | if ( !is.null(opt$help) || is.null(commandArgs()) ) { 136 | cat(getopt(spec = opt_spec, usage = TRUE, command = "yourCmd")) 137 | q(status=0) 138 | } 139 | # some inital value 140 | if ( is.null(opt$???) ) { opt$??? <- ??? } 141 | 142 | snippet optparse 143 | require("optparse", quietly = TRUE) 144 | option_list <- 145 | list(make_option(c("-n", "--add_numbers"), action="store_true", default=FALSE, 146 | help="Print line number at the beginning of each line [default]") 147 | ) 148 | parser <- OptionParser(usage = "%prog [options] file", option_list=option_list) 149 | arguments <- parse_args(parser, positional_arguments = TRUE) 150 | opt <- arguments$options 151 | 152 | if(length(arguments$args) != 1) { 153 | cat("Incorrect number of required positional arguments\n\n") 154 | print_help(parser) 155 | stop() 156 | } else { 157 | file <- arguments$args 158 | } 159 | 160 | if( file.access(file) == -1) { 161 | stop(sprintf("Specified file ( %s ) does not exist", file)) 162 | } else { 163 | file_text <- readLines(file) 164 | } 165 | 166 | snippet #! 167 | #!/usr/bin/env Rscript 168 | 169 | snippet debug 170 | # Development & Debugging, don't forget to uncomment afterwards! 171 | #-------------------------------------------------------------------------------- 172 | #setwd("~/Projekte/${1:}") 173 | #opt <- list(${2:} 174 | # ) 175 | #-------------------------------------------------------------------------------- 176 | 177 | 178 | # Took from pandoc-plugin <<<< 179 | # Underline with `=`s or `-`s 180 | snippet #=== 181 | #`repeat('=', strlen(getline(line(".") - 1)))` 182 | ${1} 183 | snippet #--- 184 | #`repeat('-', strlen(getline(line(".") - 1)))` 185 | ${1} 186 | 187 | # >>>> 188 | 189 | snippet r 190 | \`\`\`{r ${1:chung_tag}, echo = FALSE ${2:options}} 191 | ${3:} 192 | \`\`\` 193 | snippet ri 194 | \`{r ${1:}}\` 195 | 196 | snippet copt 197 | \`\`\` {r setup, echo = FALSE} 198 | opts_chunk$set(fig.path='../figures/${1:}', cache.path='../cache/-' 199 | , fig.align='center', fig.show='hold', par=TRUE) 200 | #opts_knit$set(upload.fun = imgur_upload) # upload images 201 | \`\`\` 202 | 203 | 204 | # End of File =================================================================== 205 | # vim: set noexpandtab: 206 | -------------------------------------------------------------------------------- /r-plugin/setcompldir.vim: -------------------------------------------------------------------------------- 1 | 2 | " g:rplugin_home should be the directory where the r-plugin files are. For 3 | " users following the installation instructions it will be at ~/.vim or 4 | " ~/vimfiles, that is, the same value of g:rplugin_uservimfiles. However the 5 | " variables will have different values if the plugin is installed somewhere 6 | " else in the runtimepath. 7 | let g:rplugin_home = expand(":h:h") 8 | 9 | " g:rplugin_uservimfiles must be a writable directory. It will be g:rplugin_home 10 | " unless it's not writable. Then it wil be ~/.vim or ~/vimfiles. 11 | if filewritable(g:rplugin_home) == 2 12 | let g:rplugin_uservimfiles = g:rplugin_home 13 | else 14 | let g:rplugin_uservimfiles = split(&runtimepath, ",")[0] 15 | endif 16 | 17 | " From changelog.vim, with bug fixed by "Si" ("i5ivem") 18 | " Windows logins can include domain, e.g: 'DOMAIN\Username', need to remove 19 | " the backslash from this as otherwise cause file path problems. 20 | if executable("whoami") 21 | let g:rplugin_userlogin = substitute(system('whoami'), "\\", "-", "") 22 | elseif $USER != "" 23 | let g:rplugin_userlogin = $USER 24 | else 25 | call RWarningMsgInp("Could not determine user name.") 26 | let g:rplugin_failed = 1 27 | finish 28 | endif 29 | 30 | if v:shell_error 31 | let g:rplugin_userlogin = 'unknown' 32 | else 33 | let newuline = stridx(g:rplugin_userlogin, "\n") 34 | if newuline != -1 35 | let g:rplugin_userlogin = strpart(g:rplugin_userlogin, 0, newuline) 36 | endif 37 | unlet newuline 38 | endif 39 | 40 | if has("win32") || has("win64") 41 | let g:rplugin_home = substitute(g:rplugin_home, "\\", "/", "g") 42 | let g:rplugin_uservimfiles = substitute(g:rplugin_uservimfiles, "\\", "/", "g") 43 | if $USERNAME != "" 44 | let g:rplugin_userlogin = substitute($USERNAME, " ", "", "g") 45 | endif 46 | endif 47 | 48 | if exists("g:vimrplugin_compldir") 49 | let g:rplugin_compldir = expand(g:vimrplugin_compldir) 50 | elseif (has("win32") || has("win64")) && $AppData != "" && isdirectory($AppData) 51 | let g:rplugin_compldir = $AppData . "\\Vim-R-plugin" 52 | elseif $XDG_CACHE_HOME != "" && isdirectory($XDG_CACHE_HOME) 53 | let g:rplugin_compldir = $XDG_CACHE_HOME . "/Vim-R-plugin" 54 | elseif isdirectory(expand("~/.cache")) 55 | let g:rplugin_compldir = expand("~/.cache/Vim-R-plugin") 56 | elseif isdirectory(expand("~/Library/Caches")) 57 | let g:rplugin_compldir = expand("~/Library/Caches/Vim-R-plugin") 58 | else 59 | let g:rplugin_compldir = g:rplugin_uservimfiles . "/r-plugin/objlist/" 60 | endif 61 | 62 | " Create the directory if it doesn't exist yet 63 | if !isdirectory(g:rplugin_compldir) 64 | call mkdir(g:rplugin_compldir, "p") 65 | if !filereadable(g:rplugin_compldir . "/README") 66 | let readme = ['The omnils_ and fun_ files in this directory are generated by Vim-R-plugin', 67 | \ 'and vimcom and are used for omni completion and syntax highlight.', 68 | \ '', 69 | \ 'When you load a new version of a library, their files are replaced.', 70 | \ '', 71 | \ 'You should manually delete files corresponding to libraries that you no', 72 | \ 'longer use.'] 73 | call writefile(readme, g:rplugin_compldir . "/README") 74 | endif 75 | endif 76 | let $VIMRPLUGIN_COMPLDIR = g:rplugin_compldir 77 | 78 | -------------------------------------------------------------------------------- /r-plugin/synctex_evince_backward.py: -------------------------------------------------------------------------------- 1 | 2 | # The code in this files is borrowed from Gedit Synctex plugin. 3 | # 4 | # Copyright (C) 2010 Jose Aliste 5 | # 6 | # This program is free software; you can redistribute it and/or modify it under 7 | # the terms of the GNU General Public Licence as published by the Free Software 8 | # Foundation; either version 2 of the Licence, or (at your option) any later 9 | # version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but WITHOUT 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more 14 | # details. 15 | # 16 | # You should have received a copy of the GNU General Public Licence along with 17 | # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | 20 | # Modified to Vim-R-plugin by Jakson Aquino 21 | 22 | import dbus, subprocess, time 23 | import dbus.mainloop.glib, sys, os, signal 24 | from gi.repository import GObject 25 | 26 | RUNNING, CLOSED = range(2) 27 | 28 | EV_DAEMON_PATH = "/org/gnome/evince/Daemon" 29 | EV_DAEMON_NAME = "org.gnome.evince.Daemon" 30 | EV_DAEMON_IFACE = "org.gnome.evince.Daemon" 31 | 32 | EVINCE_PATH = "/org/gnome/evince/Evince" 33 | EVINCE_IFACE = "org.gnome.evince.Application" 34 | 35 | EV_WINDOW_IFACE = "org.gnome.evince.Window" 36 | 37 | class EvinceWindowProxy: 38 | """A DBUS proxy for an Evince Window.""" 39 | daemon = None 40 | bus = None 41 | 42 | def __init__(self, uri, spawn = False): 43 | self.uri = uri 44 | self.spawn = spawn 45 | self.status = CLOSED 46 | self.dbus_name = '' 47 | self._handler = None 48 | try: 49 | if EvinceWindowProxy.bus is None: 50 | EvinceWindowProxy.bus = dbus.SessionBus() 51 | 52 | if EvinceWindowProxy.daemon is None: 53 | EvinceWindowProxy.daemon = EvinceWindowProxy.bus.get_object(EV_DAEMON_NAME, 54 | EV_DAEMON_PATH, 55 | follow_name_owner_changes=True) 56 | EvinceWindowProxy.bus.add_signal_receiver(self._on_doc_loaded, signal_name="DocumentLoaded", 57 | dbus_interface = EV_WINDOW_IFACE, 58 | sender_keyword='sender') 59 | self._get_dbus_name(False) 60 | 61 | except dbus.DBusException: 62 | sys.stderr.write("Could not connect to the Evince Daemon") 63 | sys.stderr.flush() 64 | loop.quit() 65 | 66 | def _on_doc_loaded(self, uri, **keyargs): 67 | if uri == self.uri and self._handler is None: 68 | self.handle_find_document_reply(keyargs['sender']) 69 | 70 | def _get_dbus_name(self, spawn): 71 | EvinceWindowProxy.daemon.FindDocument(self.uri,spawn, 72 | reply_handler=self.handle_find_document_reply, 73 | error_handler=self.handle_find_document_error, 74 | dbus_interface = EV_DAEMON_IFACE) 75 | 76 | def handle_find_document_error(self, error): 77 | sys.stderr.write("FindDocument DBus call has failed") 78 | sys.stderr.flush() 79 | 80 | def handle_find_document_reply(self, evince_name): 81 | if self._handler is not None: 82 | handler = self._handler 83 | else: 84 | handler = self.handle_get_window_list_reply 85 | if evince_name != '': 86 | self.dbus_name = evince_name 87 | self.status = RUNNING 88 | self.evince = EvinceWindowProxy.bus.get_object(self.dbus_name, EVINCE_PATH) 89 | self.evince.GetWindowList(dbus_interface = EVINCE_IFACE, 90 | reply_handler = handler, 91 | error_handler = self.handle_get_window_list_error) 92 | 93 | def handle_get_window_list_error (self, e): 94 | sys.stderr.write("GetWindowList DBus call has failed") 95 | sys.stderr.flush() 96 | 97 | def handle_get_window_list_reply (self, window_list): 98 | if len(window_list) > 0: 99 | window_obj = EvinceWindowProxy.bus.get_object(self.dbus_name, window_list[0]) 100 | self.window = dbus.Interface(window_obj,EV_WINDOW_IFACE) 101 | self.window.connect_to_signal("Closed", self.on_window_close) 102 | self.window.connect_to_signal("SyncSource", self.on_sync_source) 103 | else: 104 | #That should never happen. 105 | sys.stderr.write("GetWindowList returned empty list") 106 | sys.stderr.flush() 107 | 108 | def on_window_close(self): 109 | self.window = None 110 | self.status = CLOSED 111 | 112 | def on_sync_source(self, input_file, source_link, timestamp): 113 | input_file = input_file.replace("file://", "") 114 | input_file = input_file.replace("%20", " ") 115 | os.system(vimexec + ' --servername ' + vimnm + ' --remote-expr "' + "SyncTeX_backward('" + input_file + "', " + str(source_link[0]) + ')"') 116 | 117 | path_output = os.getcwd() + '/' + sys.argv[1] 118 | path_output = path_output.replace(" ", "%20") 119 | 120 | vimnm = sys.argv[2] 121 | if vimnm.find("GVIM") == 0: 122 | vimexec = "gvim" 123 | else: 124 | vimexec = "vim" 125 | time.sleep(1) 126 | os.system(vimexec + ' --servername ' + vimnm + ' --remote-expr "SyncTeX_SetPID(' + str(os.getpid()) + ')"') 127 | 128 | 129 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 130 | 131 | a = EvinceWindowProxy('file://' + path_output, True) 132 | 133 | loop = GObject.MainLoop() 134 | loop.run() 135 | 136 | -------------------------------------------------------------------------------- /r-plugin/synctex_evince_forward.py: -------------------------------------------------------------------------------- 1 | 2 | # The code in this files is borrowed from Gedit Synctex plugin. 3 | # 4 | # Copyright (C) 2010 Jose Aliste 5 | # 6 | # This program is free software; you can redistribute it and/or modify it under 7 | # the terms of the GNU General Public Licence as published by the Free Software 8 | # Foundation; either version 2 of the Licence, or (at your option) any later 9 | # version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but WITHOUT 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more 14 | # details. 15 | # 16 | # You should have received a copy of the GNU General Public Licence along with 17 | # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | 20 | # Modified to Vim-R-plugin by Jakson Aquino 21 | 22 | import dbus, subprocess, time 23 | import dbus.mainloop.glib, sys, os 24 | from gi.repository import GObject 25 | 26 | RUNNING, CLOSED = range(2) 27 | 28 | EV_DAEMON_PATH = "/org/gnome/evince/Daemon" 29 | EV_DAEMON_NAME = "org.gnome.evince.Daemon" 30 | EV_DAEMON_IFACE = "org.gnome.evince.Daemon" 31 | 32 | EVINCE_PATH = "/org/gnome/evince/Evince" 33 | EVINCE_IFACE = "org.gnome.evince.Application" 34 | 35 | EV_WINDOW_IFACE = "org.gnome.evince.Window" 36 | 37 | 38 | 39 | class EvinceWindowProxy: 40 | """A DBUS proxy for an Evince Window.""" 41 | daemon = None 42 | bus = None 43 | 44 | def __init__(self, uri, spawn = False): 45 | self.uri = uri 46 | self.spawn = spawn 47 | self.status = CLOSED 48 | self.source_handler = None 49 | self.dbus_name = '' 50 | self._handler = None 51 | try: 52 | if EvinceWindowProxy.bus is None: 53 | EvinceWindowProxy.bus = dbus.SessionBus() 54 | 55 | if EvinceWindowProxy.daemon is None: 56 | EvinceWindowProxy.daemon = EvinceWindowProxy.bus.get_object(EV_DAEMON_NAME, 57 | EV_DAEMON_PATH, 58 | follow_name_owner_changes=True) 59 | EvinceWindowProxy.bus.add_signal_receiver(self._on_doc_loaded, signal_name="DocumentLoaded", 60 | dbus_interface = EV_WINDOW_IFACE, 61 | sender_keyword='sender') 62 | self._get_dbus_name(False) 63 | 64 | except dbus.DBusException: 65 | sys.stderr.write("Could not connect to the Evince Daemon") 66 | sys.stderr.flush() 67 | 68 | def _on_doc_loaded(self, uri, **keyargs): 69 | if uri == self.uri and self._handler is None: 70 | self.handle_find_document_reply(keyargs['sender']) 71 | 72 | def _get_dbus_name(self, spawn): 73 | EvinceWindowProxy.daemon.FindDocument(self.uri,spawn, 74 | reply_handler=self.handle_find_document_reply, 75 | error_handler=self.handle_find_document_error, 76 | dbus_interface = EV_DAEMON_IFACE) 77 | 78 | def handle_find_document_error(self, error): 79 | sys.stderr.write("FindDocument DBus call has failed") 80 | sys.stderr.flush() 81 | 82 | def handle_find_document_reply(self, evince_name): 83 | if self._handler is not None: 84 | handler = self._handler 85 | else: 86 | handler = self.handle_get_window_list_reply 87 | if evince_name != '': 88 | self.dbus_name = evince_name 89 | self.status = RUNNING 90 | self.evince = EvinceWindowProxy.bus.get_object(self.dbus_name, EVINCE_PATH) 91 | self.evince.GetWindowList(dbus_interface = EVINCE_IFACE, 92 | reply_handler = handler, 93 | error_handler = self.handle_get_window_list_error) 94 | 95 | def handle_get_window_list_error (self, e): 96 | sys.stderr.write("GetWindowList DBus call has failed") 97 | sys.stderr.flush() 98 | 99 | def handle_get_window_list_reply (self, window_list): 100 | if len(window_list) > 0: 101 | window_obj = EvinceWindowProxy.bus.get_object(self.dbus_name, window_list[0]) 102 | self.window = dbus.Interface(window_obj,EV_WINDOW_IFACE) 103 | else: 104 | #That should never happen. 105 | sys.stderr.write("GetWindowList returned empty list") 106 | sys.stderr.flush() 107 | 108 | 109 | def SyncView(self, input_file, data, time): 110 | if self.status == CLOSED: 111 | if self.spawn: 112 | self._tmp_syncview = [input_file, data, time]; 113 | self._handler = self._syncview_handler 114 | self._get_dbus_name(True) 115 | else: 116 | self.window.SyncView(input_file, data, time, dbus_interface = "org.gnome.evince.Window") 117 | 118 | def _syncview_handler(self, window_list): 119 | self.handle_get_window_list_reply(window_list) 120 | 121 | if self.status == CLOSED: 122 | return False 123 | self.window.SyncView(self._tmp_syncview[0],self._tmp_syncview[1], self._tmp_syncview[2], dbus_interface="org.gnome.evince.Window") 124 | del self._tmp_syncview 125 | self._handler = None 126 | return True 127 | 128 | path_output = os.getcwd() + '/' + sys.argv[1] 129 | path_output = path_output.replace(" ", "%20") 130 | line_number = int(sys.argv[2]) 131 | path_input = os.getcwd() + '/' + sys.argv[3] 132 | 133 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 134 | 135 | a = EvinceWindowProxy('file://' + path_output, True) 136 | 137 | def sync_view(ev_window, path_input, line_number): 138 | ev_window.SyncView(path_input, (line_number, 1), 0) 139 | loop.quit() 140 | 141 | GObject.timeout_add(400, sync_view, a, path_input, line_number) 142 | loop = GObject.MainLoop() 143 | loop.run() 144 | 145 | -------------------------------------------------------------------------------- /r-plugin/windows.vim: -------------------------------------------------------------------------------- 1 | " This file contains code used only on Windows 2 | 3 | let g:rplugin_sumatra_path = "" 4 | let g:rplugin_python_initialized = 0 5 | 6 | call RSetDefaultValue("g:vimrplugin_sleeptime", 100) 7 | 8 | " Avoid invalid values defined by the user 9 | exe "let s:sleeptimestr = " . '"' . g:vimrplugin_sleeptime . '"' 10 | let s:sleeptime = str2nr(s:sleeptimestr) 11 | if s:sleeptime < 1 || s:sleeptime > 1000 12 | let g:vimrplugin_sleeptime = 100 13 | endif 14 | unlet s:sleeptimestr 15 | unlet s:sleeptime 16 | 17 | let g:rplugin_sleeptime = g:vimrplugin_sleeptime . 'm' 18 | 19 | if !exists("g:rplugin_rpathadded") 20 | if exists("g:vimrplugin_r_path") 21 | if !isdirectory(g:vimrplugin_r_path) 22 | call RWarningMsgInp("vimrplugin_r_path must be a directory (check your vimrc)") 23 | let g:rplugin_failed = 1 24 | finish 25 | endif 26 | if !filereadable(g:vimrplugin_r_path . "\\Rgui.exe") 27 | call RWarningMsgInp('File "' . g:vimrplugin_r_path . '\Rgui.exe" is unreadable (check vimrplugin_r_path in your vimrc).') 28 | let g:rplugin_failed = 1 29 | finish 30 | endif 31 | let $PATH = g:vimrplugin_r_path . ";" . $PATH 32 | let g:rplugin_Rgui = g:vimrplugin_r_path . "\\Rgui.exe" 33 | else 34 | let rip = filter(split(system('reg.exe QUERY "HKLM\SOFTWARE\R-core\R" /s'), "\n"), 'v:val =~ ".*InstallPath.*REG_SZ"') 35 | let g:rdebug_reg_rpath_1 = rip 36 | if len(rip) > 0 37 | let s:rinstallpath = substitute(rip[0], '.*InstallPath.*REG_SZ\s*', '', '') 38 | let s:rinstallpath = substitute(s:rinstallpath, '\n', '', 'g') 39 | let s:rinstallpath = substitute(s:rinstallpath, '\s*$', '', 'g') 40 | let g:rdebug_reg_rpath_2 = s:rinstallpath 41 | endif 42 | 43 | if !exists("s:rinstallpath") 44 | call RWarningMsgInp("Could not find R path in Windows Registry. If you have already installed R, please, set the value of 'vimrplugin_r_path'.") 45 | let g:rplugin_failed = 1 46 | finish 47 | endif 48 | if isdirectory(s:rinstallpath . '\bin\i386') 49 | if !isdirectory(s:rinstallpath . '\bin\x64') 50 | let g:vimrplugin_i386 = 1 51 | endif 52 | if g:vimrplugin_i386 53 | let $PATH = s:rinstallpath . '\bin\i386;' . $PATH 54 | let g:rplugin_Rgui = s:rinstallpath . '\bin\i386\Rgui.exe' 55 | else 56 | let $PATH = s:rinstallpath . '\bin\x64;' . $PATH 57 | let g:rplugin_Rgui = s:rinstallpath . '\bin\x64\Rgui.exe' 58 | endif 59 | else 60 | let $PATH = s:rinstallpath . '\bin;' . $PATH 61 | let g:rplugin_Rgui = s:rinstallpath . '\bin\Rgui.exe' 62 | endif 63 | unlet s:rinstallpath 64 | endif 65 | let g:rplugin_rpathadded = 1 66 | endif 67 | let g:vimrplugin_term_cmd = "none" 68 | let g:vimrplugin_term = "none" 69 | if !exists("g:vimrplugin_r_args") 70 | let g:vimrplugin_r_args = "--sdi" 71 | endif 72 | if g:vimrplugin_Rterm 73 | let g:rplugin_Rgui = substitute(g:rplugin_Rgui, "Rgui", "Rterm", "") 74 | endif 75 | 76 | if !exists("g:vimrplugin_R_window_title") 77 | if g:vimrplugin_Rterm 78 | let g:vimrplugin_R_window_title = "Rterm" 79 | else 80 | let g:vimrplugin_R_window_title = "R Console" 81 | endif 82 | endif 83 | 84 | function FindSumatra() 85 | if executable($ProgramFiles . "\\SumatraPDF\\SumatraPDF.exe") 86 | let g:rplugin_sumatra_path = $ProgramFiles . "\\SumatraPDF\\SumatraPDF.exe" 87 | return 1 88 | endif 89 | let smtr = system('reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths" /v "SumatraPDF.exe"') 90 | if len(smtr) > 0 91 | let g:rdebug_reg_personal = smtr 92 | let smtr = substitute(smtr, '.*REG_SZ\s*', '', '') 93 | let smtr = substitute(smtr, '\n', '', 'g') 94 | let smtr = substitute(smtr, '\s*$', '', 'g') 95 | if executable(smtr) 96 | let g:rplugin_sumatra_path = smtr 97 | return 1 98 | else 99 | call RWarningMsg('Sumatra not found: "' . smtr . '"') 100 | endif 101 | else 102 | call RWarningMsg("SumatraPDF not found in Windows registry.") 103 | endif 104 | return 0 105 | endfunction 106 | 107 | function StartR_Windows() 108 | if string(g:SendCmdToR) != "function('SendCmdToR_fake')" 109 | let repl = libcall(g:rplugin_vimcom_lib, "IsRRunning", 'No argument') 110 | if repl =~ "^Yes" 111 | call RWarningMsg('R is already running.') 112 | return 113 | else 114 | let g:SendCmdToR = function('SendCmdToR_fake') 115 | let g:rplugin_r_pid = 0 116 | endif 117 | endif 118 | 119 | if !executable(g:rplugin_Rgui) 120 | call RWarningMsg('R executable "' . g:rplugin_Rgui . '" not found.') 121 | if exists("g:rdebug_reg_rpath_1") 122 | call RWarningMsg('DEBUG message 1: >>' . g:rdebug_reg_rpath_1 . '<<') 123 | endif 124 | if exists("g:rdebug_reg_rpath_1") 125 | call RWarningMsg('DEBUG message 2: >>' . g:rdebug_reg_rpath_2 . '<<') 126 | endif 127 | return 128 | endif 129 | 130 | " R and Vim use different values for the $HOME variable. 131 | let saved_home = $HOME 132 | let prs = system('reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal"') 133 | if len(prs) > 0 134 | let g:rdebug_reg_personal = prs 135 | let prs = substitute(prs, '.*REG_SZ\s*', '', '') 136 | let prs = substitute(prs, '\n', '', 'g') 137 | let prs = substitute(prs, '\s*$', '', 'g') 138 | let $HOME = prs 139 | endif 140 | 141 | let rcmd = g:rplugin_Rgui 142 | if g:vimrplugin_Rterm 143 | let rcmd = substitute(rcmd, "Rgui", "Rterm", "") 144 | endif 145 | let rcmd = '"' . rcmd . '" ' . g:vimrplugin_r_args 146 | 147 | silent exe "!start " . rcmd 148 | 149 | let $HOME = saved_home 150 | 151 | let g:SendCmdToR = function('SendCmdToR_Windows') 152 | if WaitVimComStart() 153 | call foreground() 154 | if g:vimrplugin_arrange_windows && v:servername != "" && filereadable(g:rplugin_compldir . "/win_pos") 155 | let repl = libcall(g:rplugin_vimcom_lib, "ArrangeWindows", $VIMRPLUGIN_COMPLDIR) 156 | if repl != "OK" 157 | call RWarningMsg(repl) 158 | endif 159 | endif 160 | if g:vimrplugin_after_start != '' 161 | call system(g:vimrplugin_after_start) 162 | endif 163 | endif 164 | endfunction 165 | 166 | function SendCmdToR_Windows(cmd) 167 | if g:vimrplugin_ca_ck 168 | let cmd = "\001" . "\013" . a:cmd . "\n" 169 | else 170 | let cmd = a:cmd . "\n" 171 | endif 172 | let save_clip = getreg('+') 173 | call setreg('+', cmd) 174 | if g:vimrplugin_Rterm 175 | let repl = libcall(g:rplugin_vimcom_lib, "SendToRTerm", cmd) 176 | else 177 | let repl = libcall(g:rplugin_vimcom_lib, "SendToRConsole", cmd) 178 | endif 179 | if repl != "OK" 180 | call RWarningMsg(repl) 181 | call ClearRInfo() 182 | endif 183 | exe "sleep " . g:rplugin_sleeptime 184 | call foreground() 185 | call setreg('+', save_clip) 186 | return 1 187 | endfunction 188 | 189 | -------------------------------------------------------------------------------- /syntax/rbrowser.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Object browser of R Workspace 3 | " Maintainer: Jakson Alves de Aquino (jalvesaq@gmail.com) 4 | 5 | if exists("b:current_syntax") 6 | finish 7 | endif 8 | scriptencoding utf-8 9 | 10 | setlocal iskeyword=@,48-57,_,. 11 | 12 | if has("conceal") 13 | setlocal conceallevel=2 14 | setlocal concealcursor=nvc 15 | syn match rbrowserNumeric "{#.*\t" contains=rbrowserDelim,rbrowserTab 16 | syn match rbrowserCharacter /"#.*\t/ contains=rbrowserDelim,rbrowserTab 17 | syn match rbrowserFactor "'#.*\t" contains=rbrowserDelim,rbrowserTab 18 | syn match rbrowserFunction "(#.*\t" contains=rbrowserDelim,rbrowserTab 19 | syn match rbrowserList "\[#.*\t" contains=rbrowserDelim,rbrowserTab 20 | syn match rbrowserLogical "%#.*\t" contains=rbrowserDelim,rbrowserTab 21 | syn match rbrowserLibrary "##.*\t" contains=rbrowserDelim,rbrowserTab 22 | syn match rbrowserS4 "<#.*\t" contains=rbrowserDelim,rbrowserTab 23 | syn match rbrowserLazy "&#.*\t" contains=rbrowserDelim,rbrowserTab 24 | syn match rbrowserUnknown "=#.*\t" contains=rbrowserDelim,rbrowserTab 25 | else 26 | syn match rbrowserNumeric "{.*\t" contains=rbrowserDelim,rbrowserTab 27 | syn match rbrowserCharacter /".*\t/ contains=rbrowserDelim,rbrowserTab 28 | syn match rbrowserFactor "'.*\t" contains=rbrowserDelim,rbrowserTab 29 | syn match rbrowserFunction "(.*\t" contains=rbrowserDelim,rbrowserTab 30 | syn match rbrowserList "\[.*\t" contains=rbrowserDelim,rbrowserTab 31 | syn match rbrowserLogical "%.*\t" contains=rbrowserDelim,rbrowserTab 32 | syn match rbrowserLibrary "#.*\t" contains=rbrowserDelim,rbrowserTab 33 | syn match rbrowserS4 "<.*\t" contains=rbrowserDelim,rbrowserTab 34 | syn match rbrowserLazy "&.*\t" contains=rbrowserDelim,rbrowserTab 35 | syn match rbrowserUnknown "=.*\t" contains=rbrowserDelim,rbrowserTab 36 | endif 37 | syn match rbrowserEnv "^.GlobalEnv " 38 | syn match rbrowserEnv "^Libraries " 39 | syn match rbrowserLink " Libraries$" 40 | syn match rbrowserLink " .GlobalEnv$" 41 | syn match rbrowserTreePart "├─" 42 | syn match rbrowserTreePart "└─" 43 | syn match rbrowserTreePart "│" 44 | if &encoding != "utf-8" 45 | syn match rbrowserTreePart "|" 46 | syn match rbrowserTreePart "`-" 47 | syn match rbrowserTreePart "|-" 48 | endif 49 | 50 | syn match rbrowserTab contained "\t" 51 | syn match rbrowserErr /Error: label isn't "character"./ 52 | if has("conceal") 53 | syn match rbrowserDelim contained /'#\|"#\|(#\|\[#\|{#\|%#\|##\|<#\|&#\|=#/ conceal 54 | else 55 | syn match rbrowserDelim contained /'\|"\|(\|\[\|{\|%\|#\|<\|&\|=/ 56 | endif 57 | 58 | hi def link rbrowserEnv Statement 59 | hi def link rbrowserNumeric Number 60 | hi def link rbrowserCharacter String 61 | hi def link rbrowserFactor Special 62 | hi def link rbrowserList Type 63 | hi def link rbrowserLibrary PreProc 64 | hi def link rbrowserLink Comment 65 | hi def link rbrowserLogical Boolean 66 | hi def link rbrowserFunction Function 67 | hi def link rbrowserS4 Statement 68 | hi def link rbrowserLazy Comment 69 | hi def link rbrowserUnknown Normal 70 | hi def link rbrowserWarn WarningMsg 71 | hi def link rbrowserErr ErrorMsg 72 | hi def link rbrowserTreePart Comment 73 | hi def link rbrowserDelim Ignore 74 | hi def link rbrowserTab Ignore 75 | 76 | " vim: ts=8 sw=4 77 | -------------------------------------------------------------------------------- /syntax/rdoc.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: R documentation 3 | " Maintainer: Jakson A. Aquino 4 | 5 | if exists("b:current_syntax") 6 | finish 7 | endif 8 | 9 | setlocal iskeyword=@,48-57,_,. 10 | 11 | if !exists("rdoc_minlines") 12 | let rdoc_minlines = 200 13 | endif 14 | if !exists("rdoc_maxlines") 15 | let rdoc_maxlines = 2 * rdoc_minlines 16 | endif 17 | exec "syn sync minlines=" . rdoc_minlines . " maxlines=" . rdoc_maxlines 18 | 19 | 20 | syn match rdocTitle "^[A-Z].*:$" 21 | syn match rdocTitle "^\S.*R Documentation$" 22 | syn match rdocFunction "\([A-Z]\|[a-z]\|\.\|_\)\([A-Z]\|[a-z]\|[0-9]\|\.\|_\)*" contained 23 | syn region rdocStringS start="\%u2018" end="\%u2019" contains=rdocFunction transparent keepend 24 | syn region rdocStringS start="\%x91" end="\%x92" contains=rdocFunction transparent keepend 25 | syn region rdocStringD start='"' skip='\\"' end='"' 26 | syn match rdocURL `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-zA-Z0-9/]` 27 | syn keyword rdocNote note Note NOTE note: Note: NOTE: Notes Notes: 28 | 29 | " When using vim as R pager to see the output of help.search(): 30 | syn region rdocPackage start="^[A-Za-z]\S*::" end="[\s\r]" contains=rdocPackName,rdocFuncName transparent 31 | syn match rdocPackName "^[A-Za-z][A-Za-z0-9\.]*" contained 32 | syn match rdocFuncName "::[A-Za-z0-9\.\-_]*" contained 33 | 34 | syn region rdocArgReg matchgroup=rdocArgTitle start="^Arguments:" matchgroup=NONE end="^\t" contains=rdocArgItems,rdocArgTitle,rdocPackage,rdocFuncName,rdocStringS keepend transparent 35 | syn match rdocArgItems "\n\n\s*\([A-Z]\|[a-z]\|[0-9]\|\.\|_\)*:" contains=rdocArg contained transparent 36 | syn match rdocArg "\([A-Z]\|[a-z]\|[0-9]\|\.\|_\)*" contained 37 | 38 | syn include @rdocR syntax/r.vim 39 | syn region rdocExample matchgroup=rdocExTitle start="^Examples:$" matchgroup=rdocExEnd end='^###$' contains=@rdocR keepend 40 | syn region rdocUsage matchgroup=rdocTitle start="^Usage:$" matchgroup=NONE end='^\t' contains=@rdocR 41 | 42 | syn sync match rdocSyncExample grouphere rdocExample "^Examples:$" 43 | syn sync match rdocSyncUsage grouphere rdocUsage "^Usage:$" 44 | syn sync match rdocSyncArg grouphere rdocArgReg "^Arguments:" 45 | syn sync match rdocSyncNONE grouphere NONE "^\t$" 46 | 47 | 48 | " Define the default highlighting. 49 | "hi def link rdocArgReg Statement 50 | hi def link rdocTitle Title 51 | hi def link rdocArgTitle Title 52 | hi def link rdocExTitle Title 53 | hi def link rdocExEnd Comment 54 | hi def link rdocFunction Function 55 | hi def link rdocStringD String 56 | hi def link rdocURL HtmlLink 57 | hi def link rdocArg Special 58 | hi def link rdocNote Todo 59 | 60 | hi def link rdocPackName Title 61 | hi def link rdocFuncName Function 62 | 63 | let b:current_syntax = "rdoc" 64 | 65 | " vim: ts=8 sw=4 66 | -------------------------------------------------------------------------------- /syntax/rout.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: R output Files 3 | " Maintainer: Jakson Aquino 4 | 5 | 6 | if exists("b:current_syntax") 7 | finish 8 | endif 9 | 10 | setlocal iskeyword=@,48-57,_,. 11 | 12 | syn case match 13 | 14 | " Normal text 15 | syn match routNormal "." 16 | 17 | " Strings 18 | syn region routString start=/"/ skip=/\\\\\|\\"/ end=/"/ end=/$/ 19 | 20 | " Constants 21 | syn keyword routConst NULL NA NaN 22 | syn keyword routTrue TRUE 23 | syn keyword routFalse FALSE 24 | syn match routConst "\" 25 | syn match routInf "-Inf\>" 26 | syn match routInf "\" 27 | 28 | " integer 29 | syn match routInteger "\<\d\+L" 30 | syn match routInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L" 31 | syn match routInteger "\<\d\+[Ee]+\=\d\+L" 32 | 33 | " number with no fractional part or exponent 34 | syn match routNumber "\<\d\+\>" 35 | syn match routNegNum "-\<\d\+\>" 36 | " hexadecimal number 37 | syn match routNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+" 38 | 39 | " floating point number with integer and fractional parts and optional exponent 40 | syn match routFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=" 41 | syn match routNegFlt "-\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=" 42 | " floating point number with no integer part and optional exponent 43 | syn match routFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\=" 44 | syn match routNegFlt "-\<\.\d\+\([Ee][-+]\=\d\+\)\=" 45 | " floating point number with no fractional part and optional exponent 46 | syn match routFloat "\<\d\+[Ee][-+]\=\d\+" 47 | syn match routNegFlt "-\<\d\+[Ee][-+]\=\d\+" 48 | 49 | " complex number 50 | syn match routComplex "\<\d\+i" 51 | syn match routComplex "\<\d\++\d\+i" 52 | syn match routComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i" 53 | syn match routComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i" 54 | syn match routComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i" 55 | syn match routComplex "\<\d\+[Ee][-+]\=\d\+i" 56 | 57 | " dates and times 58 | syn match routDate "[0-9][0-9][0-9][0-9][-/][0-9][0-9][-/][0-9][-0-9]" 59 | syn match routDate "[0-9][0-9][-/][0-9][0-9][-/][0-9][0-9][0-9][-0-9]" 60 | syn match routDate "[0-9][0-9]:[0-9][0-9]:[0-9][-0-9]" 61 | 62 | if !exists("g:Rout_more_colors") 63 | let g:Rout_more_colors = 0 64 | endif 65 | 66 | if g:Rout_more_colors 67 | syn include @routR syntax/r.vim 68 | syn region routColoredR start="^>" end='$' contains=@routR keepend 69 | syn region routColoredR start="^+" end='$' contains=@routR keepend 70 | else 71 | " Input 72 | syn match routInput /^>.*/ 73 | syn match routInput /^+.*/ 74 | endif 75 | 76 | " Index of vectors 77 | syn match routIndex /^\s*\[\d\+\]/ 78 | 79 | " Errors and warnings 80 | syn match routError "^Error.*" 81 | syn match routWarn "^Warning.*" 82 | 83 | if v:lang =~ "^da" 84 | syn match routError "^Fejl.*" 85 | syn match routWarn "^Advarsel.*" 86 | endif 87 | 88 | if v:lang =~ "^de" 89 | syn match routError "^Fehler.*" 90 | syn match routWarn "^Warnung.*" 91 | endif 92 | 93 | if v:lang =~ "^es" 94 | syn match routWarn "^Aviso.*" 95 | endif 96 | 97 | if v:lang =~ "^fr" 98 | syn match routError "^Erreur.*" 99 | syn match routWarn "^Avis.*" 100 | endif 101 | 102 | if v:lang =~ "^it" 103 | syn match routError "^Errore.*" 104 | syn match routWarn "^Avviso.*" 105 | endif 106 | 107 | if v:lang =~ "^nn" 108 | syn match routError "^Feil.*" 109 | syn match routWarn "^Åtvaring.*" 110 | endif 111 | 112 | if v:lang =~ "^pl" 113 | syn match routError "^BŁĄD.*" 114 | syn match routError "^Błąd.*" 115 | syn match routWarn "^Ostrzeżenie.*" 116 | endif 117 | 118 | if v:lang =~ "^pt_BR" 119 | syn match routError "^Erro.*" 120 | syn match routWarn "^Aviso.*" 121 | endif 122 | 123 | if v:lang =~ "^ru" 124 | syn match routError "^Ошибка.*" 125 | syn match routWarn "^Предупреждение.*" 126 | endif 127 | 128 | if v:lang =~ "^tr" 129 | syn match routError "^Hata.*" 130 | syn match routWarn "^Uyarı.*" 131 | endif 132 | 133 | " Define the default highlighting. 134 | if g:Rout_more_colors == 0 135 | hi def link routInput Comment 136 | endif 137 | 138 | if exists("g:rout_follow_colorscheme") && g:rout_follow_colorscheme 139 | " Default when following :colorscheme 140 | hi def link routNormal Normal 141 | hi def link routNumber Number 142 | hi def link routInteger Number 143 | hi def link routFloat Float 144 | hi def link routComplex Number 145 | hi def link routNegNum Number 146 | hi def link routNegFlt Float 147 | hi def link routDate Number 148 | hi def link routTrue Boolean 149 | hi def link routFalse Boolean 150 | hi def link routInf Number 151 | hi def link routConst Constant 152 | hi def link routString String 153 | hi def link routIndex Special 154 | hi def link routError ErrorMsg 155 | hi def link routWarn WarningMsg 156 | else 157 | if has("gui_running") 158 | " Default 256 colors scheme for R output: 159 | hi routInput guifg=#9e9e9e 160 | hi routNormal guifg=#00d700 161 | hi routNumber guifg=#ffaf00 162 | hi routInteger guifg=#ffaf00 163 | hi routFloat guifg=#ffaf00 164 | hi routComplex guifg=#ffaf00 165 | hi routNegNum guifg=#ff875f 166 | hi routNegFlt guifg=#ff875f 167 | hi routDate guifg=#d7af5f 168 | hi routFalse guifg=#ff5f5f 169 | hi routTrue guifg=#5fd787 170 | hi routInf guifg=#00afff 171 | hi routConst guifg=#00af5f 172 | hi routString guifg=#5fffaf 173 | hi routError guifg=#ffffff guibg=#c00000 174 | hi routWarn guifg=#c00000 175 | hi routIndex guifg=#87afaf 176 | elseif &t_Co == 256 177 | " Default 256 colors scheme for R output: 178 | hi routInput ctermfg=247 179 | hi routNormal ctermfg=40 180 | hi routNumber ctermfg=214 181 | hi routInteger ctermfg=214 182 | hi routFloat ctermfg=214 183 | hi routComplex ctermfg=214 184 | hi routNegNum ctermfg=209 185 | hi routNegFlt ctermfg=209 186 | hi routDate ctermfg=179 187 | hi routFalse ctermfg=203 188 | hi routTrue ctermfg=78 189 | hi routInf ctermfg=39 190 | hi routConst ctermfg=35 191 | hi routString ctermfg=85 192 | hi routError ctermfg=15 ctermbg=1 193 | hi routWarn ctermfg=1 194 | hi routIndex ctermfg=109 195 | else 196 | " Default 16 colors scheme for R output: 197 | hi routInput ctermfg=gray 198 | hi routNormal ctermfg=darkgreen 199 | hi routNumber ctermfg=darkyellow 200 | hi routInteger ctermfg=darkyellow 201 | hi routFloat ctermfg=darkyellow 202 | hi routComplex ctermfg=darkyellow 203 | hi routNegNum ctermfg=darkyellow 204 | hi routNegFlt ctermfg=darkyellow 205 | hi routDate ctermfg=darkyellow 206 | hi routInf ctermfg=darkyellow 207 | hi routFalse ctermfg=magenta 208 | hi routTrue ctermfg=darkgreen 209 | hi routConst ctermfg=magenta 210 | hi routString ctermfg=darkcyan 211 | hi routError ctermfg=white ctermbg=red 212 | hi routWarn ctermfg=red 213 | hi routIndex ctermfg=darkgreen 214 | endif 215 | 216 | " Change colors under user request: 217 | if exists("g:rout_color_input") 218 | exe "hi routInput " . g:rout_color_input 219 | endif 220 | if exists("g:rout_color_normal") 221 | exe "hi routNormal " . g:rout_color_normal 222 | endif 223 | if exists("g:rout_color_number") 224 | exe "hi routNumber " . g:rout_color_number 225 | endif 226 | if exists("g:rout_color_integer") 227 | exe "hi routInteger " . g:rout_color_integer 228 | endif 229 | if exists("g:rout_color_float") 230 | exe "hi routFloat " . g:rout_color_float 231 | endif 232 | if exists("g:rout_color_complex") 233 | exe "hi routComplex " . g:rout_color_complex 234 | endif 235 | if exists("g:rout_color_negnum") 236 | exe "hi routNegNum " . g:rout_color_negnum 237 | endif 238 | if exists("g:rout_color_negfloat") 239 | exe "hi routNegFlt " . g:rout_color_negfloat 240 | endif 241 | if exists("g:rout_color_date") 242 | exe "hi routDate " . g:rout_color_date 243 | endif 244 | if exists("g:rout_color_false") 245 | exe "hi routFalse " . g:rout_color_false 246 | endif 247 | if exists("g:rout_color_true") 248 | exe "hi routTrue " . g:rout_color_true 249 | endif 250 | if exists("g:rout_color_inf") 251 | exe "hi routInf " . g:rout_color_inf 252 | endif 253 | if exists("g:rout_color_constant") 254 | exe "hi routConst " . g:rout_color_constant 255 | endif 256 | if exists("g:rout_color_string") 257 | exe "hi routString " . g:rout_color_string 258 | endif 259 | if exists("g:rout_color_error") 260 | exe "hi routError " . g:rout_color_error 261 | endif 262 | if exists("g:rout_color_warn") 263 | exe "hi routWarn " . g:rout_color_warn 264 | endif 265 | if exists("g:rout_color_index") 266 | exe "hi routIndex " . g:rout_color_index 267 | endif 268 | endif 269 | 270 | let b:current_syntax = "rout" 271 | 272 | " vim: ts=8 sw=4 273 | --------------------------------------------------------------------------------