forked from jalvesaq/Nvim-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows.vim
125 lines (112 loc) · 3.9 KB
/
windows.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
" This file contains code used only on Windows
let g:rplugin_sumatra_in_path = 0
call RSetDefaultValue("g:R_set_home_env", 1)
call RSetDefaultValue("g:R_i386", 0)
if !exists("g:rplugin_R_path")
call writefile(['reg.exe QUERY "HKLM\SOFTWARE\R-core\R" /s'], g:rplugin_tmpdir . "/run_cmd.bat")
let rip = filter(split(system(g:rplugin_tmpdir . "/run_cmd.bat"), "\n"), 'v:val =~ ".*InstallPath.*REG_SZ"')
if len(rip) > 0
let s:rinstallpath = substitute(rip[0], '.*InstallPath.*REG_SZ\s*', '', '')
let s:rinstallpath = substitute(s:rinstallpath, '\n', '', 'g')
let s:rinstallpath = substitute(s:rinstallpath, '\s*$', '', 'g')
endif
if !exists("s:rinstallpath")
call RWarningMsgInp("Could not find R path in Windows Registry. If you have already installed R, please, set the value of 'R_path'.")
let g:rplugin_failed = 1
finish
endif
if isdirectory(s:rinstallpath . '\bin\i386')
if !isdirectory(s:rinstallpath . '\bin\x64')
let g:R_i386 = 1
endif
if g:R_i386
let $PATH = s:rinstallpath . '\bin\i386;' . $PATH
else
let $PATH = s:rinstallpath . '\bin\x64;' . $PATH
endif
else
let $PATH = s:rinstallpath . '\bin;' . $PATH
endif
unlet s:rinstallpath
endif
if !exists("g:R_args")
if g:R_in_buffer
let g:R_args = ["--no-save"]
else
let g:R_args = ["--sdi", "--no-save"]
endif
endif
let g:R_R_window_title = "R Console"
function SumatraInPath()
if g:rplugin_sumatra_in_path
return 1
endif
if $PATH =~ "SumatraPDF"
let g:rplugin_sumatra_in_path = 1
return 1
endif
" $ProgramFiles has different values for win32 and win64
if executable($ProgramFiles . "\\SumatraPDF\\SumatraPDF.exe")
let $PATH = $ProgramFiles . "\\SumatraPDF;" . $PATH
let g:rplugin_sumatra_in_path = 1
return 1
endif
if executable($ProgramFiles . " (x86)\\SumatraPDF\\SumatraPDF.exe")
let $PATH = $ProgramFiles . " (x86)\\SumatraPDF;" . $PATH
let g:rplugin_sumatra_in_path = 1
return 1
endif
return 0
endfunction
function SetRHome()
" R and Vim use different values for the $HOME variable.
if g:R_set_home_env
let s:saved_home = $HOME
call writefile(['reg.exe QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal"'], g:rplugin_tmpdir . "/run_cmd.bat")
let prs = system(g:rplugin_tmpdir . "/run_cmd.bat")
if len(prs) > 0
let prs = substitute(prs, '.*REG_SZ\s*', '', '')
let prs = substitute(prs, '\n', '', 'g')
let prs = substitute(prs, '\r', '', 'g')
let prs = substitute(prs, '\s*$', '', 'g')
let $HOME = prs
endif
endif
endfunction
function UnsetRHome()
if exists("s:saved_home")
let $HOME = s:saved_home
unlet s:saved_home
endif
endfunction
function StartR_Windows()
if string(g:SendCmdToR) != "function('SendCmdToR_fake')"
call RWarningMsg('R was already started.')
endif
call SetRHome()
if has("nvim")
call system("start " . g:rplugin_R . ' ' . join(g:R_args))
else
silent exe "!start " . g:rplugin_R . ' ' . join(g:R_args)
endif
call UnsetRHome()
let g:SendCmdToR = function('SendCmdToR_Windows')
if WaitNvimcomStart()
if g:R_arrange_windows && filereadable(g:rplugin_compldir . "/win_pos")
" ArrangeWindows
call JobStdin(g:rplugin_jobs["ClientServer"], "\005" . g:rplugin_compldir . "\n")
endif
if g:R_after_start != ''
call system(g:R_after_start)
endif
endif
endfunction
function SendCmdToR_Windows(...)
if g:R_ca_ck
let cmd = "\001" . "\013" . a:1 . "\n"
else
let cmd = a:1 . "\n"
endif
call JobStdin(g:rplugin_jobs["ClientServer"], "\003" . cmd)
return 1
endfunction