Nano is Free Software and a nice intro text editor. It also starts up very quickly and has good syntax highlighting functionality, so it makes a nice file viewer. The syntax highlighting is configured in the ~/.nanorc file. See the attached code and screenshot.

I was looking for good nano syntax highlighting code for R when I found by Stephen Haptonstahl's code here:

http://srh.ucdavis.edu/drupal/node/20

He is happy for others to use the code, modify it and distribute it. My edited version of his code is attached. To use it, just append it to your ~/.nanorc file. There's also a systemwide way to use it, but I don't know offhand. To use nano in a view-only mode, just use the -v option to turn off editing functionality:

nano -v file.R

The .R file extension will cause Nano to use the R syntax highlighting, but it can also be triggered with the -Y option:

nano -v -Y R file.whatever

Of course, nano also is an editor, so just drop the -v option if you want to edit a file.

The screenshot looks pretty nice now (I'm using xterm with white on black and haven't tested with black on white), but I'm sure it can be improved further. I don't have time to work on it much now, but maybe someone else will want to pick it up.

Best,
Mike

--
Michael B. Miller, Ph.D.
Bioinformatics Specialist
Minnesota Center for Twin and Family Research
Department of Psychology
University of Minnesota
############################################
#  Syntax highlighting for R               #
#  by Stephen Haptonstahl                  #
#  March 15, 2009                          #
#  http://srh.ucdavis.edu/drupal/node/20   #
#  edited by Mike Miller                   #
############################################

syntax "R" "\.R$"

# reserved words
color brightyellow 
"\b(if|else|repeat|while|function|for|in|next|break|TRUE|T|FALSE|F|NULL|Inf|NaN|NA|NA_integer_|NA_real_|NA_complex_|NA_character_|\.\.\.)\b"
color brightyellow "\.\.[0-9]"
color brightred "\b(require|library)\b"

# logicals
color brightgreen "(==|<=|>=|!=|!|<|>|\||\|\||&|&&|%in%|%%|%\*%|%/%|%o%|%x%)"

# strings
color cyan "'[^']*'"
color cyan ""[^"]*""
# "

# variable definitions
color blue "^.*?<-"

color yellow start="[...@%]" end="[[:alnum:]]*"

# function definitions
color magenta "\<([A-Za-z0-9\.]+)\>\("

# parameters -- not working yet
# icolor brightblue "[^,\(=]*=(?:[^=])"

# danger!
color black,red "(stop|warning|return)"
color red " = "

color yellow "[(){}[;|<>]"
color yellow "\]"
color brightred "<-"

## Comment highlighting
color brightblack "#.*$"

<<ATTACHMENT: nano_R.png>>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to