dot dot dotfiles
1if $TMUX == ''
2 finish
3endif
4
5if exists("*TmuxActivePane")
6 finish
7endif
8
9let g:R_external_term = 1
10let g:R_applescript = 0
11let g:rplugin.tmux_split = 1
12let g:R_tmux_title = get(g:, 'R_tmux_title', 'NvimR')
13
14" Adapted from screen plugin:
15function TmuxActivePane()
16 let line = system("tmux list-panes | grep \'(active)$'")
17 let paneid = matchstr(line, '\v\%\d+ \(active\)')
18 if !empty(paneid)
19 return matchstr(paneid, '\v^\%\d+')
20 else
21 return matchstr(line, '\v^\d+')
22 endif
23endfunction
24
25" Replace StartR_ExternalTerm with a function that starts R in a Tmux split pane
26function! StartR_ExternalTerm(rcmd)
27 let g:rplugin.editor_pane = $TMUX_PANE
28 let tmuxconf = ['set-environment NVIMR_TMPDIR "' . g:rplugin.tmpdir . '"',
29 \ 'set-environment NVIMR_COMPLDIR "' . substitute(g:rplugin.compldir, ' ', '\\ ', "g") . '"',
30 \ 'set-environment NVIMR_ID ' . $NVIMR_ID ,
31 \ 'set-environment NVIMR_SECRET ' . $NVIMR_SECRET ,
32 \ 'set-environment NVIMR_PORT ' . $NVIMR_PORT ,
33 \ 'set-environment R_DEFAULT_PACKAGES ' . $R_DEFAULT_PACKAGES ]
34 if $NVIM_IP_ADDRESS != ""
35 call extend(tmuxconf, ['set-environment NVIM_IP_ADDRESS ' . $NVIM_IP_ADDRESS ])
36 endif
37 if $R_LIBS_USER != ""
38 call extend(tmuxconf, ['set-environment R_LIBS_USER ' . $R_LIBS_USER ])
39 endif
40 if &t_Co == 256
41 call extend(tmuxconf, ['set default-terminal "' . $TERM . '"'])
42 endif
43 call writefile(tmuxconf, g:rplugin.tmpdir . "/tmux" . $NVIMR_ID . ".conf")
44 call system("tmux source-file '" . g:rplugin.tmpdir . "/tmux" . $NVIMR_ID . ".conf" . "'")
45 call delete(g:rplugin.tmpdir . "/tmux" . $NVIMR_ID . ".conf")
46 let tcmd = "tmux split-window "
47 if g:R_rconsole_width > 0 && winwidth(0) > (g:R_rconsole_width + g:R_min_editor_width + 1 + (&number * &numberwidth))
48 if g:R_rconsole_width == -1
49 let tcmd .= "-h"
50 else
51 let tcmd .= "-h"
52 "let tcmd .= "-h -l " . g:R_rconsole_width
53 endif
54 else
55 "let tcmd .= "-l " . g:R_rconsole_height
56 let tcmd .= "-h"
57 endif
58
59 " Let Tmux automatically kill the panel when R quits.
60 let tcmd .= " '" . a:rcmd . "'"
61
62 let rlog = system(tcmd)
63 if v:shell_error
64 call RWarningMsg(rlog)
65 return
66 endif
67 let g:rplugin.rconsole_pane = TmuxActivePane()
68 let rlog = system("tmux select-pane -t " . g:rplugin.editor_pane)
69 if v:shell_error
70 call RWarningMsg(rlog)
71 return
72 endif
73 let g:SendCmdToR = function('SendCmdToR_TmuxSplit')
74 let g:rplugin.last_rcmd = a:rcmd
75 if g:R_tmux_title != "automatic" && g:R_tmux_title != ""
76 call system("tmux rename-window " . g:R_tmux_title)
77 endif
78 call WaitNvimcomStart()
79 " Environment variables persist across Tmux windows.
80 " Unset NVIMR_TMPDIR to avoid nvimcom loading its C library
81 " when R was not started by Neovim:
82 call system("tmux set-environment -u NVIMR_TMPDIR")
83 " Also unset R_DEFAULT_PACKAGES so that other R instances do not
84 " load nvimcom unnecessarily
85 call system("tmux set-environment -u R_DEFAULT_PACKAGES")
86endfunction
87
88function SendCmdToR_TmuxSplit(...)
89 if g:R_clear_line
90 if g:R_editing_mode == "emacs"
91 let cmd = "\001\013" . a:1
92 else
93 let cmd = "\x1b0Da" . a:1
94 endif
95 else
96 let cmd = a:1
97 endif
98
99 let str = substitute(cmd, "'", "'\\\\''", "g")
100 if str =~ '^-'
101 let str = ' ' . str
102 endif
103 if a:0 == 2 && a:2 == 0
104 let scmd = "tmux set-buffer '" . str . "' && tmux paste-buffer -t " . g:rplugin.rconsole_pane
105 else
106 let scmd = "tmux set-buffer '" . str . "\<C-M>' && tmux paste-buffer -t " . g:rplugin.rconsole_pane
107 endif
108 let rlog = system(scmd)
109 if v:shell_error
110 let rlog = substitute(rlog, "\n", " ", "g")
111 let rlog = substitute(rlog, "\r", " ", "g")
112 call RWarningMsg(rlog)
113 call ClearRInfo()
114 return 0
115 endif
116 return 1
117endfunction