Title: Creating an Ox-major mode in Emacs. Author: Michael Höhle Date: 18 December 2000 Category: Quick (and Dirty) Hacks. An easy way to get highlighting and indentation of Ox files in Emacs 20.5 is to use C++-mode. The biggest prohibiting problem (in my eyes) is the use of "'" in Ox to invert matrices. This totally messes up hi-lighting etc. What needs to be done is to change the meaning of ?\' in the syntax-table when working with Ox files. A quick (and dirty?) way to achieve this is to add an ox-mode into the cc-mode files which more or less steal everything from the c++ mode - except the syntax-table. Hi-lighting for the Ox specific keywords is obtained by adding support for the ox-mode to font-lock.el. To achieve the above solution, proceed as follows. Make a backup of the files $EMACS/lisp/progmodes/cc-langs.el and $EMACS/lisp/progmodes/cc-mode.el $EMACS/lisp/font-lock.el After this security announcement proceed by adding the following to $EMACS/lisp/progmodes/cc-langs.el just before the line "(provide 'cc-langs)". ; ; Support for Ox ; ; (added by Michael Höhle , 18 December 2000) ;;;###autoload (defvar ox-mode-syntax-table nil "Syntax table used in ox-mode buffers.") (if ox-mode-syntax-table () (setq ox-mode-syntax-table (make-syntax-table)) (c-populate-syntax-table ox-mode-syntax-table) ; Unfortunately in Ox \' means transposing a matrix ; If nothing done hi-lights are not proper, so we change its meaning to word (modify-syntax-entry ?\' "w" ox-mode-syntax-table) ) In $EMACS/lisp/progmodes/cc-mode.el just before the line ";; bug reporting" add ;;;###autoload (defun ox-mode () "Major mode for editing Ox code. Added to CC-mode by Michael Höhle , 18 December 2000 To see what version of CC Mode you are running, enter `\\[c-version]'. The hook variable `ox-mode-hook' is run with no args, if that variable is bound and has a non-nil value. Also the hook `c-mode-common-hook' is run first. Key bindings: \\{c++-mode-map}" (interactive) (c-initialize-cc-mode) (kill-all-local-variables) ; This is the only change - we use an ox-mode-syntax-table to ; correct for ' problem. (set-syntax-table ox-mode-syntax-table) (setq major-mode 'ox-mode mode-name "Ox" local-abbrev-table c++-mode-abbrev-table) (use-local-map c++-mode-map) (c-common-init) (setq comment-start "// " comment-end "" c-conditional-key c-C++-conditional-key c-comment-start-regexp c-C++-comment-start-regexp c-class-key c-C++-class-key c-extra-toplevel-key c-C++-extra-toplevel-key c-access-key c-C++-access-key c-recognize-knr-p nil imenu-generic-expression cc-imenu-c++-generic-expression imenu-case-fold-search nil ) (run-hooks 'c-mode-common-hook) ; Better run the ox-hooks instead of c++-mode-hook (run-hooks 'ox-mode-hook) (c-update-modeline)) This is quick and dirty and reuses most of the c++-part. Only thing left is to make font-lock.el aware of the ox-mode and have it hi-light ox specific keywords. Replace font-lock.el file with the one found at http://www.dina.kvl.dk/~hoehle/software/ox/font-lock.el. To make everything work it is necessary to byte-compile the three edited files (cc-mode.el, cc-lang.el, font-lock.el), e.g. with Esc-x byte-compile-file. Now all there is left is to edit your ~/.emacs file to auto-load ox-mode on files with the ".ox" extension. (require 'cc-mode) ; necessary to put it here in order to get extra modes. (setq auto-mode-alist (append '(("\\.ox$" . ox-mode) ) auto-mode-alist)) If you want to be able to run Ox within Emacs you might consider adding the following to your .emacs file. It makes C-c o execute the current buffer (requires oxl to be in your current path). [Suggested by Riccardo `Jack' Lucchetti ] (defun ox-compile () "Try and compile an ox file" (interactive ()) (save-buffer) (shell-command (concat "oxl " (buffer-file-name) ) nil nil )) (setq ox-mode-map nil) (add-hook 'ox-mode-hook '(lambda () (local-set-key "\C-co" 'ox-compile) )) Restart emacs and enjoy (with the usual disclaimer: use is at own risk)!