unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to make a new mode based on c++-mode
@ 2006-12-01 21:15 Helfer Thomas
  0 siblings, 0 replies; 4+ messages in thread
From: Helfer Thomas @ 2006-12-01 21:15 UTC (permalink / raw)


following awk.el i have tried the following :

;;; -*-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))
   ))

;;;###autoload
(define-derived-mode castfront-mode c++-mode "CASTFRONT"
  "Major mode for editing castfront code."
  (setq font-lock-defaults '(castfront-keywords)))

This make @Coef to be highlighted by not standard c++-keywords. What I
am doing wrong ?

Sincerly,

Helfer Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <mailman.1412.1165007734.2155.help-gnu-emacs@gnu.org>]
[parent not found: <mailman.1403.1164993075.2155.help-gnu-emacs@gnu.org>]
* How to make a new mode based on c++-mode
@ 2006-12-01 17:11 Helfer Thomas
  0 siblings, 0 replies; 4+ messages in thread
From: Helfer Thomas @ 2006-12-01 17:11 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-12-04 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-01 21:15 How to make a new mode based on c++-mode Helfer Thomas
     [not found] <mailman.1412.1165007734.2155.help-gnu-emacs@gnu.org>
2006-12-04 16:10 ` Robert Thorpe
     [not found] <mailman.1403.1164993075.2155.help-gnu-emacs@gnu.org>
2006-12-01 17:32 ` Robert Thorpe
  -- strict thread matches above, loose matches on Subject: below --
2006-12-01 17:11 Helfer Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).