From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Deriving from cc-mode with define-derived-mode Date: Mon, 07 Sep 2015 11:16:55 -0400 Message-ID: References: <87k2s3fgdm.fsf@earth.catern.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1441639063 6852 80.91.229.3 (7 Sep 2015 15:17:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Sep 2015 15:17:43 +0000 (UTC) Cc: emacs-devel@gnu.org To: Spencer Baugh Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 07 17:17:34 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZYyAn-0006dN-V1 for ged-emacs-devel@m.gmane.org; Mon, 07 Sep 2015 17:17:34 +0200 Original-Received: from localhost ([::1]:57268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYyAn-0003Og-Lk for ged-emacs-devel@m.gmane.org; Mon, 07 Sep 2015 11:17:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYyAM-0003AS-JI for emacs-devel@gnu.org; Mon, 07 Sep 2015 11:17:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZYyAH-0000Vq-Fb for emacs-devel@gnu.org; Mon, 07 Sep 2015 11:17:06 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:14192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYyAH-0000VH-CE for emacs-devel@gnu.org; Mon, 07 Sep 2015 11:17:01 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A+FgA731xV/5Wg+M5cgxCEAoVVwwsEAgKBPD0QAQEBAQEBAYEKQQWDXQEBAwFWIwULCw4mEhQYDSSINwjPIwEBAQcBAQEBHos6hDMBAVAHhC0BBItEp3uBRSOBZoIuIoE9gTsBAQE X-IPAS-Result: A0A+FgA731xV/5Wg+M5cgxCEAoVVwwsEAgKBPD0QAQEBAQEBAYEKQQWDXQEBAwFWIwULCw4mEhQYDSSINwjPIwEBAQcBAQEBHos6hDMBAVAHhC0BBItEp3uBRSOBZoIuIoE9gTsBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="162790238" Original-Received: from 206-248-160-149.dsl.teksavvy.com (HELO fmsmemgm.homelinux.net) ([206.248.160.149]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Sep 2015 11:17:00 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 1E03FAE11E; Mon, 7 Sep 2015 11:16:55 -0400 (EDT) In-Reply-To: <87k2s3fgdm.fsf@earth.catern.com> (Spencer Baugh's message of "Sun, 06 Sep 2015 16:21:41 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:189668 Archived-At: > 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