Difference between revisions of "Emacs"

From Apertium
Jump to navigation Jump to search
Line 18: Line 18:
; Start of nxml-mode setup
; Start of nxml-mode setup
(load "~/.elisp/nxml-mode-20041004/rng-auto.el") ; path to the _file_ you extracted
(load "~/.elisp/nxml-mode-20041004/rng-auto.el") ; path to the _file_ you extracted

; Start of dix-mode setup
; Start of dix-mode setup

(add-to-list 'load-path "~/.elisp") ; path to the folder where you have dix.el
(add-to-list 'load-path "~/.elisp") ; path to the folder where you have dix.el
(autoload 'dix-mode "dix"
(autoload 'dix-mode "dix"
Line 34: Line 34:
(transient-mark-mode 1) ;; No region when it is not highlighted
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

</pre>
</pre>



Revision as of 10:57, 7 April 2010

Emacs stuff:

Quickstart for non-emacs users

If you just want to get it set up for dix editing with the minimum of hassle, here is a howto. Assming you have emacs installed, first execute (paste) the following commands in your terminal:


mkdir ~/.elisp
cd ~/.elisp
wget http://www.thaiopensource.com/download/nxml-mode-20041004.tar.gz
tar xzvf nxml-mode-20041004.tar.gz
rm -f nxml-mode-20041004.tar.gz
wget http://apertium.svn.sourceforge.net/viewvc/apertium/trunk/apertium-tools/dix.el
cd ..
touch ~/.emacs

Then open the file ~/.emacs in an editor (like vi) and enter the following:

 ; Start of nxml-mode setup
(load "~/.elisp/nxml-mode-20041004/rng-auto.el") ; path to the _file_ you extracted

 ; Start of dix-mode setup
(add-to-list 'load-path "~/.elisp") ; path to the folder where you have dix.el
(autoload 'dix-mode "dix" 
   "dix-mode is a minor mode for editing Apertium XML dictionary files."  t)
(add-hook 'nxml-mode-hook
 	  (lambda () (and buffer-file-name
 			  (string-match "\\.dix$" buffer-file-name)
 			  (dix-mode 1))))
(add-to-list 'auto-mode-alist '("\\.dix\\'" . nxml-mode))

 ; Start of CUA mode setup - to make Emacs behave like other editors - see http://www.emacswiki.org/CuaMode
(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour


On Debian/Ubuntu

sudo apt-get install nxml-mode
mkdir ~/.elisp
cd ~/.elisp
wget http://apertium.svn.sourceforge.net/viewvc/apertium/trunk/apertium-tools/dix.el
cd ..
touch ~/.emacs

Then open the file ~/.emacs in an editor (like vi) and enter the following:

(add-to-list 'load-path "~/.elisp") ; path to the folder where you have dix.el
(autoload 'dix-mode "dix" 
   "dix-mode is a minor mode for editing Apertium XML dictionary files."  t)
(add-hook 'nxml-mode-hook
 	  (lambda () (and buffer-file-name
 			  (string-match "\\.dix$" buffer-file-name)
 			  (dix-mode 1))))
(add-to-list 'auto-mode-alist '("\\.dix\\'" . nxml-mode))

(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

nxml-mode

Emacs has a nice xml editing mode called nXML, with syntax highlighting, movement commands to navigate through the XML (out of, into, across elements, etc.). It also has validation, and can auto-complete using the XML schema if a schema file is available.

Note: since the dix-files can often get rather huge, syntax highlighting can make nXML a bit slow (at least if you're eg. planning on running a keyboard macro 10000 times). To speed it up, just temporarily turn off syntax highlighting with by typing M-x set-variable RET nxml-syntax-highlight-flag RET nil RET. Alternatively, use the dix.el function C-c H (dix-toggle-syntax-highlighting).

If your emacs doesn't turn on nxml-mode automatically when you open an xml-file, you can add the following line to your ~/.emacs file:

(add-to-list 'auto-mode-alist '("\\.dix\\'" . nxml-mode))

If your emacs doesn't even come with nxml-mode, download nxml-mode-20030901.tar.gz (or whatever the newest version is) from http://www.thaiopensource.com/download/, extract somewhere, and add the following to your .emacs file:

  (load "/path/to/nxml-mode-20030901/rng-auto.el") ; full path to the _file_ rng-auto.el which you just extracted

dix-mode

Screenshot of dix.el in Aquamacs (fullscreen). Upper left window has output from dix-view-pardef, lower left shows rng schema completion. There is a red underline since a p can't be an empty element, as noted by the message in the minibuffer

In svn there is a minor mode for editing .dix files, dix.el (or use svn co https://apertium.svn.sourceforge.net/svnroot/apertium/trunk/apertium-tools). It needs nxml-mode (see above).

Put the following in your ~/.emacs file to use it:

 (add-to-list 'load-path "/path/to/dix.el-folder") ; ie. path to the _folder_ containing dix.el
 (autoload 'dix-mode "dix" 
   "dix-mode is a minor mode for editing Apertium XML dictionary files."  t)
 (add-hook 'nxml-mode-hook
 	  (lambda () (and buffer-file-name
 			  (string-match "\\.dix$" buffer-file-name)
 			  (dix-mode 1))))

I use Apertium-dixtools-formatted dix, not all functions have been tested in the regular format.

Note: there's now a menu-bar, if you forget the keyboard shortcuts :-)

The minor mode adds keyboard shortcuts C-c L and C-c R which make LR or RL restricted copies of <e>'s (use C-TAB to cycle between restriction possibilities LR, RL or none, C-c C creates a copy without modifying restrictions), C-c G which finds the pardef of a dictionary entry (and lets you go back with C-u C-SPC) and C-c S which sorts a pardef by its right-hand-side <r>. M-n and M-p move to the next and previous "important bits" of <e>-elements (just try it!). Inside a pardef, C-c A shows all usages of that pardef within the dictionaries represented by the variable `dix-dixfiles', while C-c D gives you a list of all pardefs which use these suffixes (where a suffix is the contents of an <l>-element). The space bar inserts a <b/> in <r>, <l> or <i> elements (o/w a regular space).

Also, if you like having all <i> elements aligned at eg. column 25, the minor mode lets you do M-x align on a region to achieve that, and also aligns <p> to 10 and <r> to 44 (for bidix). These numbers are customizable with M-x customize-group RET dix. (Ie. there's no extra indentation function, but then nxml already has that.)

Validation (Relax NG-schemas)

nxml-mode uses compact Relax NG schemas for validation (without these, XML is only checked for well-formedness by nxml-mode).

(There is a non-compact dix.rng here, while transfer.rng and modes.rng are in trunk/apertium/apertium.)

You can make compact Relax NG schemas (.rnc) using trang. Use a script like this to keep all your rnc's up-to-date:

cd /path/to/trunk/apertium/apertium
for DTD in `ls *.dtd`; do
    OUT=`echo $DTD | sed 's/dtd$/rnc/'`;
    CMD="java -jar /path/to/trang.jar $DTD $OUT"
    echo $CMD
    eval $CMD
done

Note: if you want to auto-complete using the schema (keyboard shortcut: C-RET), you should have (add-to-list 'nxml-completion-hook 'rng-complete) somewhere in your ~/.emacs.

You can toggle validation using the XML menu at the top of the screen, or the keyboard shortcut C-c C-v.

See also