Project

General

Profile

Syntax highlighting for emacs » History » Version 12

Kuldeep Maan, 09/27/2014 06:24 PM

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