Skip to content

Commit

Permalink
Version 090810
Browse files Browse the repository at this point in the history
 * Added R icons for some terminal emulators.
 * Removed the script open-gvim-here. You may use Vim's option autochdir.
 * Added option g:vimrplugin_term.
 * Improved indentation script.
 * Changed key binding from <S-Enter>, which doesn't work in any terminal, to <M-Enter>, which at least works in xterm.
  • Loading branch information
jalvesaq authored and vim-scripts committed Nov 7, 2010
1 parent b1d6843 commit 1cabc86
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 73 deletions.
Binary file added bitmaps/ricon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions bitmaps/ricon.xbm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define ricon_width 24
#define ricon_height 24
static unsigned char ricon_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f, 0x00, 0xf8, 0xff, 0x01,
0xf8, 0xff, 0x03, 0xf8, 0xff, 0x07, 0xf8, 0xe0, 0x07, 0xf8, 0xc0, 0x07,
0xf8, 0xc0, 0x07, 0xf8, 0xc0, 0x07, 0xf8, 0xe0, 0x03, 0xf8, 0xff, 0x03,
0xf8, 0xff, 0x00, 0xf8, 0xff, 0x00, 0xf8, 0xff, 0x01, 0xf8, 0xf0, 0x03,
0xf8, 0xe0, 0x07, 0xf8, 0xe0, 0x07, 0xf8, 0xc0, 0x0f, 0xf8, 0x80, 0x0f,
0xf8, 0x80, 0x1f, 0xf8, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
} ;
100 changes: 59 additions & 41 deletions doc/r-plugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin to work with R~

Author: Jakson A. Aquino (jalvesaq@gmail.com)
Last Change: 10 Jun 2009
Last Change: 10 Aug 2009

For Vim version 7.2 and above

Expand Down Expand Up @@ -90,24 +90,9 @@ Optional steps~

Edit Vim's ToolBar and remove the buttons that you never use. The plugin adds
some buttons to the tool bar, but you may not see them because gvim has too
many buttons by default. For example:
>
aunmenu ToolBar.Open
<
You can edit the file ftplugin/r.vim and replace xterm by other terminal
emulator. The file ftplugin/r.vim has an example of how to use gnome-terminal.

Desktop integration~
many buttons by default. Please see:

If you prefer to use the file manager instead of a terminal emulator to
navigate in the directory tree and to open files, you might be interested in
configuring your file manager to use the script ~/.vim/open-gvim-here to open
R source code. For example, if you use Gnome, open nautilus, right click a
file whose extension is .R, choose the menu item "Properties" and configure
the "Open with" command.

The script open-gvim-here simply changes to the file's directory before
opening it.
http://vim.wikia.com/wiki/Hide_specific_ToolBar_buttons


==============================================================================
Expand Down Expand Up @@ -136,7 +121,7 @@ and, in some cases, tool bar buttons:
<F8> Build tags file (/tmp/.Rtags-user-time) for omni completion.
<F9> Send the current line or selected code and go to the next line.
<C-F9> Send the current function.
<S-Enter> Send the current line to R and open a new line (insert mode only).
<M-Enter> Send the current line to R and open a new line (insert mode only).
<_> In insert mode, write " <- ", if not inside a string. Please,
type "_" again if the function yields " <- " when you really
needs "_".
Expand Down Expand Up @@ -197,6 +182,16 @@ include the column names.
6. Known bugs and workarounds~
*r-plugin-known-bugs*

Some correctly written code is wrongly indented. All other know bugs are due
to running R through a pipe. The definitive solution would be to find a better
means of communication between Vim and R.

You should never close the xterm directly~

You should always finish the R session with R's quit() command. If you close
the xterm directly, R will still be running and may begin to run crazily. Vim
will freeze if you try to send code to R.

You should never hit CTRL-C~

You should never hit CTRL-C in the terminal emulator window. If you hit CTRL-C
Expand All @@ -209,44 +204,65 @@ process, but currently you can't do this if R is running through a pipe.
You cannot send large blocks of code to R~

The plugin does not send more than 4000 bytes at once to R because it could
freeze the terminal emulator window. If you have large blocks of code to send
to R, you will not be able to send the whole code at once.
freeze the terminal emulator window. If you have larger blocks of code to send
to R, you will not be able to send the whole code at once, unless you change
this value. See|g:vimrplugin_pipe_limit|.

You should close any pager or web browser opened by R~

After doing "quit()" in R, you still have to close any pager running in
separate terminal emulator or web browser that were opened by R's "help()" or
"?" commands. Otherwise the terminal emulator where R was running will not
close and the pipe file will not be deleted. It's not necessary to close the
web browser if it was already open when help.start() was done.

The terminal emulator truncates big lines sent by Vim~

The truncated lines are not a xterm limitation, but an issue with running R
through a pipe (and I don't know how to solve it). However, I don't see this
annoying problem as a serious bug because you still have the entire lines in
the script that you are editing with Vim. You can break the lines in Vim
before sending them to R, and, in my opinion, the code will become more
readable.
through a pipe. You may break the lines in Vim before sending them to R.

R's autocomplete function does not work in the terminal and~
you cannot scroll R help files in the terminal emulator~

It seems that R doesn't use GNU Readline when called through a pipe. That's
why you can't complete object names with <Tab> in the terminal window (and
that's why I created the omni function for Vim). Regarding the scroll issue in
R help, the best solution for me is to do "help.start()" in the terminal
window before using help(). This will be done automatically by the plugin (see
R help(), workarounds are to use less as pager or do "help.start()" in the
terminal window before using help(). Please, see |r-pager| and
|g:vimrplugin_nohstart|for details).


==============================================================================
7. Options~
*r-plugin-options*

*g:vimrplugin_term_cmd*
*g:vimrplugin_term*
The plugin uses uxterm to run R, but you may define another terminal emulator
in your|vimrc|by setting the variable g:vimrplugin_term_cmd, as in the example
in your|vimrc|by setting the variable g:vimrplugin_term, as in the example
below:
>
let g:vimrplugin_term = "gnome-terminal"
<
Supported terminals are: xterm, gnome-terminal, konsole, xfce4-terminal,
Eterm, rxvt and aterm.
*g:vimrplugin_term_cmd*
If your terminal emulator is not listed above, or if you are not satisfied
with the way your terminal emulator is called by the plugin, you may define in
your|vimrc|the variable g:vimrplugin_term_cmd, as in the example below:
>
let g:vimrplugin_term_cmd = "gnome-terminal -t R -x"
<
*g:vimrplugin_underscore*
To disable the underscore replacement with " <- " put in your |vimrc|:
>
let g:vimrplugin_underscore = 1
<
*r-pager*
You may also want to use less in a separate terminal emulator as the default
pager for R's help. You can use the script ~/.vim/tools/rpager.sh (which will
call less) by putting in your ~/.Rprofile:
>
options(pager="~/.vim/tools/rpager.sh")
<
*g:vimrplugin_nohstart*
The plugin will call R's function help.start() the first time that you press
Expand All @@ -261,18 +277,19 @@ may want to add the following global variable (with the appropriate value) to
your|vimrc|:
>
let g:vimrplugin_browser_time = 4
<
In addition to using help.start() you may also want to use less as the default
pager for R's help. You can use the script ~/.vim/tools/rpager.sh which will
call less by putting in your ~/.Rprofile:
>
options(pager="~/.vim/tools/rpager.sh")
<
*g:vimrplugin_single_pipe*
If you prefer that all Vim buffers use the same R process, put the following
option in your |vimrc|:
>
let g:vimrplugin_single_pipe = 1
<
*g:vimrplugin_pipe_limit*
By default, the plugin will send at most 4000 bytes of data to R to decrease
the probability of obstructing the pipe, but you can increase this value at
your own risk. Example:
>
let g:vimrplugin_pipe_limit = 5000
<
*g:vimrplugin_map_r*

Expand All @@ -282,7 +299,7 @@ with the original plugin). To activate this option, put in your |vimrc|:
>
let g:vimrplugin_map_r = 1
<
You may want to put in your |vimrc|the following three lines which are in the
You may want to put in your|vimrc|the following three lines which are in the
original plugin and are intended to increase compatibility with emacs edited
code:
>
Expand Down Expand Up @@ -340,9 +357,9 @@ bindings:
map <F9> <Plug>RSendLine
imap <F9> <Plug>RSendLine
vmap <F9> <Plug>RSendLine
map <S-Enter> <Plug>RSendLineAndOpenNewOne
imap <S-Enter> <Plug>RSendLineAndOpenNewOne
vmap <S-Enter> <Plug>RSendLineAndOpenNewOne
map <M-Enter> <Plug>RSendLineAndOpenNewOne
imap <M-Enter> <Plug>RSendLineAndOpenNewOne
vmap <M-Enter> <Plug>RSendLineAndOpenNewOne
vmap <F9> <Plug>RSendBlock
map <C-F9> <Plug>RSendFunction
imap <C-F9> <Plug>RSendFunction
Expand All @@ -367,6 +384,8 @@ directory after the installation:
| |-- rbuffer.xpm
| |-- rcomplete.xpm
| |-- rfunction.xpm
| |-- ricon.png
| |-- ricon.xbm
| |-- rkill.xpm
| |-- rline.xpm
| |-- rregion.xpm
Expand All @@ -381,7 +400,6 @@ directory after the installation:
|-- indent
| `-- r.vim
`-- tools
|-- open-gvim-here
|-- rargs.R
|-- rfunnel.pl
|-- rpager.sh
Expand Down
57 changes: 47 additions & 10 deletions ftplugin/r.vim
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,50 @@ if exists("g:vimrplugin_browser_time") == 0
let g:vimrplugin_browser_time = 4
endif

if exists("g:vimrplugin_pipe_limit")
let b:pipe_limit = g:vimrplugin_pipe_limit
else
let b:pipe_limit = 4000
endif

let b:replace_us = 1
if exists("g:vimrplugin_underscore")
if g:vimrplugin_underscore != 0
let b:replace_us = 0
endif
endif

" What terminal is preferred:

" Terminal options:
let b:term_cmd = "uxterm -xrm '*iconPixmap: " . expand("~") . "/.vim/bitmaps/ricon.xbm' -T '" . expand("%:t") . "' -e"

if exists("g:vimrplugin_term")
if g:vimrplugin_term == "xterm"
let b:term_cmd = "xterm -xrm '*iconPixmap: " . expand("~") . "/.vim/bitmaps/ricon.xbm' -T '" . expand("%:t") . "' -e"
endif
if g:vimrplugin_term == "gnome-terminal"
" Cannot set icon: http://bugzilla.gnome.org/show_bug.cgi?id=126081
let b:term_cmd = "gnome-terminal --working-directory='" . expand("%:p:h") . "' -t 'R - " . expand("%:t") . "' -x"
endif
if g:vimrplugin_term == "konsole"
let b:term_cmd = "konsole --workdir '" . expand("%:p:h") . "' --icon ~/.vim/bitmaps/ricon.png --title '" . expand("%:t") . "' -e"
endif
if g:vimrplugin_term == "xfce4-terminal"
let b:term_cmd = "xfce4-terminal --working-directory='" . expand("%:p:h") . "' -t 'R - " . expand("%:t") . "' -x"
endif
if g:vimrplugin_term == "Eterm"
let b:term_cmd = "Eterm --icon ~/.vim/bitmaps/ricon.png -n '" . expand("%:t") . "' -e"
endif
if g:vimrplugin_term == "rxvt"
let b:term_cmd = "rxvt -title 'R - " . expand("%:t") . "' -e"
endif
if g:vimrplugin_term == "aterm"
let b:term_cmd = "aterm -title 'R - " . expand("%:t") . "' -e"
endif
endif

if exists("g:vimrplugin_term_cmd")
let b:term_cmd = g:vimrplugin_term_cmd
else
let b:term_cmd = "uxterm -T 'R' -e"
endif

" Automatically source the script tools/rargs.R the first time <S-F1> is
Expand Down Expand Up @@ -102,7 +134,7 @@ endif
setl backupskip=/tmp/.r-pipe*

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" From the orignal plugin:
" From the original plugin:
" Set tabstop so it is compatible with the emacs edited code. Personally, I
" prefer shiftwidth=2, which I have in my .vimrc anyway
" set expandtab
Expand Down Expand Up @@ -185,8 +217,8 @@ function! CheckBlockSize(lines, type)
let b:needsnewtags = 1
endif
endfor
if nbytes > 4000
call RWarningMsg("We can send to R at most 4000 bytes at once, but this " . a:type . " has " . nbytes . " bytes.")
if nbytes > b:pipe_limit
call RWarningMsg("We can send to R at most " . b:pipe_limit . " bytes at once, but this " . a:type . " has " . nbytes . " bytes.")
return 1
endif
return 0
Expand Down Expand Up @@ -382,9 +414,14 @@ function! StartR(whatr, kbdclk)
endif
return
endif
" Run R
let opencmd = printf("%s ~/.vim/tools/rfunnel.pl %s \"%s && echo -e 'Interpreter has finished. Exiting. Goodbye.'\"&", b:term_cmd, b:pipefname, a:whatr)

let opencmd = printf("%s ~/.vim/tools/rfunnel.pl %s \"%s && echo -e 'Interpreter has finished. Please close any remaining help pager or web browser that you have opened.'\"&", b:term_cmd, b:pipefname, a:whatr)

" Change to buffer's directory, run R, and go back to original directory:
lcd %:p:h
let rlog = system(opencmd)
lcd -

if rlog != ""
call RWarningMsg(rlog)
return
Expand Down Expand Up @@ -545,7 +582,7 @@ endif
if hasmapto('<Plug>RSendLineAndOpenNewOne')
inoremap <buffer> <Plug>RSendLineAndOpenNewOne <Esc>:call SendLineToR(0)<CR>o
else
inoremap <buffer> <S-Enter> <Esc>:call SendLineToR(0)<CR>o
inoremap <buffer> <M-Enter> <Esc>:call SendLineToR(0)<CR>o
endif

" Send current file to R
Expand Down Expand Up @@ -629,7 +666,7 @@ function! MakeRMenu()
if hasmapto('<Plug>RSendLineAndOpenNewOne')
imenu R.Send\ line\ and\ &open\ a\ new\ one <Esc>:call SendLineToR(0)<CR>o
else
imenu R.Send\ line\ and\ &open\ a\ new\ one<Tab><S-Enter> <Esc>:call SendLineToR(0)<CR>o
imenu R.Send\ line\ and\ &open\ a\ new\ one<Tab><M-Enter> <Esc>:call SendLineToR(0)<CR>o
endif
if hasmapto('<Plug>RSendFile')
amenu R.Send\ &file :call SendFileToR()<CR>
Expand Down
Loading

0 comments on commit 1cabc86

Please sign in to comment.