Project

General

Profile

Syntax highlighting for emacs

Emacs should automatically highlight C++ files, makefiles etc. for you (you may need to activate global-font-lock-mode). But it needs to be taught about FHCIL files.

There is a more official project here: https://github.com/knoepfel/art-fhicl the below is the legacy NOvA attempt, kept for historical interest.

Copy and paste this onto the end of your .emacs file to get syntax highlighting of files with a .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                                        
   ("process_name:\\|services:\\|source:\\|outputs:\\|physics:\\|producers:\\|filters:\\|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 are welcome to attempt to fix the first three.

Other emacs features

  • for mac users with iterm2
  • If you wanna to scroll down your code in -nw mode on iterm2, add these line in .emacs
  • this is specially for mac users
    ;; mouse integration
    (require 'mouse) ;; needed for iterm2 compatibility
    (xterm-mouse-mode t)
    (global-set-key [mouse-4] '(lambda ()
                               (interactive)
                               (scroll-down 1)))
    (global-set-key [mouse-5] '(lambda ()
                               (interactive)
                               (scroll-up 1)))
    (setq mouse-sel-mode t)
    (defun track-mouse (e))