[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to make a new mode based on c++-mode
From: |
Helfer Thomas |
Subject: |
How to make a new mode based on c++-mode |
Date: |
Fri, 01 Dec 2006 18:11:09 +0100 |
Hello,
I have created a parser which translates a file into C++ source code.
The initial file has a syntax very close to C++ with some additional
keywords.
I would like to provide an emacs mode for editing those files.
For the moment I have written this :
----------------------------------------------------------------------
;;; -*-emacs-lisp-*-
;;; castfront.el --- ELisp package for making castfront related stuff
easier.
(provide 'castfront)
(defconst castfront-keywords
(list
(list
"\\(@\\(Coef\\)\\)\\>"
'(0 font-lock-warning-face prepend))
))
(defun castfront-font-lock ()
"Turn on font-lock for CastFront keywords."
(interactive)
(if (functionp 'font-lock-add-keywords)
(font-lock-add-keywords nil castfront-keywords)
(let ((old (if (eq (car-safe font-lock-keywords) t)
(cdr font-lock-keywords)
font-lock-keywords)))
(setq font-lock-keywords (append old castfront-keywords)))))
------------------------------------------------------------------------
I have then added the following line to my .emacs :
(defun my-castfront-font-lock-hook ()
(if (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
(castfront-font-lock)))
(add-hook 'font-lock-mode-hook 'my-castfront-font-lock-hook)
This work pretty good. The only thing to do is to open my parsed file
with c++-mode. However I want more. I want them to have their own mode,
a mode that will automatically load the c++-mode to handle c++-construct
a that will add my keywords as above. How can I make it ?
Thank for help
Sincerely,
Helfer Thomas
- How to make a new mode based on c++-mode,
Helfer Thomas <=