Vim Ada Mode

Here is the latest vim Ada syntax mode (November 2, 2001).

First, some background: Vim is a neat text editor intentionally similar to the venerable vi. It includes ``syntax highlighting'' - it can color text you're editing for a variety of languages. Ada is a computer language emphasizing compile-time detection of errors.

I maintain the vim Ada mode. If you're using vim and Ada, here's the latest version of this mode; I believe this will eventually get into the official vim sources, but if you you're using Ada and vim, you might want it now. In particular, I'd like feedback before this mode is shipped with a new version of vim (my email address is in the header of the mode file).

Here's a screenshot using the latest (November 2001) version of the vim Ada mode (thanks to Preben Randhol for the screenshot):
Picture of new setup

The vim Ada mode version (November 2001) changed the April 2001 version by making the normal "end" match the normal "begin", and "end record" has the same highlighting as the beginning "record". My thanks to Preben Randhol for this improvement.

Here are some of the advantages of the vim Ada mode version (April 2001) over its predecessor (which was shipped in vim 5.7):

  1. Based numbers are highlighted correctly (e.g., 16#FFFF#).
  2. Operators (+, *, etc.) are colored as operators.
  3. The +/- operators are colored differently than numeric signs (-5). So, the "-" in "A-5" is colored as an operator, while the same character in "A:=-5" is colored as a number.
  4. Conditionals and repeats are grouped differently. Thus, you can specially color all loop keywords (if you did this, "for", "loop", and "end loop" would be colored differently than "if" and "end if").
  5. The "with" and "use" clauses, when used to reference other compilation units, are colored differently (like "#include" in C).
  6. Keywords aren't incorrectly colored as "preprocessor" colors, unless you turn that on as an option.
  7. Standard exception names are highlighted as such.
  8. Types in package Standard can be optionally highlighted.
  9. Certain erroneous notation (e.g., "//") is immediately highlighted.
  10. Various other options are available, e.g., for highlighting bad spaces.
  11. Unlike the March 2001 version, if you're using vim 6.0, this version won't highlight leading spaces in certain cases involving "with" and "use" (avoiding this required advanced pattern-matching features not available in vim before version 6.0).

This vim Ada mode works on both vim version 5.7 (deployed version), 6.0z (development version), and 6.0 (final); I've tested it on all three.

So, please download and enjoy:

Click here to download ada.vim

To use it, just replace your current Ada mode with this new version. For vim 5.7 on Red Hat Linux 7, this file is located at /usr/share/vim/vim57/syntax/ada.vim. On some systems, change "/usr/share" to "/usr/local/share"; for vim 6.0z, change "vim57" to "vim60z". Then just run "vim" or "gvim" and edit an Ada file. If you've turned off syntax highlighting, you can turn it back on with the command ":syntax on".

Here are the "help" instructions that I will propose with this mode when it's officially incorporated into vim:

Ada

This mode is designed for the 1995 edition of Ada ("Ada95"), which
includes support for objected-programming, protected types, and so on.
It handles code written for the original Ada language
("Ada83" or "Ada87") as well, though Ada83 code which uses Ada95-only
keywords will be wrongly colored (such code should be fixed anyway).
For more information about Ada, see http://www.adapower.com.

The Ada mode handles a number of situations cleanly.
For example, it knows that the "-" in "-5" is a number, but the same
character in "A-5" is an operator.  Normally, a "with" or "use" clause
referencing another compilation unit is colored the same way as C's
"#include" is colored.  If you have "Conditional" or "Repeat"
groups colored differently, then "end if" and "end loop" will be
colored as part of those respective groups.
You can set these to different colors using vim's "highlight" command
(e.g., to change how loops are displayed, enter the command
":hi Repeat" followed by the color specification; on simple terminals
the color specification ctermfg=White often shows well).

There are several options you can select in this Ada mode.
To enable them, assign a value to the option.  For example, to turn one on:
   let ada_standard_types = 1
To disable them use ":unlet".  Example:
   unlet ada_standard_types = 1
You can just use ":" and type these into the command line to set these
temporarily before loading an Ada file.  You can make these option settings
permanent by adding the "let" command(s), without a colon,
to your "~/.vimrc" file.

Here are the Ada mode options:

Variable                 Action
ada_standard_types       Highlight types in package Standard (e.g., "Float")
ada_space_errors         Highlight extraneous errors in spaces...
ada_no_trail_space_error   but ignore trailing spaces at the end of a line 
ada_no_tab_space_error     but ignore tabs after spaces
ada_withuse_ordinary     Show "with" and "use" as ordinary keywords
                           (when used to reference other compilation units
                           they're normally highlighted specially).
ada_begin_preproc        Show all begin-like keywords using the coloring
                           of C preprocessor commands.

Even on a slow (90Mhz) PC this mode works quickly, but if you find
the performance unnacceptable, turn on ada_withuse_ordinary.

Vim includes an Ada indenting system as well, but that's maintained by Neil Bird.

I've already sent this patch to Bram. I've also sent the help text, along with a patch so that ".ada" files are recognized as Ada (it already recognized .adb and .ads as Ada). For the last point, you just modify /usr/local/share/vim/vim60/filetype.vim; here's the patch if you want to do it yourself:

--- filetype.vim.orig	Sun Feb 24 09:04:00 2002
+++ filetype.vim	Sun Feb 24 09:04:16 2002
@@ -68,7 +68,7 @@
 au BufNewFile,BufRead *.wrm			setf acedb
 
 " Ada (83, 9X, 95)
-au BufNewFile,BufRead *.adb,*.ads		setf ada
+au BufNewFile,BufRead *.adb,*.ads,*.ada		setf ada
 
 " AHDL
 au BufNewFile,BufRead *.tdf			setf ahdl

If you're looking for an Ada compiler, check out GNAT; some sources include the Ada-Belgium mirrors and the GNU Ada home page.

If you want to see my website, go to my home page at http://www.dwheeler.com.