Text Editor Support
Interfaces are available for the three most popular editors in the open source community: Vim, Emacs, and OpenOffice. These interfaces are distributed with the Perl module in the share/ directory, but if you prefer you can download them here:
- gramadoir.el. Emacs Lisp Interface (screenshot).
- gramadoir.vim. Plug-in for Vim (screenshot).
- gramadoir.sxw. OpenOffice macro (screenshot).
Installation and usage instructions follow.
Martin Gregory has kindly contributed an Emacs interface to An Gramadóir which is very easy to use. Here are his instructions:
"The Emacs interface to An Gramadóir allows you to run An Gramadóir from within an Emacs session and navigate to the locations in the input files where An Gramadóir found problems. The interface is similar to that of the compile or grep commands in Emacs.
INSTALLING THE INTERFACE:
Put gramadoir.el in your emacs site lisp directory, often something like:
/usr/share/emacs/site-lisp/gramadoirIf you don't have one, put it it ~/lisp or some other directory of your choice and put the following line in your ~/.emacs file
(load-file "/where/you/put/gramadoir.el")If you are an experienced Emacs user, you'll probably want to auto load the file.
USING THE INTERFACE:
The interface allows you to specify files in two different ways:
- using the command gramadoir-check-files which prompts for a space separated list of files, without file completion;
- from a dired window using the gramadoir-dired command. This behaves like other dired commands: either all selected files are processed or, if no file is selected, the file listed on the current line is processed.
After running one of the above commands, the output of An Gramadóir is written to a new buffer which is displayed in a separate window. Using the gramadoir-next-message command positions the cursor at the location of the first error in the first file. Subsequent use of this command takes you to the locations of subsequent errors. If you reposition the cursor in the output buffer, the command takes you to the location of the next error after that position.
For convenience, you can bind the three commands to keys. These need to be global definitions, for example:
(global-set-key "\C-cg" 'gramadoir-check-files) (global-set-key "\C-cd" 'gramadoir-dired) (global-set-key [f3] 'gramadoir-next-message)
If you installed An Gramadóir anywhere other than in /usr/bin
you need to tell the interface where to look for it by putting a line
similar to the following:
(setq gramadoir-program-path "/usr/bin/gram-xx.pl")in your ~/.emacs, substituting the appropriate path for "/usr/bin" and language code for "xx".
Finally, the interface highlights the error text both in the output
buffer and in the buffer of the original file. If you prefer not to
highlight the text in the original file, add this:
(setq gramadoir-highlight-text nil)to your ~/.emacs."
I've written a script which emulates the behavior of Martin's Emacs interface within Vim. You can download it from the link at the top of this page, or you can get it directly from Vim online. Instructions:
- put gramadoir.vim in ~/.vim/plugin. For languages other than Irish, you'll need to change the "gram-ga.pl" around line 30 to the appropriate script name.
- put the following lines in your ~/.vimrc file
map <F3> <Plug>Gr map <F4> <Plug>Neamh map <F5> <Plug>Amachor choose different hot keys if you want.
- open the text file to be checked in Vim.
- to check its grammar, press F3; a second buffer, containing the messages from An Gramadóir, will open at the bottom of the screen. The cursor will move to the first error (which is also highlighted in red if you are using a suitable color terminal).
- Each successive use of F3 moves to the next error (in both windows, in parallel).
- If the current error is a single word (unknown, misspelled, rare,
non-standard, etc.), you can insert it into your
.neamhshuim(ignore) file by pressing F4.
- Pressing F5 exits the grammar checker and resumes normal editing.
- Notes: you are free to make edits, corrections, etc. to the main buffer while running the grammar checker. The last error displayed is tracked according to the cursor position in the error buffer, so whenever you press F3 it will correctly take you to the next error. This also means that you can jump to any particular error you'd like: go into the error buffer (with Crtl-w-w), move the cursor to just before the desired error, press F3.
The file gramadoir.sxw is an OpenOffice document that contains an embedded macro allowing An Gramadóir to be called directly from an OpenOffice session. See Russ Phillips' Macro Library How-To for more detailed installation instructions.
- Open gramadoir.sxw in OpenOffice.
- Go to Tools and select Macros, then Macro....
- The "Macro" dialog will appear. Double click "Gramadoir" and then single click the "Gramadoir" underneath.
- Now click the Edit button, which will open up the macro source code. The first line points to the file groo-ga.bat; change the "ga" to your ISO-639 language code (if you don't speak Irish), and change the file extension "bat" to "pl" if you're not running Windows. This file will need to be in your path.
- Save your changes and close the source code window, which should take you back to the original file. Now reopen the "Macro" dialog as in step 2; this time click on the Organizer button.
- The "Macro Organizer" dialog will appear. Click on the Libraries tab at the top left.
- Be sure "soffice" appears under "Application/Document", then click Append.
- Choose gramadoir.sxw using the file selection dialog that opens.
- Make sure only "Gramadoir" is checked in the "Append Libraries" dialog; you may need to uncheck "Standard". Then click OK.
- Close the Macro Organizer and then close the Macro dialog.
You should now have the macro installed and ready to use from any OpenOffice session. You can associate a hot key or a toolbar item with the macro via the Tools->Configure dialog.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.