Add R language support

This commit is contained in:
Adam Stankiewicz 2013-09-30 12:04:53 +02:00
parent e9d8c39608
commit b3257271db
7 changed files with 389 additions and 0 deletions

View File

@ -57,6 +57,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
- [puppet](https://github.com/ajf/puppet-vim) (syntax, indent, ftplugin, ftdetect)
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, ftdetect)
- [python](https://github.com/vim-scripts/python.vim--Vasiliev) (syntax)
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
- [rspec](https://github.com/sheerun/rspec.vim) (syntax, ftdetect)
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
- [rust](https://github.com/wting/rust.vim) (syntax, indent, compiler, ftplugin, ftdetect)

1
build
View File

@ -97,6 +97,7 @@ PACKS="
puppet:ajf/puppet-vim
protobuf:uarun/vim-protobuf
python:vim-scripts/python.vim--Vasiliev
r-lang:vim-scripts/R.vim
rspec:sheerun/rspec.vim
ruby:vim-ruby/vim-ruby
rust:wting/rust.vim

69
ftplugin/r.vim Normal file
View File

@ -0,0 +1,69 @@
" ftplugin for R files
"
" Author: Iago Mosqueira <i.mosqueira@ic.ac.uk>
" Author: Johannes Ranke <jranke@uni-bremen.de>
" Author: Fernando Henrique Ferraz Pereira da Rosa <feferraz@ime.usp.br>
" Maintainer: Johannes Ranke <jranke@uni-bremen.de>
" Last Change: 2007 Nov 21
" SVN: $Id: r.vim 75 2007-11-21 13:34:02Z ranke $
"
" Code written in vim is sent to R through a perl pipe
" [funnel.pl, by Larry Clapp <vim@theclapp.org>], as individual lines,
" blocks, or the whole file.
" Press <F2> to open a new xterm with a new R interpreter listening
" to its standard input (you can type R commands into the xterm)
" as well as to code pasted from within vim.
"
" After selecting a visual block, 'r' sends it to the R interpreter
"
" In insert mode, <M-Enter> sends the active line to R and moves to the next
" line (write and process mode).
"
" Maps:
" <F2> Start a listening R interpreter in new xterm
" <F3> Start a listening R-devel interpreter in new xterm
" <F4> Start a listening R --vanilla interpreter in new xterm
" <F5> Run current file
" <F9> Run line under cursor
" r Run visual block
" <M-Enter> Write and process
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
finish
endif
" Don't load another plugin for this buffer
let b:did_ftplugin = 1
" Disable backup for .r-pipe
setl backupskip=.*pipe
" 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
set shiftwidth=4
set tabstop=8
" Start a listening R interpreter in new xterm
noremap <buffer> <F2> :!xterm -T 'R' -e funnel.pl ~/.r-pipe "R && echo -e 'Interpreter has finished. Exiting. Goodbye.\n'"&<CR><CR>
" Start a listening R-devel interpreter in new xterm
noremap <buffer> <F3> :!xterm -T 'R' -e funnel.pl ~/.r-pipe "R-devel && echo 'Interpreter has finished. Exiting. Goodbye.'"&<CR><CR>
" Start a listening R --vanilla interpreter in new xterm
noremap <buffer> <F4> :!xterm -T 'R' -e funnel.pl ~/.r-pipe "R -vanilla && echo 'Interpreter has finished. Exiting. Goodbye.'"&<CR><CR>
" Send line under cursor to R
noremap <buffer> <F9> :execute line(".") 'w >> ~/.r-pipe'<CR>
inoremap <buffer> <F9> <Esc> :execute line(".") 'w >> ~/.r-pipe'<CR>
" Send visual selected block to R
vnoremap <buffer> r :w >> ~/.r-pipe<CR>
" Write and process mode (somehow mapping <C-Enter> does not work)
inoremap <M-Enter> <Esc>:execute line(".") 'w >> ~/.r-pipe'<CR>o
" Send current file to R
noremap <buffer> <F5> :execute '1 ,' line("$") 'w >> ~/.r-pipe' <CR><CR>

48
ftplugin/rhelp.vim Normal file
View File

@ -0,0 +1,48 @@
" ftplugin for R help files
"
" Author: Johannes Ranke <jranke@uni-bremen.de>
" Last Change: 2007 Nov 21
" SVN: $Id: rhelp.vim 75 2007-11-21 13:34:02Z ranke $
"
" Usage:
"
" Press <F2> to open a new xterm with a new R interpreter listening
" to its standard input (you can type R commands into the xterm)
" as well as to code pasted from within vim.
"
" After selecting a visual block, 'r' sends it to the R interpreter
"
" Add to filetypes.vim, if you don't use vim 7
" au BufNewFile,BufRead *.Rd,*.rd setf rhelp
"
" Maps:
" <F2> Start a listening R interpreter in new xterm
" <F9> Run line under cursor
" r Run visual block
" <M-Enter> Write and process R code
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
finish
endif
" Don't load another plugin for this buffer
let b:did_ftplugin = 1
" Set tabbing
set expandtab
set tabstop=2
set shiftwidth=2
" Start a listening R interpreter in new xterm
noremap <buffer> <F2> :!xterm -T 'R' -e funnel.pl ~/.r-pipe "R && echo -e 'Interpreter has finished. Exiting. Goodbye.\n'"&<CR><CR>
" Send line under cursor to R
noremap <buffer> <F9> :execute line(".") 'w >> ~/.r-pipe'<CR>
inoremap <buffer> <F9> <Esc> :execute line(".") 'w >> ~/.r-pipe'<CR>
" Send visual selected block to R
vnoremap <buffer> r :w >> ~/.r-pipe<CR>
" Write and process mode (somehow mapping <C-Enter> does not work)
inoremap <M-Enter> <Esc>:execute line(".") 'w >> ~/.r-pipe'<CR>o

59
ftplugin/rnoweb.vim Normal file
View File

@ -0,0 +1,59 @@
" ftplugin for Sweave files containing both LaTeX and R code
"
" Maintainer: Johannes Ranke <jranke@uni-bremen.de>
" Last Change: 2007 Nov 21
" SVN: $Id: rnoweb.vim 75 2007-11-21 13:34:02Z ranke $
"
" Usage:
"
" Press <F2> to open a new xterm with a new R interpreter listening
" to its standard input (you can type R commands into the xterm)
" as well as to code pasted from within vim.
"
" A Makefile for producing R noweb files is in included in my Vim script
" R.vim:
" http://www.vim.org/scripts/script.php?script_id=1048
" You can also look in my SVN repository under:
" http://kri/viewcvs/*checkout*/Makefile.rnoweb?root=vim
"
"
" After selecting a visual block, 'r' sends it to the R interpreter
"
" Add to filetypes.vim, if you don't use vim 7
" au BufNewFile,BufRead *.Rnw,*.rnw setf rnoweb
" and/or
" au BufNewFile,BufRead *.Snw,*.snw setf rnoweb
"
" Maps:
" <F2> Start a listening R interpreter in new xterm
" <F9> Run line under cursor
" r Run visual block
" <M-Enter> Write and process R code
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
finish
endif
" Don't load another plugin for this buffer
let b:did_ftplugin = 1
" Disable backup for .r-pipe
setl backupskip=.*pipe
" Set R friendly tabbing
set expandtab
set shiftwidth=2
" Start a listening R interpreter in new xterm
noremap <buffer> <F2> :!xterm -T 'R' -e funnel.pl ~/.r-pipe "R && echo -e 'Interpreter has finished. Exiting. Goodbye.\n'"&<CR><CR>
" Send line under cursor to R
noremap <buffer> <F9> :execute line(".") 'w >> ~/.r-pipe'<CR>
inoremap <buffer> <F9> <Esc> :execute line(".") 'w >> ~/.r-pipe'<CR>
" Send visual selected block to R
vnoremap <buffer> r :w >> ~/.r-pipe<CR>
" Write and process mode (somehow mapping <C-Enter> does not work)
inoremap <M-Enter> <Esc>:execute line(".") 'w >> ~/.r-pipe'<CR>o

155
syntax/rhelp.vim Normal file
View File

@ -0,0 +1,155 @@
" Vim syntax file
" Language: R Help File
" Maintainer: Johannes Ranke <jranke@uni-bremen.de>
" Last Change: 2006 Apr 24
" Version: 0.7
" SVN: $Id: rhelp.vim 57 2006-04-24 15:52:13Z ranke $
" Remarks: - Now includes R syntax highlighting in the appropriate
" sections if an r.vim file is in the same directory or in the
" default debian location.
" - There is no Latex markup in equations
" Version Clears: {{{1
" For version 5.x: Clear all syntax items
" For version 6.x and 7.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syn case match
" R help identifiers {{{
syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}"
syn region rhelpIdentifier matchgroup=rhelpSection start="\\item{" end="}" contained contains=rhelpDots
syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end=/}/ contained
" Highlighting of R code using an existing r.vim syntax file if available {{{1
syn include @R syntax/r.vim
syn match rhelpDots "\\dots" containedin=@R
syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end=/}/ contains=@R,rhelpSection
syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end=/}/ contains=@R,rhelpIdentifier,rhelpS4method
syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end=/}/ contains=@R
syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end=/}/ contains=@R contained
syn region rhelpRcode matchgroup=Delimiter start="\\code{" matchgroup=Delimiter transparent end=/}/ contains=@R,rhelpLink contained
syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=/)/ contains=@R,rhelpDots contained
" Strings {{{1
syn region rhelpString start=/"/ end=/"/
" Special characters ( \$ \& \% \# \{ \} \_) {{{1
syn match rhelpSpecialChar "\\[$&%#{}_]"
" Special Delimiters {{{1
syn match rhelpDelimiter "\\cr"
syn match rhelpDelimiter "\\tab "
" Keywords {{{1
syn match rhelpKeyword "\\R"
syn match rhelpKeyword "\\ldots"
syn match rhelpKeyword "--"
syn match rhelpKeyword "---"
syn match rhelpKeyword "<"
syn match rhelpKeyword ">"
" Links {{{1
syn region rhelpLink matchgroup=rhelpSection start="\\link{" end="}" contained keepend
syn region rhelpLink matchgroup=rhelpSection start="\\link\[.*\]{" end="}" contained keepend
syn region rhelpLink matchgroup=rhelpSection start="\\linkS4class{" end="}" contained keepend
" Type Styles {{{1
syn match rhelpType "\\emph\>"
syn match rhelpType "\\strong\>"
syn match rhelpType "\\bold\>"
syn match rhelpType "\\sQuote\>"
syn match rhelpType "\\dQuote\>"
syn match rhelpType "\\preformatted\>"
syn match rhelpType "\\kbd\>"
syn match rhelpType "\\samp\>"
syn match rhelpType "\\eqn\>"
syn match rhelpType "\\deqn\>"
syn match rhelpType "\\file\>"
syn match rhelpType "\\email\>"
syn match rhelpType "\\url\>"
syn match rhelpType "\\var\>"
syn match rhelpType "\\env\>"
syn match rhelpType "\\option\>"
syn match rhelpType "\\command\>"
syn match rhelpType "\\dfn\>"
syn match rhelpType "\\cite\>"
syn match rhelpType "\\acronym\>"
" rhelp sections {{{1
syn match rhelpSection "\\encoding\>"
syn match rhelpSection "\\title\>"
syn match rhelpSection "\\description\>"
syn match rhelpSection "\\concept\>"
syn match rhelpSection "\\arguments\>"
syn match rhelpSection "\\details\>"
syn match rhelpSection "\\value\>"
syn match rhelpSection "\\references\>"
syn match rhelpSection "\\note\>"
syn match rhelpSection "\\author\>"
syn match rhelpSection "\\seealso\>"
syn match rhelpSection "\\keyword\>"
syn match rhelpSection "\\docType\>"
syn match rhelpSection "\\format\>"
syn match rhelpSection "\\source\>"
syn match rhelpSection "\\itemize\>"
syn match rhelpSection "\\describe\>"
syn match rhelpSection "\\enumerate\>"
syn match rhelpSection "\\item "
syn match rhelpSection "\\item$"
syn match rhelpSection "\\tabular{[lcr]*}"
syn match rhelpSection "\\dontrun\>"
syn match rhelpSection "\\dontshow\>"
syn match rhelpSection "\\testonly\>"
" Freely named Sections {{{1
syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end=/}/
" R help file comments {{{1
syn match rhelpComment /%.*$/ contained
" Error {{{1
syn region rhelpRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rhelpError,rhelpBraceError,rhelpCurlyError
syn region rhelpRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rhelpError,rhelpBraceError,rhelpParenError
syn region rhelpRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rhelpError,rhelpCurlyError,rhelpParenError
syn match rhelpError /[)\]}]/
syn match rhelpBraceError /[)}]/ contained
syn match rhelpCurlyError /[)\]]/ contained
syn match rhelpParenError /[\]}]/ contained
" Define the default highlighting {{{1
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_rhelp_syntax_inits")
if version < 508
let did_rhelp_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink rhelpIdentifier Identifier
HiLink rhelpString String
HiLink rhelpKeyword Keyword
HiLink rhelpDots Keyword
HiLink rhelpLink Underlined
HiLink rhelpType Type
HiLink rhelpSection PreCondit
HiLink rhelpError Error
HiLink rhelpBraceError Error
HiLink rhelpCurlyError Error
HiLink rhelpParenError Error
HiLink rhelpDelimiter Delimiter
HiLink rhelpComment Comment
HiLink rhelpRComment Comment
HiLink rhelpSpecialChar SpecialChar
delcommand HiLink
endif
let b:current_syntax = "rhelp"
" vim: foldmethod=marker:

56
syntax/rnoweb.vim Normal file
View File

@ -0,0 +1,56 @@
" Vim syntax file
" Language: R noweb Files
" Maintainer: Johannes Ranke <jranke@uni-bremen.de>
" Last Change: 2007 Mär 30
" Version: 0.8
" SVN: $Id: rnoweb.vim 69 2007-03-30 08:55:36Z ranke $
" Remarks: - This file is inspired by the proposal of
" Fernando Henrique Ferraz Pereira da Rosa <feferraz@ime.usp.br>
" http://www.ime.usp.br/~feferraz/en/sweavevim.html
"
" Version Clears: {{{1
" For version 5.x: Clear all syntax items
" For version 6.x and 7.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syn case match
" Extension of Tex clusters {{{1
runtime syntax/tex.vim
unlet b:current_syntax
syn cluster texMatchGroup add=@rnoweb
syn cluster texEnvGroup add=@rnoweb
syn cluster texFoldGroup add=@rnoweb
syn cluster texDocGroup add=@rnoweb
syn cluster texPartGroup add=@rnoweb
syn cluster texChapterGroup add=@rnoweb
syn cluster texSectionGroup add=@rnoweb
syn cluster texSubSectionGroup add=@rnoweb
syn cluster texSubSubSectionGroup add=@rnoweb
syn cluster texParaGroup add=@rnoweb
" Highlighting of R code using an existing r.vim syntax file if available {{{1
syn include @rnowebR syntax/r.vim
syn region rnowebChunk matchgroup=rnowebDelimiter start="^<<.*>>=" matchgroup=rnowebDelimiter end="^@" contains=@rnowebR,rnowebChunkReference,rnowebChunk fold keepend
syn match rnowebChunkReference "^<<.*>>$" contained
syn region rnowebSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter end="}" contains=@rnowebR
" Sweave options command {{{1
syn region rnowebSweaveopts matchgroup=Delimiter start="\\SweaveOpts{" matchgroup=Delimiter end="}"
" rnoweb Cluster {{{1
syn cluster rnoweb contains=rnowebChunk,rnowebChunkReference,rnowebDelimiter,rnowebSexpr,rnowebSweaveopts
" Highlighting {{{1
hi def link rnowebDelimiter Delimiter
hi def link rnowebSweaveOpts Statement
hi def link rnowebChunkReference Delimiter
let b:current_syntax = "rnoweb"
" vim: foldmethod=marker: