NCL Home>
Application examples>
Miscellaneous ||
Data files for some examples
Example pages containing:
tips |
resources |
functions/procedures
Editor Enhancements
This page contains some handy scripts for customizing various editors
to do special highlighting of NCL syntax. They were documented and
contributed by other users.
These editor scripts are not necessarily supported by the NCL team,
but we greatly appreciate and encourage these kind of contributions.
In order to help create your own editor enhancements, you can use the
functions
in gen_editor_utils.ncl to
create lists of all the NCL functions/procedures, keywords, operators,
and/or resource names. See the comments at the top.
If you have an editor enhancement contribution for NCL, send
email to ncl-talk.
ncl.el: emacs
Emacs NCL mode screenshot
Functionality includes:
- Indents two spaces between "begin" and "end" statments
- Indents two spaces within "do" loops and "if" statments
- Comment handling (M-;)
- insert a comment at the end of the current line
- Alternatively comment/uncomment selected region
- Highlighting (chose your
colors)
Issues that remain
- Comment Handling does not work in xemacs
- Comments may not fontify on file open in xemacs
Controlling your emacs window:
Add and modify the following to your .Xdefaults if desired:
Emacs.geometry: 80x38+250+10
Emacs*background: antique white
Emacs*foreground: black
Emacs.pane.menubar.background: peachpuff
Emacs.menu*.background: peachpuff
Emacs.cursorColor: red3
Emacs.font: 10x20
Emacs.pane.menubar.font: 10x20
Steps
- Download the ncl.el file and put it on
your system.
- Put the following text in your .emacs file: (note, if you do not
like the specified colors, you can change them here or not include this portion in
your .emacs file)
(setq auto-mode-alist (cons '("\.ncl$" . ncl-mode) auto-mode-alist))
; this line associates ncl-mode with the lisp package that defines it.
(autoload 'ncl-mode "~/bin/ncl.el")
; a hook is a list of functions that get executed under certain
; conditions.
(add-hook 'ncl-mode-hook
(lambda () ; lambda is an anonymous function. e.g. has no name.
; highlight comments
(set-face-foreground font-lock-comment-face "FireBrick")
; highlight strings
(set-face-foreground font-lock-string-face "Salmon")
; highlight keywords, array descriptors, and tests
(set-face-foreground font-lock-keyword-face "Purple")
; highlight built-in functions
(set-face-foreground font-lock-builtin-face "Blue")
; highlight gsn* functions
(set-face-foreground font-lock-variable-name-face "SteelBlue")
; highlight shea_util and contributed functions
(set-face-foreground font-lock-function-name-face "CadetBlue")
; highlight resources
(set-face-foreground font-lock-constant-face "ForestGreen")
)
)
Change ~/bin/ncl.el to the location of YOUR ncl.el file
Modify the ncl.el code as necessary to include functions or keywords
not specifically listed
The Emacs NCL mode was first implemented by Sylvia Murphy at NCAR. Updates
have been provided by Heiko Klein of Norway, Carl Schreck and Alan Srock of the
University at Albany (SUNY), and Thierry Corti of ETH in Zurich, Switzerland.
ncl.nedit /
ncl2.nedit /
ncl3.nedit:Various files for
nedit
The following scripts enable NCL syntax highlighting in nedit versions
5.1.0 and higher. The scripts range from a minimalistic approach with
few highlighting schemes and few colors, to a more thorough
highlighting scheme with many colors. The scripts can be downloaded
and, if desired, edited and tested. When ready you can import
the file into nedit by typing, for example:
nedit -import ncl.edit
You will only have to import the file once. Go to "Preferences"
and click on "Save Defaults".
- ncl.nedit -a minimalistic approach,
keywords and flow constructs are in bold-black, comments are plain-red
and symbols are highlighted in bold-blue (courtesy of Dennis Shea)
- ncl2.nedit - a more moderate
highlighting scheme that highlights attributes, I/O functions (among
others) (courtesy of Adam Phillips)
- ncl3.nedit - an intensive syntax
highlighting approach that highlights most NCL functions (courtesy of
Paul Thomas Quelet). Updated periodically by volunteers to reflect new
syntax or functions.
ncl.vim /
ncl2.vim /
ncl.dic : Various files for
vim
Steps
- Download the desired .vim file [naming it ncl.vim] and put it in
your .vim/syntax directory
- Put the following text in your .vimrc file
au BufRead,BufNewFile *.ncl set filetype=ncl
au! Syntax newlang source $VIM/ncl.vim
ncl1.vim -a simple approach
(courtesy of Kevin Mueller [UIUC])
ncl2.vim - extensive highlighting
of functions through v5.0.0 with some v5.1.0 functions
included. (courtesy of Arindam Chakraborty [Indian Institute of Science])
The following was donated by Prince K. Xavier [Laboratoire de
Meteorologie Dynamique, France].
I experimented a bit with the VIM to include an auto-completion option for
NCL commands. I think I have some good news for those who do not want to
remember all the commands or consult the website often while writing a
script! I find it particularly useful! Here is what you have to do.
- save ncl.dic to ~/.vim/dictionary/
(I took the commands from the ncl syntax file compiled by Arindam
Chakraborty. I am not sure how complete this list is, but one can always
add entries to this file.)
- make the following entries to your .gvimrc
"Show autocomplete menus.
set complete-=k complete+=k " Add dictionary search (as per dictionary option)
set wildmode=list:full
set wildmenu
au BufRead,BufNewFile *.ncl set dictionary=~/.vim/dictionary/ncl.dic
- open your .ncl file and start typing the first letter of the
command/resource/function name and press 'control+n' and choose your
option.
Here is a screenshot of my editor
that works great!
ncl.sl :
JED
This script was contributed by TJ Olney of Western Washington
University, for use with John E Davis's JED editor.
The latest version (June 1, 2011) has been updated to work with NCL
V6.0.0, and should be used with version 99.19 of jed.
JED is a freely available text editor for Unix, VMS, MSDOS, OS/2,
BeOS, QNX, and win9X/NT platforms. Although it is a powerful editor
designed for use by programmers, its drop-down menu facility make it
one of the friendliest text editors around. Hence it is ideal for
composing simple email messages as well as editing complex programs in
a variety of computer languages.
JED makes extensive use of the S-Lang library, which endows it with a
powerful S-Lang macro language. This and other features of the library
are discussed on the features page.
To incorporate this syntax in your JED environment, add the lines from
the ncl.sl to your "defaults.sl" or "jed.rc"
(.jedrc) file. The instructions are also in the file.
NCL.tmbundle.zip :
TextMate
This script was contributed by Ryan Pavlick of the Biospheric Theory
and Modelling Group at Max Planck Institute for Biogeochemistry.
To install the file, unzip the "NCL.tmbundle.zip" file, double click
"NCL.tmbundle", and restart TextMate if it is open. If that doesn't
work, try opening a Terminal window and enter the following two
commands:
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cp NCL.tmbundle ~/Library/Application\ Support/TextMate/Bundles/
then restart TextMate.
ncl_gedit_xml.tgz :
gedit
This configuration was contributed by Chad Herman.
To install, unwrap
the ncl_gedit_xml.tgz tarball in
some convenient directory, cd into the ncl_gedit_xml
directory and run the install.sh bash script as follows:
# Install for gedit 2.x
./install.sh 2
# Install for gedit 3.x
./install.sh 3
The tarball and ncl_gedit_xml directory can be deleted
after the installation.
Chad writes:
Gedit should now recognise and highlight your *.ncl files. If you
start gedit in the terminal, you'll see a *warning*:
(gedit:6532): GtkSourceView-WARNING **: Cannot create a regex for all the
transitions, the syntax highlighting process will be slower than usual.
The error was: Error while compiling regular expression ...
This is nothing to worry about. This started showing up after I added
all of
the "resource" names (all 1,452 of them). NCL is a big language!
For MacOS X users with an official binary of
gedit, Rob Nicholas of the Dept. of
Geosciences at Penn State University advises:
...for those of you using the official Mac OS X binary for gedit,
you'll need to change line 57 of the install script to:
sudo cp ncl.lang \
/Applications/gedit.app/Contents/Resources/share/gtksourceview-2.0/language-specs
Rob further notes that this does not apply to users who obtained gedit
through Fink or MacPorts.
ncl.el: aquamacs
This editor enhancement for Aquamacs
was contributed by Luis C. Cana Cascallar of the Universidad de Las Palmas de Gran Canaria.
Aquamacs NCL mode screenshot
Aquamacs (see
http://aquamacs.org)
is a free editor based on the GNU Emacs but with a deep integration in
Mac OSX. These are the steps following some recommendations of David
Reiter, the main developer and maintainer of Aquamacs:
- Download ncl.el file (the same for
Emacs) and put it on the system.
David Reiter's suggestion: /YOUR-HOME-DIRECTORY/Library/Application
Support/Aquamacs Emacs
- Add the following piece of code in
/YOUR-HOME-DIRECTORY/Library/Preferences/Aquamacs Emacs/Preferences.el
;=======================
(setq auto-mode-alist (cons '("\.ncl$" . ncl-mode) auto-mode-alist))
; This line associates ncl-mode with the lisp package that defines it.
(autoload 'ncl-mode "/YOUR-HOME-DIRECTORY/Library/Application Support/Aquamacs Emacs/ncl.el") ; <<<<<<<< pointing to the right place
; a hook is a list of functions that get executed under certain
; conditions.
(add-hook 'ncl-mode-hook
(lambda () ; lambda is an anonymous function. e.g. has no name.
; highlight comments
(set-face-foreground font-lock-comment-face "FireBrick")
; highlight strings
(set-face-foreground font-lock-string-face "Salmon")
; highlight keywords, array descriptors, and tests
(set-face-foreground font-lock-keyword-face "Purple")
; highlight built-in functions
(set-face-foreground font-lock-builtin-face "Blue")
; highlight gsn* functions
(set-face-foreground font-lock-variable-name-face "SteelBlue")
; highlight shea_util and contributed functions
(set-face-foreground font-lock-function-name-face "CadetBlue")
; highlight resources
(set-face-foreground font-lock-constant-face "ForestGreen")
)
)
;====================================
And that's all!
If there is any problem, one should check first which is the Major Mode:
Mode Line (at bottom of screen).
M-x ncl-mode RET will enter the mode manually
Another possibility is just adding to the FIRST LINE of the ncl script
this single line:
; -*- mode: ncl;-*-
This trick switches the mode to NCL.
Robert Schuster has written
a
NetBeans
plugin that supports NCL script development. It features:
- Syntax highlighting and checking.
- Code completion for all NCL procedures functions and resources:
type the first few letters followed by CTRL-SPACE to get a list of
all procedures/functions/resources that begin with those
letters.
- Displays online documentation in conjunction with code completion.
- NCL project management: develop, manage and run ncl scripts from
within the NetBeans IDE.
Netbeans is freely available for Unix/Linux, MacOS X, and Windows
machines. See the NetBeans site for more information.
NCL.plist: TextWrangler
The editor enhancement
for TextWrangler
was contributed by Emilie Vanvyve of NCAR/RAL. It highlights NCL
resources, functions, procedures, and keywords. The file should be
put in the directory $HOME/Library/Application
Support/TextWrangler/Language Modules.
ncl.xml: Kate
Kate NCL mode screenshot
The editor enhancement for Kate
was contributed by Raul Valenzuela, a graduate student in the
Atmospheric and Oceanic Sciences Program at the University of
Colorado. It highlights NCL keywords, functions, contributed
functions, gsn_code functions, gsn_csm_functions, comments, strings,
and metadata markers (@, !, &).
The file should be put in the directory
/usr/share/kde4/apps/katepart/syntax.