📄 c++-mode.el
字号:
;;; c++-mode.el --- major mode for editing C++ (and C) code;; Author: 1992 Barry A. Warsaw, Century Computing Inc. <baw@cen.com>;; 1987 Dave Detlefs and Stewart Clamen;; 1985 Richard M. Stallman;; Maintainer: c++-mode-help@anthem.nlm.nih.gov;; Created: a long, long, time ago. adapted from the original c-mode.el;; Version: Revision: 2.195;; Last Modified: Date: 1992/08/28 22:07:39;; Keywords: C++ C editing major-mode;; Copyright (C) 1992 Free Software Foundation, Inc.;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING. If not, write to;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.;; Introduction;; ============;; Do a "C-h m" in a c++-mode buffer for more information on;; customizing c++-mode. To submit bug reports hit "C-c C-b" in a;; c++-mode buffer. This runs the command c++-submit-bug-report and;; automatically sets up the mail buffer with all the necessary;; information. If you have other questions contact me at the;; following address: c++-mode-help@anthem.nlm.nih.gov. Please don't;; send bug reports to my personal account, I may not get it for a;; long time.;; Important Note about Escapes in Comments, and Performance;; =========================================================;; You will notice that certain characters, when typed in comment;; regions, get escaped with a backslash. This is a workaround for an;; emacs bug. In brief, GNU emacs 18 and its derivatives cannot;; handle more than 1 comment style per mode, and as you know, C++;; supports 2 orthogonal comment styles. Thus emacs' syntax parsing;; code will sometimes choke on unbalanced parentheses and single;; quotes in comments. Please do a "C-h v c++-untame-characters" for;; more information. Note further that workarounds for this bug;; require that some buffer parsing be performed in elisp where it;; would normally be more efficient to do via the C primitives. I've;; chosen accuracy over performance but have worked hard to give;; acceptable performance in all but the most uncommon situations. You;; will most likely notice c++-mode becoming slow when you're editing;; a file of preprocessor commands, where the file contains few if any;; function definitions. None of this can be changed until emacs;; itself is fixed.;; Notes for Novice Users;; ======================;; c++-mode facilitates editing of C++ code by automatically handling;; the indentation of lines of code in a manner very similar to c-mode;; as distributed with GNU emacs. Refer to the GNU Emacs manual,;; chapter 21 for more information on "Editing Programs". In fact,;; c++-mode can also be used to edit C code!;;;; To use c++-mode you need to do two things: get this file loaded;; into your emacs sessions at the right time; and tell emacs what;; type of files are C++ files. To do the former, make sure that;; c++-mode.el{c} is on your load-path, and add the following lines to;; your .emacs file:;; (autoload 'c++-mode "c++-mode" "C++ Editing Mode" t);; (autoload 'c++-c-mode "c++-mode" "C Editing Mode" t);; ;; To do the latter, set up your auto-mode-alist file to recognize C++;; file extensions. For example, if you use .C and .cc as C++ source;; code files, add this to your .emacs file:;; (setq auto-mode-alist;; (append '(("\\.C$" . c++-mode);; ("\\.cc$" . c++-mode));; auto-mode-alist));;;; This retains the original value of auto-mode-alist. Finally, you;; may want to customize certain c++-mode variables. The best place;; to do this is in the mode hook variable called c++-mode-hook.;; Again, see the Emacs manual, chapter 21 for more information.;;;; If you want to use c++-mode to edit C code, use the entry point;; c++-c-mode. Change the above setq in your .emacs file with:;;;; (setq auto-mode-alist;; (append '(("\\.c$" . c++-c-mode) ; use c++-mode to edit C code;; ("\\.h$" . c++-c-mode) ; instead of built-in c-mode;; ("\\.C$" . c++-mode);; ("\\.cc$" . c++-mode));; auto-mode-alist));; Beta Testers Mailing List;; =========================;; Want to be a c++-mode victim, er, beta-tester? Send add/drop;; requests to c++-mode-victims-request@anthem.nlm.nih.gov.;; Discussions go to c++-mode-victims@anthem.nlm.nih.gov, but bug;; reports and such should still be sent to c++-mode-help only.;; Getting c++-mode.el;; ===================;; The latest public release version of this file should always be;; available for anon-ftp on ftp.cme.nist.gov:pub/gnu/c++-mode.el. It;; will also most likely be available on the elisp archive machine:;; archive.cis.ohio-state.edu. Look around.;; ;; For those of you without aftp access, try sending a message to the;; mail-server at library@cme.nist.gov. Put this message in the body;; of your email: "send pub/gnu/c++-mode.el" (without the quotes) to;; get the file in uuencoded format, or send the message "help" to get;; more information about using the mail-server. Please don't email;; me asking for the latest version, I may not have it readily;; available to send to you. The mail-server should get it to you;; pretty quickly. Remember that if you want advanced access to beta;; releases, get on the victims list -- but be forewarned, you should;; be elisp and C++ fluent, and should have anon-ftp access.;; LCD Archive Entry;; =================;; c++-mode|Barry A. Warsaw|c++-mode-help@anthem.nlm.nih.gov;; |Mode for editing C++ code (was Detlefs' c++-mode.el);; | Date: 1992/08/28 22:07:39 Revision: 2.195 |;;; Code:;; ======================================================================;; user definable variables;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv(defvar c++-mode-abbrev-table nil "Abbrev table in use in C++-mode buffers.")(define-abbrev-table 'c++-mode-abbrev-table ())(defvar c++-mode-map () "Keymap used in C++ mode.")(if c++-mode-map () (setq c++-mode-map (make-sparse-keymap)) (define-key c++-mode-map "\C-j" 'reindent-then-newline-and-indent) (define-key c++-mode-map "{" 'c++-electric-brace) (define-key c++-mode-map "}" 'c++-electric-brace) (define-key c++-mode-map ";" 'c++-electric-semi) (define-key c++-mode-map "#" 'c++-electric-pound) (define-key c++-mode-map "\e\C-h" 'mark-c-function) (define-key c++-mode-map "\e\C-q" 'c++-indent-exp) (define-key c++-mode-map "\t" 'c++-indent-command) (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header) (define-key c++-mode-map "\C-c\C-\\" 'c++-macroize-region) (define-key c++-mode-map "\C-c\C-c" 'c++-comment-region) (define-key c++-mode-map "\C-c\C-u" 'c++-uncomment-region) (define-key c++-mode-map "\C-c\C-x" 'c++-match-paren) (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun) (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun) (define-key c++-mode-map "\e\C-x" 'c++-indent-defun) (define-key c++-mode-map "/" 'c++-electric-slash) (define-key c++-mode-map "*" 'c++-electric-star) (define-key c++-mode-map ":" 'c++-electric-colon) (define-key c++-mode-map "\177" 'c++-electric-delete) (define-key c++-mode-map "\C-c\C-t" 'c++-toggle-auto-hungry-state) (define-key c++-mode-map "\C-c\C-h" 'c++-toggle-hungry-state) (define-key c++-mode-map "\C-c\C-a" 'c++-toggle-auto-state) (define-key c++-mode-map "\C-c'" 'c++-tame-comments) (define-key c++-mode-map "'" 'c++-tame-insert) (define-key c++-mode-map "[" 'c++-tame-insert) (define-key c++-mode-map "]" 'c++-tame-insert) (define-key c++-mode-map "(" 'c++-tame-insert) (define-key c++-mode-map ")" 'c++-tame-insert) (define-key c++-mode-map "\C-c\C-b" 'c++-submit-bug-report) (define-key c++-mode-map "\C-c\C-v" 'c++-version) )(defvar c++-mode-syntax-table nil "Syntax table used in c++-mode buffers.")(defvar c++-c-mode-syntax-table nil "Syntax table used in c++-c-mode buffers.")(if c++-mode-syntax-table () (setq c++-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\\ "\\" c++-mode-syntax-table) (modify-syntax-entry ?/ ". 124" c++-mode-syntax-table) (modify-syntax-entry ?* ". 23b" c++-mode-syntax-table) (modify-syntax-entry ?+ "." c++-mode-syntax-table) (modify-syntax-entry ?- "." c++-mode-syntax-table) (modify-syntax-entry ?= "." c++-mode-syntax-table) (modify-syntax-entry ?% "." c++-mode-syntax-table) (modify-syntax-entry ?< "." c++-mode-syntax-table) (modify-syntax-entry ?> "." c++-mode-syntax-table) (modify-syntax-entry ?& "." c++-mode-syntax-table) (modify-syntax-entry ?| "." c++-mode-syntax-table) (modify-syntax-entry ?\' "\"" c++-mode-syntax-table) (modify-syntax-entry ?\n ">" c++-mode-syntax-table) )(if c++-c-mode-syntax-table () (setq c++-c-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\\ "\\" c++-c-mode-syntax-table) (modify-syntax-entry ?/ ". 14" c++-c-mode-syntax-table) (modify-syntax-entry ?* ". 23" c++-c-mode-syntax-table) (modify-syntax-entry ?+ "." c++-c-mode-syntax-table) (modify-syntax-entry ?- "." c++-c-mode-syntax-table) (modify-syntax-entry ?= "." c++-c-mode-syntax-table) (modify-syntax-entry ?% "." c++-c-mode-syntax-table) (modify-syntax-entry ?< "." c++-c-mode-syntax-table) (modify-syntax-entry ?> "." c++-c-mode-syntax-table) (modify-syntax-entry ?& "." c++-c-mode-syntax-table) (modify-syntax-entry ?| "." c++-c-mode-syntax-table) (modify-syntax-entry ?\' "\"" c++-c-mode-syntax-table) )(defvar c++-tab-always-indent (if (boundp 'c-tab-always-indent) c-tab-always-indent t) "*Controls the operation of the TAB key.If t (the default), always just indent the current line. If nil,indent the current line only if point is at the left margin or in theline's indentation; otherwise insert a tab. If not-nil-or-t, then tabis inserted only within literals (comments and strings) and insidepreprocessor directives, but line is always reindented.")(defvar c++-always-arglist-indent-p nil "*Control indentation of continued arglists.When non-nil, arglists continued on subsequent lines will alwaysindent c++-empty-arglist-indent spaces, otherwise, they will indent tojust under previous line's argument indentation.")(defvar c++-class-member-indent c-indent-level "*Extra indentation given to each member of a class, relative to theenclosing class's indentation. Note that if you change c-indent-levelin your c++-mode-hook, you will probably want to set this variable tothe same value.")(defvar c++-block-close-brace-offset 0 "*Extra indentation given to close braces which close a block. Thisdoes not affect braces which close a top-level construct (e.g. function).")(defvar c++-paren-as-block-close-p nil "*Treat a parenthesis which is the first non-whitespace on a line asa paren which closes a block. When non-nil, c-indent-level issubtracted, and c++-block-close-brace-offset is added to the line'soffset.")(defvar c++-continued-member-init-offset nil "*Extra indent for continuation lines of member inits; NIL means to alignwith previous initializations rather than with the colon on the first line.")(defvar c++-member-init-indent 0 "*Indentation level of member initializations in function declarations.")(defvar c++-friend-offset -4 "*Offset of C++ friend class declarations relative to member declarations.")(defvar c++-access-specifier-offset c-label-offset "*Extra indentation given to public, protected, and private labels.")(defvar c++-empty-arglist-indent nil "*Indicates how far to indent an line following an empty argumentlist. Nil indicates to just after the paren.")(defvar c++-comment-only-line-offset 0 "*Indentation offset for line which contains only C or C++ style comments.")(defvar c++-C-block-comments-indent-p nil "*4 styles of C block comments are supported. If this variable is nil,then styles 1-3 are supported. If this variable is non-nil, style 4 issupported.style 1: style 2: style 3: style 4:/* /* /* /* blah * blah ** blah blah blah * blah ** blah blah */ */ */ */")(defvar c++-cleanup-list nil "*List of various C++ constructs to \"clean up\".These cleanups only take place when auto-newline minor mode is on.Current legal values are: brace-else-brace -- clean up \"} else {\" constructs by placing entire construct on a single line. This cleanup only takes place when there is nothing but white space between the braces and the else. empty-defun-braces -- cleans up empty C++ function braces by placing them on the same line. defun-close-semi -- cleans up the terminating semi-colon on class definitions and functions by placing the semi on the same line as the closing brace.")(defvar c++-hanging-braces t "*Controls the insertion of newlines before open (left) braces.This variable only has effect when auto-newline is on. If nil, openbraces do not hang (i.e. a newline is inserted before all openbraces). If t, all open braces hang -- no newline is inserted beforeopen braces. If not nil or t, newlines are only inserted beforetop-level open braces; all other braces hang.")(defvar c++-hanging-member-init-colon 'before "*Defines how colons which introduce member initializations are formatted.Legal values are: t -- no newlines inserted before or after colon nil -- newlines inserted before and after colon 'after -- newlines inserted only after colon 'before -- newlines inserted only before colon")(defvar c++-auto-hungry-initial-state 'none "*Initial state of auto/hungry mode when buffer is first visited.Legal values are: 'none -- no auto-newline and no hungry-delete-key. 'auto-only -- auto-newline, but no hungry-delete-key. 'hungry-only -- no auto-newline, but hungry-delete-key. 'auto-hungry -- both auto-newline and hungry-delete-key enabled.Nil is synonymous for 'none and t is synonymous for 'auto-hungry.")(defvar c++-auto-hungry-toggle t "*Enable/disable toggling of auto/hungry states.Legal values are: 'none -- auto-newline and hungry-delete-key cannot be enabled. 'auto-only -- only auto-newline state can be toggled. 'hungry-only -- only hungry-delete-key state can be toggled. 'auto-hungry -- both auto-newline and hungry-delete-key can be toggled.Nil is synonymous for 'none and t is synonymous for 'auto-hungry.")(defvar c++-mailer 'mail "*Mail package to use to generate bug report mail buffer.")(defconst c++-mode-help-address "c++-mode-help@anthem.nlm.nih.gov" "Address accepting submission of bug reports.")(defvar c++-relative-offset-p t "*Control the calculation for indentation.When non-nil (the default), indentation is calculated relative to thefirst statement in the block. When nil, the indentation is calculatedwithout regard to how the first statement is indented.")(defvar c++-untame-characters '(?\') "*Utilize a backslashing workaround of an emacs syntax parsing bug.If non-nil, this variable should contain a list of characters whichwill be prepended by a backslash in comment regions. By default, the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -