From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: bug-cc-mode@gnu.org
Cc: emacs-devel@gnu.org
Subject: Reify the cc-mode-common into an actual parent mode
Date: Mon, 23 May 2016 20:41:56 -0400 [thread overview]
Message-ID: <jwvwpmk5lxb.fsf-monnier+emacs@gnu.org> (raw)
IIRC last conversation, while you disagreed with introducing
a c-derivative-mode (for objc/c++/c), you said you were OK with the idea
of introducing a cc-mode-common.
Here's a corresponding patch.
Any objection?
Stefan
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index de903b8..bbb96f2 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -238,6 +238,8 @@ control). See \"cc-mode.el\" for more info."
;; incompatible
(t (error "CC Mode is incompatible with this version of Emacs")))
map))
+(make-obsolete 'c-make-inherited-keymap
+ "Use make-sparse-keymap + (set-keymap-parent c-mode-base-map); or derive from c-mode-common" "26.1")
(defun c-define-abbrev-table (name defs &optional doc)
;; Compatibility wrapper for `define-abbrev' which passes a non-nil
@@ -861,6 +863,7 @@ Note that the style variables are always made local to the buffer."
(if (cc-bytecomp-fboundp 'run-mode-hooks)
`(run-mode-hooks ,@hooks)
`(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
+(make-obsolete 'c-run-mode-hooks "derive your mode from c-common-mode" "26.1")
\f
;;; Change hooks, linking with Font Lock and electric-indent-mode.
@@ -1431,6 +1434,17 @@ This function is called from `c-common-init', once per mode initialization."
(c-update-modeline)))
\f
+(defvar c-mode-common-map c-mode-base-map)
+
+(define-derived-mode c-mode-common prog-mode "CC-common"
+ "Pseudo major mode, parent of all modes using the CC engine."
+ ;; We want to update the mode-line but *after* the major mode's hooks
+ ;; have been run.
+ :after-hook (c-update-modeline)
+ (c-initialize-cc-mode t)
+ (setq abbrev-mode t) ;; Used for c-electric-continued-statement!
+ )
+
;; Support for C
(defvar c-mode-syntax-table
@@ -1443,7 +1457,7 @@ This function is called from `c-common-init', once per mode initialization."
"Abbreviation table used in c-mode buffers.")
(defvar c-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for C.
(define-key map "\C-c\C-e" 'c-macro-expand)
map)
@@ -1484,7 +1498,7 @@ This function is called from `c-common-init', once per mode initialization."
(unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
;;;###autoload
-(define-derived-mode c-mode prog-mode "C"
+(define-derived-mode c-mode c-mode-common "C"
"Major mode for editing C code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
@@ -1500,15 +1514,11 @@ initialization, then `c-mode-hook'.
Key bindings:
\\{c-mode-map}"
:after-hook (progn (c-make-noise-macro-regexps)
- (c-make-macro-with-semi-re)
- (c-update-modeline))
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
+ (c-make-macro-with-semi-re))
(c-init-language-vars-for 'c-mode)
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
- (cc-imenu-init cc-imenu-c-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook))
+ (cc-imenu-init cc-imenu-c-generic-expression))
\f
;; Support for C++
@@ -1524,7 +1534,7 @@ Key bindings:
"Abbreviation table used in c++-mode buffers.")
(defvar c++-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for C++.
(define-key map "\C-c\C-e" 'c-macro-expand)
(define-key map "\C-c:" 'c-scope-operator)
@@ -1537,7 +1547,7 @@ Key bindings:
(cons "C++" (c-lang-const c-mode-menu c++)))
;;;###autoload
-(define-derived-mode c++-mode prog-mode "C++"
+(define-derived-mode c++-mode c-mode-common "C++"
"Major mode for editing 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
@@ -1553,15 +1563,11 @@ initialization, then `c++-mode-hook'.
Key bindings:
\\{c++-mode-map}"
:after-hook (progn (c-make-noise-macro-regexps)
- (c-make-macro-with-semi-re)
- (c-update-modeline))
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
+ (c-make-macro-with-semi-re))
(c-init-language-vars-for 'c++-mode)
(c-common-init 'c++-mode)
(easy-menu-add c-c++-menu)
- (cc-imenu-init cc-imenu-c++-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook))
+ (cc-imenu-init cc-imenu-c++-generic-expression))
\f
;; Support for Objective-C
@@ -1576,7 +1582,7 @@ Key bindings:
"Abbreviation table used in objc-mode buffers.")
(defvar objc-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for Objective-C.
(define-key map "\C-c\C-e" 'c-macro-expand)
map)
@@ -1588,7 +1594,7 @@ Key bindings:
;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
;;;###autoload
-(define-derived-mode objc-mode prog-mode "ObjC"
+(define-derived-mode objc-mode c-mode-common "ObjC"
"Major mode for editing Objective C code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
objc-mode buffer. This automatically sets up a mail buffer with
@@ -1604,15 +1610,11 @@ initialization, then `objc-mode-hook'.
Key bindings:
\\{objc-mode-map}"
:after-hook (progn (c-make-noise-macro-regexps)
- (c-make-macro-with-semi-re)
- (c-update-modeline))
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
+ (c-make-macro-with-semi-re))
(c-init-language-vars-for 'objc-mode)
(c-common-init 'objc-mode)
(easy-menu-add c-objc-menu)
- (cc-imenu-init nil 'cc-imenu-objc-function)
- (c-run-mode-hooks 'c-mode-common-hook))
+ (cc-imenu-init nil 'cc-imenu-objc-function))
\f
;; Support for Java
@@ -1629,7 +1631,7 @@ Key bindings:
"Abbreviation table used in java-mode buffers.")
(defvar java-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for Java.
map)
"Keymap used in java-mode buffers.")
@@ -1647,7 +1649,7 @@ Key bindings:
;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
;;;###autoload
-(define-derived-mode java-mode prog-mode "Java"
+(define-derived-mode java-mode c-mode-common "Java"
"Major mode for editing Java code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
java-mode buffer. This automatically sets up a mail buffer with
@@ -1662,14 +1664,10 @@ initialization, then `java-mode-hook'.
Key bindings:
\\{java-mode-map}"
- :after-hook (c-update-modeline)
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
(c-init-language-vars-for 'java-mode)
(c-common-init 'java-mode)
(easy-menu-add c-java-menu)
- (cc-imenu-init cc-imenu-java-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook))
+ (cc-imenu-init cc-imenu-java-generic-expression))
\f
;; Support for CORBA's IDL language
@@ -1682,7 +1680,7 @@ Key bindings:
"Abbreviation table used in idl-mode buffers.")
(defvar idl-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for IDL.
map)
"Keymap used in idl-mode buffers.")
@@ -1693,7 +1691,7 @@ Key bindings:
;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
;;;###autoload
-(define-derived-mode idl-mode prog-mode "IDL"
+(define-derived-mode idl-mode c-mode-common "IDL"
"Major mode for editing CORBA's IDL, PSDL and CIDL code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
idl-mode buffer. This automatically sets up a mail buffer with
@@ -1708,13 +1706,13 @@ initialization, then `idl-mode-hook'.
Key bindings:
\\{idl-mode-map}"
- :after-hook (c-update-modeline)
- (c-initialize-cc-mode t)
+ ;; No c-electric-continued-statement here, so we don't need abbrev-mode.
+ (kill-local-variable 'abbrev-mode)
(c-init-language-vars-for 'idl-mode)
(c-common-init 'idl-mode)
(easy-menu-add c-idl-menu)
;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
- (c-run-mode-hooks 'c-mode-common-hook))
+ )
\f
;; Support for Pike
@@ -1729,7 +1727,7 @@ Key bindings:
"Abbreviation table used in pike-mode buffers.")
(defvar pike-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Additional bindings.
(define-key map "\C-c\C-e" 'c-macro-expand)
map)
@@ -1742,7 +1740,7 @@ Key bindings:
;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
;;;###autoload
-(define-derived-mode pike-mode prog-mode "Pike"
+(define-derived-mode pike-mode c-mode-common "Pike"
"Major mode for editing Pike code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
pike-mode buffer. This automatically sets up a mail buffer with
@@ -1757,14 +1755,11 @@ initialization, then `pike-mode-hook'.
Key bindings:
\\{pike-mode-map}"
- :after-hook (c-update-modeline)
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
(c-init-language-vars-for 'pike-mode)
(c-common-init 'pike-mode)
(easy-menu-add c-pike-menu)
;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
- (c-run-mode-hooks 'c-mode-common-hook))
+ )
\f
;; Support for AWK
@@ -1781,7 +1776,7 @@ Key bindings:
"Abbreviation table used in awk-mode buffers.")
(defvar awk-mode-map
- (let ((map (c-make-inherited-keymap)))
+ (let ((map (make-sparse-keymap)))
;; Add bindings which are only useful for awk.
(define-key map "#" 'self-insert-command);Overrides electric parent binding.
(define-key map "/" 'self-insert-command);Overrides electric parent binding.
@@ -1804,7 +1799,7 @@ Key bindings:
(declare-function c-awk-unstick-NL-prop "cc-awk" ())
;;;###autoload
-(define-derived-mode awk-mode prog-mode "AWK"
+(define-derived-mode awk-mode c-mode-common "AWK"
"Major mode for editing AWK code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
awk-mode buffer. This automatically sets up a mail buffer with version
@@ -1818,18 +1813,14 @@ initialization, then `awk-mode-hook'.
Key bindings:
\\{awk-mode-map}"
- :after-hook (c-update-modeline)
;; We need the next line to stop the macro defining
;; `awk-mode-syntax-table'. This would mask the real table which is
;; declared in cc-awk.el and hasn't yet been loaded.
:syntax-table nil
(require 'cc-awk) ; Added 2003/6/10.
- (c-initialize-cc-mode t)
- (setq abbrev-mode t)
(c-init-language-vars-for 'awk-mode)
(c-common-init 'awk-mode)
- (c-awk-unstick-NL-prop)
- (c-run-mode-hooks 'c-mode-common-hook))
+ (c-awk-unstick-NL-prop))
\f
;; bug reporting
next reply other threads:[~2016-05-24 0:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-24 0:41 Stefan Monnier [this message]
2016-05-28 11:30 ` Reify the cc-mode-common into an actual parent mode Alan Mackenzie
2016-05-28 17:51 ` Stefan Monnier
2016-05-29 9:45 ` Alan Mackenzie
2016-05-29 14:53 ` Stefan Monnier
2016-05-28 18:08 ` Stefan Monnier
2016-05-29 10:00 ` Alan Mackenzie
2016-05-30 17:37 ` Stefan Monnier
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvwpmk5lxb.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=bug-cc-mode@gnu.org \
--cc=emacs-devel@gnu.org \
/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 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.