Skip to content

Editing LEMS and NeuroML2 files with Emacs and nXML mode

Eugenio Piasini edited this page Jun 27, 2013 · 5 revisions

nXML-mode is helpful when editing xml files, as it performs real-time validation, context-sensitive completion and various other clever tricks. It's the default mode for xml editing since emacs 23. Unfortunately, it's designed to work with RELAX NG, while the LEMS and NeuroML2 schemas are expressed as a W3C XML Schema, so out of the box it will only offer basic xml editing facilities. To work around this issue, an unofficial port of the NeuroML and LEMS schemas to rng and rnc formats is provided at https://github.com/epiasini/LEMS_NeuroML_RelaxNG.

Once you have downloaded the rnc files, it might be useful to add something like

(global-set-key [C-return] 'completion-at-point)
(setq rng-schema-locating-files '("~/.emacs.d/schemas.xml" "schemas.xml" "/usr/share/emacs/24.3/etc/schema/schemas.xml"))

to your .emacs file to enable autocompletion with C-return (rather than the somewhat inconvenient default M-C-i) and to store all schema associations in a central file under your .emacs.d directory. See the nXML-mode documentation for a detailed explanation on how to configure the associations in the schemas.xml file, or just adapt from the example below:

<?xml version="1.0"?>
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
  <namespace ns="http://www.neuroml.org/lems/0.7" uri="/path/to/LEMS_NeuroML_RelaxNG/LEMS_v0.7.rnc"/>
  <namespace ns="http://www.neuroml.org/schema/neuroml2" uri="/path/to/LEMS_NeuroML_RelaxNG/NeuroML_v2beta.rnc"/>
</locatingRules>

Finally, remember that you can always use C-c C-s C-f to manually associate a schema to the current buffer or file.


See also

Clone this wiki locally