Using refdb-mode with NTEmacs

Windows is an extra challenge for refdb-mode, as we have to call Cygwin programs (which use Unix-style paths) from a Win32 application (which uses Win32-style paths) by running a Cygwin shell (which needs a different environment than the one it inherits from NTEmacs) through Lisp commands, leaving enough room for things to go wrong. It boils down to getting your .emacs right, and we'll show here step by step what it takes to see the light. You'll notice that the setup uses UTF-8 quite heavily, assuming that you've set up your RefDB databases accordingly. I've settled for this encoding as it gave me the simplest consistent setup possible. You may well experiment with other character encodings, but I hardly see any benefit in doing so.

Note

Some of the administrative functions currently do not work under NTEmacs. Affected are all functions which run sudo for authentication or which start an xterm to obtain database passwords.

Note

Path names need a little extra care on Windows. Save yourself a great deal of pain by adding all Win32 executables that you want to call (mainly viewers for RTF, PDF, and Postscript files) to your Windows PATH. In your /usr/local/etc/refdb-mode-config.el file, use the command names instead of the full paths of the viewing programs. Viewing HTML files is handled by browse-url which should be set up to use an external browser like Firefox. The Emacs w3 browser does not seem to grok the paths assembled by refdb-mode.

;; use Unix-style line endings
(setq-default buffer-file-coding-system 'undecided-unix)

;; xml files as well as files with "utf8" somewhere
;; in the path are opened as Unicode
(setq file-coding-system-alist
      (append (list
	       (cons "\\.xml$" 'utf-8)
	       (cons "utf8" 'utf-8))
	      file-coding-system-alist))
      

First we ask NTEmacs to use Unix-style line endings. The second expression makes sure that all XML files as well as all files with the string "utf8" in their name (e.g. refdata-utf8.ris) are loaded as Unicode files using the UTF-8 character encoding.

;; use bash as the default shell
(setq exec-path (cons "C:/Programme/cygwin/bin" exec-path))
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
(setenv "PATH" (concat (getenv "PATH") ";C:\\Programme\\cygwin\\bin" ";C:\\Programme\\cygwin\\usr\\local\\bin"))
(setq explicit-shell-file-name shell-file-name)
(setq explicit-shell-args '("--login" "-i"))
(setq shell-command-switch "-ic")
(setq w32-quote-process-args t)
(defun bash ()
  (interactive)
  (let ((binary-process-input t)
        (binary-process-output nil))
    (shell)))

(setq process-coding-system-alist (cons '("bash" . (utf-8-dos . utf-8-unix))
                    process-coding-system-alist))
      

This block of commands uses the Cygwin version of bash as the default shell. It also makes sure that a few additional directories are added to the path. Finally it tells NTEmacs that the data returned by the shell use the UTF-8 encoding as well. The paths shown here need to be adapted to your local installation.

Note

If you want to process SGML files, you'll have to set SGML_CATALOG_FILES once in your .bashrc using Unix-style paths (bash, when called from NTEmacs, doesn't seem to evaluate /etc/profile) to make the catalogs available to OpenJade et al., and once in your system (the usual clicking odyssey in the control panel) using the Win32 paths. PSGML will use the latter when running under NTEmacs.

;; refdb-mode and ris mode
(load-file "c:/Programme/emacsen/site-lisp/refdb-mode-config.el")
(setq refdb-default-ris-encoding 'utf-8-unix)
      

Now we load refdb-mode and ris-mode through the config file. Again, use the path of your local system here. The second command makes sure we use UTF-8 again to display results in RIS format.

;; nxml mode
(load "c:/Programme/emacsen/site-lisp/nxml-mode-20041004/rng-auto.el")
(setq auto-mode-alist
      (cons '("\\.\\(xml\\|xsl\\|rng\\|xhtml\\)\\'" . nxml-mode)
	    auto-mode-alist))
      

Finally, we also load nxml-mode to edit XML files. The setup of PSGML to edit SGML-files has been described elsewhere (slightly outdated, though).

The final step to make nxml-mode work properly is to make the RefDB RelaxNG schemas known to the system. To this end, create or edit the file schemas.xml in your home directory. The contents for the RefDB schemas looks like this:

<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
  <documentElement prefix="" localName="ris" typeId="RISX"/>
  <documentElement prefix="" localName="STYLESET" typeId="CiteStyleX"/>
  <documentElement prefix="" localName="xnoteset" typeId="XNote"/>

  <typeId id="RISX" uri="/Programme/cygwin/usr/local/share/refdb/dtd/risx.rnc"/>
  <typeId id="CiteStyleX" uri="/Programme/cygwin/usr/local/share/refdb/dtd/citestylex.rnc"/>
  <typeId id="XNote" uri="/Programme/cygwin/usr/local/share/refdb/dtd/xnote.rnc"/>
</locatingRules>
      

You may have to run the command M-xcustomize-variableRETrng-schema-locating-filesRET and add the path of your schemas.xml to the existing list of schema files. Do not use a drive letter but start the path with a slash, like in the file itself.