Syntax highlighting for emacs » History » Version 2

« Previous - Version 2/18 (diff) - Next » - Current version
Christopher Backhouse, 04/28/2011 12:41 PM
Pretty up, put some words in

Syntax highlighting for emacs

Copy and paste this onto the end of your <tt>.emacs</tt> file, for syntax highlighting of files with .fcl extension.

(setq fclKeywords
   ;; Unfortunately, the comment syntax takes precedence, so this doesn't work  
   ("#include" . font-lock-keyword-face)
   ("@local" . font-lock-keyword-face)
   ;; All these names are magic, I think                                        
ilters:\\|analyzers:||\trigger_paths:||\end-paths:" . font-lock-builtin-face)
   ("true\\|false" . font-lock-builtin-face)
   ;; Variable definitions are followed by colons                               
   ("[a-zA-Z0-9_]*:" . font-lock-variable-name-face)

;; Python mode gets us comment handling and indentation at colons               
(define-derived-mode fcl-mode python-mode
  (setq mode-name "FHICL")
  (setq font-lock-defaults '(fclKeywords))
;;  (setq tab-width 2) ;; Doesn't seem to work                                  

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

Known bugs

  • The comment syntax takes precedence, so #include gets incorrectly coloured as a comment
  • The mode defaults to 4-space tabs, 2 seems to be our standard
  • The mode thinks that blocks start at : not :{ , so the auto-indenting is a little off (but better than nothing).
  • This doesn't help vi users

Emacs/lisp experts welcome to attempt to fix the first three.