From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Spencer Baugh <sbaugh@catern.com>
Cc: emacs-devel@gnu.org
Subject: Re: Deriving from cc-mode with define-derived-mode
Date: Mon, 07 Sep 2015 11:16:55 -0400 [thread overview]
Message-ID: <jwv1teamfdo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87k2s3fgdm.fsf@earth.catern.com> (Spencer Baugh's message of "Sun, 06 Sep 2015 16:21:41 -0400")
> 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
prev parent reply other threads:[~2015-09-07 15:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-06 20:21 Deriving from cc-mode with define-derived-mode Spencer Baugh
2015-09-07 15:16 ` Stefan Monnier [this message]
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=jwv1teamfdo.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=sbaugh@catern.com \
/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.
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).