unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Helfer Thomas <helferthomas@free.fr>
Subject: How to make a new mode based on c++-mode
Date: Fri, 01 Dec 2006 18:11:09 +0100	[thread overview]
Message-ID: <1164993069.13163.10.camel@portableAsus> (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

             reply	other threads:[~2006-12-01 17:11 UTC|newest]

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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1164993069.13163.10.camel@portableAsus \
    --to=helferthomas@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).