* Deriving from cc-mode with define-derived-mode
@ 2015-09-06 20:21 Spencer Baugh
2015-09-07 15:16 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Spencer Baugh @ 2015-09-06 20:21 UTC (permalink / raw)
To: emacs-devel
Hi emacs-devel,
I'm trying to write a mode for a C variant, C0. C0 is a pedagogical
language described in more depth here: http://c0.typesafety.net/. The
mode is called c0-mode.
More precisely, I'm trying to update our already existing mode. The
existing mode seems to be heavily inspired by
http://cc-mode.sourceforge.net/derived-mode-ex.el and awk-mode. In the
course of adding some new features I would like to replace some of the
old idioms and boilerplate with newer approaches.(C0 has a REPL, so one
of the new features I want to add is REPL interaction; I would also
appreciate recommendations on how to approach that.)
Just like in derivde-mode-ex.el, currently c0-mode is defined with
(defun c0-mode () ...)
But I would rather use define-derived-mode, and anyway that example
seems very out of date. Is there some documentation about how to write a
mode deriving from cc-mode in a modern way? Or at least some examples of
modes deriving from cc-mode that use define-derived-mode? Or any other
advice you can offer me?
Thanks,
Spencer Baugh
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Deriving from cc-mode with define-derived-mode
2015-09-06 20:21 Deriving from cc-mode with define-derived-mode Spencer Baugh
@ 2015-09-07 15:16 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2015-09-07 15:16 UTC (permalink / raw)
To: Spencer Baugh; +Cc: emacs-devel
> mode deriving from cc-mode in a modern way? Or at least some examples of
> modes deriving from cc-mode that use define-derived-mode? Or any other
FWIW, you could define for example c-mode in the following way:
(defvar c-mode-syntax-table
(funcall (c-lang-const c-make-mode-syntax-table c))
"Syntax table used in c-mode buffers.")
(c-define-abbrev-table 'c-mode-abbrev-table
'(("else" "else" c-electric-continued-statement 0)
("while" "while" c-electric-continued-statement 0))
"Abbreviation table used in c-mode buffers.")
(defvar c-mode-map
(let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for C.
map)
"Keymap used in c-mode buffers.")
(define-derived-mode c-mode c-derivative-mode "C"
"Major mode for editing K&R and ANSI C code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
c-mode buffer. This automatically sets up a mail buffer with version
information already added. You just need to add a description of the
problem, including a reproducible test case, and send the message.
To see what version of CC Mode you are running, enter `\\[c-version]'.
The hook `c-mode-common-hook' is run with no args at mode
initialization, then `c-mode-hook'.
Key bindings:
\\{c-mode-map}"
(c-init-language-vars-for 'c-mode)
(c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
(cc-imenu-init cc-imenu-c-generic-expression))
where c-derivative-mode would be defined as
(define-derived-mode c-mode-common prog-mode "CC-generic"
"Pseudo major mode, parent of all modes using the CC engine."
(c-initialize-cc-mode t)
(setq abbrev-mode t) ;FIXME: Why?
;; FIXME: Alan doesn't like this because there's no guarantee
;; mode-line-process is close to the major mode name.
(set (make-local-variable 'mode-line-process) c-submode-indicators))
(defvar c-derivative-mode-map
;; FIXME: We can't have the menu on this keymap, because the menus for C,
;; C++, and ObjC can't be shared: the only difference between them is their
;; title, but easy-menu offers no way to compute the title dynamically.
(let ((map (make-sparse-keymap)))
;; Add bindings which are useful for any C derivative.
(define-key map "\C-c\C-e" 'c-macro-expand)
map)
"Keymap used in c-derivative-mode buffers.")
(define-derived-mode c-derivative-mode c-mode-common "C-derivative"
"Pseudo major mode, parent of all modes for C derivatives.
A C derivative is a language which is a superset of C (or is
C itself).")
-- Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-07 15:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-06 20:21 Deriving from cc-mode with define-derived-mode Spencer Baugh
2015-09-07 15:16 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).