wiki:EditorUtils/EmacsHighlight

Version 1 (modified by Nicolas Pouillon, 17 years ago) (diff)

Add in soclib highlight elisp script

Introduction

In caba writing rules are some naming conventions for signals, ports and registers. If you follow those rules, you may want to have those datatypes highlighted automagically by your favorite editor. Here is an emacs file for such a purpose.

Usage

Put this file in soclib.el, then edit your ~/.emacs and add a line:

(load "/path/to/soclib.el")

soclib.el

(defun soclib-make-face (face colour &optional bold)
  "Create a face from a colour and optionally make it bold"
  (make-face face)
  (copy-face 'default face)
  (set-face-foreground face colour)
  (if bold (make-face-bold face))
  )

(soclib-make-face 'soclib-font-method "DarkSalmon" t)
(soclib-make-face 'soclib-font-member "DarkSeaGreen" t)
(soclib-make-face 'soclib-font-register "MediumSpringGreen" t)
(soclib-make-face 'soclib-font-port "DarkTurquoise" t)
(soclib-make-face 'soclib-font-namespace "DarkOrange")

(setq c++-font-lock-extra-types
          (append (list
           "[A-Z][A-Za-z0-9]+" "sc_[a-z_]+")
           c++-font-lock-extra-types))

(font-lock-add-keywords
 'c++-mode
 '(("\\<\\([a-z_]+[A-Z][A-Za-z0-9_]*\\)\\>" . 'soclib-font-method)
   ("\\<\\(m_[a-z_]+\\)\\>" . 'soclib-font-member)
   ("\\<\\(r_[a-z_]+\\)\\>" . 'soclib-font-register)
   ("\\<\\(p_[a-z_]+\\)\\>" . 'soclib-font-port)
   ("\\<\\([a-z_]+\\)::" . 'soclib-font-namespace)
;   ("\\([a-z_][A-Z][A-Za-z0-9_]*\\)" . 'soclib-font-method)
   ("std::\\([a-z]+\\)\\>" . font-lock-type-face)
   ))