Project

General

Profile

Syntax highlighting for emacs » History » Version 18

Christopher Backhouse, 12/11/2017 05:49 AM
Link to official fcl synatax highlighter

1 1 Christopher Backhouse
h1. Syntax highlighting for emacs
2 1 Christopher Backhouse
3 4 Christopher Backhouse
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.
4 4 Christopher Backhouse
5 18 Christopher Backhouse
There is a more official project here: https://github.com/knoepfel/art-fhicl the below is the legacy NOvA attempt, kept for historical interest.
6 18 Christopher Backhouse
7 5 Christopher Backhouse
Copy and paste this onto the end of your .emacs file to get syntax highlighting of files with a .fcl extension.
8 1 Christopher Backhouse
9 2 Christopher Backhouse
<pre>
10 1 Christopher Backhouse
(setq fclKeywords
11 1 Christopher Backhouse
 '(
12 2 Christopher Backhouse
   ;; Unfortunately, the comment syntax takes precedence, so this doesn't work  
13 1 Christopher Backhouse
   ("#include" . font-lock-keyword-face)
14 1 Christopher Backhouse
   ("@local" . font-lock-keyword-face)
15 2 Christopher Backhouse
   ;; All these names are magic, I think                                        
16 5 Christopher Backhouse
   ("process_name:\\|services:\\|source:\\|outputs:\\|physics:\\|producers:\\|filters:\\|analyzers:||\trigger_paths:||\end-paths:" . font-lock-builtin-face)
17 1 Christopher Backhouse
   ("true\\|false" . font-lock-builtin-face)
18 1 Christopher Backhouse
   ;; Variable definitions are followed by colons                               
19 1 Christopher Backhouse
   ("[a-zA-Z0-9_]*:" . font-lock-variable-name-face)
20 1 Christopher Backhouse
  )
21 1 Christopher Backhouse
)
22 1 Christopher Backhouse
23 1 Christopher Backhouse
;; Python mode gets us comment handling and indentation at colons               
24 1 Christopher Backhouse
(define-derived-mode fcl-mode python-mode
25 1 Christopher Backhouse
  (setq mode-name "FHICL")
26 1 Christopher Backhouse
  (setq font-lock-defaults '(fclKeywords))
27 1 Christopher Backhouse
;;  (setq tab-width 2) ;; Doesn't seem to work                                  
28 1 Christopher Backhouse
)
29 1 Christopher Backhouse
30 1 Christopher Backhouse
(add-to-list 'auto-mode-alist '("\\.fcl\\'" . fcl-mode))
31 2 Christopher Backhouse
</pre>
32 2 Christopher Backhouse
33 2 Christopher Backhouse
h2. Known bugs 
34 2 Christopher Backhouse
35 2 Christopher Backhouse
* The comment syntax takes precedence, so #include gets incorrectly coloured as a comment
36 2 Christopher Backhouse
* The mode defaults to 4-space tabs, 2 seems to be our standard
37 2 Christopher Backhouse
* The mode thinks that blocks start at : not :{ , so the auto-indenting is a little off (but better than nothing).
38 2 Christopher Backhouse
* This doesn't help vi users
39 2 Christopher Backhouse
40 3 Christopher Backhouse
Emacs/lisp experts are welcome to attempt to fix the first three.
41 8 Kuldeep Maan
42 14 Kuldeep Maan
h3. Other emacs features
43 11 Kuldeep Maan
44 16 Kuldeep Maan
* for mac users with iterm2
45 17 Kuldeep Maan
* If you wanna to scroll down your code in -nw mode on iterm2, add these line in .emacs
46 15 Kuldeep Maan
* this is specially for mac users
47 8 Kuldeep Maan
<pre>
48 6 Kuldeep Maan
;; mouse integration
49 6 Kuldeep Maan
(require 'mouse) ;; needed for iterm2 compatibility
50 6 Kuldeep Maan
(xterm-mouse-mode t)
51 6 Kuldeep Maan
(global-set-key [mouse-4] '(lambda ()
52 6 Kuldeep Maan
                           (interactive)
53 6 Kuldeep Maan
                           (scroll-down 1)))
54 6 Kuldeep Maan
(global-set-key [mouse-5] '(lambda ()
55 6 Kuldeep Maan
                           (interactive)
56 6 Kuldeep Maan
                           (scroll-up 1)))
57 6 Kuldeep Maan
(setq mouse-sel-mode t)
58 1 Christopher Backhouse
(defun track-mouse (e))
59 7 Kuldeep Maan
</pre>