all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

* Re: How to make a new mode based on c++-mode
       [not found] <mailman.1403.1164993075.2155.help-gnu-emacs@gnu.org>
@ 2006-12-01 17:32 ` Robert Thorpe
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Thorpe @ 2006-12-01 17:32 UTC (permalink / raw)


Helfer Thomas wrote:
> 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 :

Read awk-mode.el in the GNU Emacs distribution.  Awk is a pattern
matching language very similar to C in syntax.  Emacs supports it by
defining a derived mode from C mode, it manages to do it in ~100 lines
of elisp.

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

* 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

* Re: How to make a new mode based on c++-mode
       [not found] <mailman.1412.1165007734.2155.help-gnu-emacs@gnu.org>
@ 2006-12-04 16:10 ` Robert Thorpe
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Thorpe @ 2006-12-04 16:10 UTC (permalink / raw)


Helfer Thomas wrote:
> 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 ?

What you have written probably works.  However your new mode is not in
font-lock-global-modes so turning on global-font-lock mode doesn't turn
it on.  The common solution is to add a hook to turn font-lock on for
your new mode in .emacs for example.

This applies whether or not you're using a derived mode.

^ 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 --
     [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
     [not found] <mailman.1412.1165007734.2155.help-gnu-emacs@gnu.org>
2006-12-04 16:10 ` Robert Thorpe
2006-12-01 21:15 Helfer Thomas
  -- strict thread matches above, loose matches on Subject: below --
2006-12-01 17:11 Helfer Thomas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.