⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c++-mode.el

📁 早期freebsd实现
💻 EL
📖 第 1 页 / 共 5 页
字号:
list contains only the most troublesome character, the single quote.To be completely safe, set this variable to:    '(?\( ?\) ?\' ?\{ ?\} ?\[ ?\])This is the full list of characters which can potentially causeproblems if they exist unbalanced within comments. Setting thisvariable to nil will defeat this feature, but be forewarned!  Suchun-escaped characters in comment regions can potentially break manythings such as some indenting and blinking of parenthesis.Note further that only the default set of characters will be escapedautomatically as they are typed. But, executing c++-tame-comments(\\[c++-tame-comments]) will escape all characters which are membersof this set, and which are found in comments throughout the file.")(defvar c++-default-macroize-column 78  "*Column to insert backslashes.")(defvar c++-special-indent-hook nil  "*Hook for user defined special indentation adjustments.This hook gets called after each line to allow the user to do whateverspecial indentation adjustments are desired.  If you have non-standardindentation, you will likely need to have c++-relative-offset-p set tonil.")(defvar c++-delete-function 'backward-delete-char-untabify  "*Function called by c++-electric-delete when deleting a single char.")(defvar c++-electric-pound-behavior nil  "*List of behaviors for electric pound insertion.Only currently supported behavior is '(alignleft).");; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT;; (defvar c++-hungry-delete-key nil  "Internal state of hungry delete key.")(defvar c++-auto-newline nil  "Internal state of auto newline feature.")(make-variable-buffer-local 'c++-auto-newline)(make-variable-buffer-local 'c++-hungry-delete-key)(defconst c++-class-key "\\<\\(class\\|struct\\|union\\)\\>"  "Keywords which introduce a struct declaration in C++.")(defconst c++-access-key "\\<\\(public\\|protected\\|private\\)\\>:"  "Keywords which modify access protection.");; ======================================================================;; c++-mode main entry point;; ======================================================================(defun c++-mode ()  "Major mode for editing C++ code.  Revision: 2.195To submit a bug report, enter \"\\[c++-submit-bug-report]\"from a c++-mode buffer.1. Very much like editing C code.2. Expression and list commands understand all C++ brackets.3. Tab at left margin indents for C++ code4. Comments are delimited with /* ... */ {or with // ... <newline>}5. Paragraphs are separated by blank lines only.6. Delete converts tabs to spaces as it moves back.IMPORTANT NOTE: You will notice that some characters (by default, onlysingle quote) will get escaped with a backslash when typed in acomment region.  This is a necessary workaround of a bug present inGNU emacs 18 and derivatives.  Enter \"\\[describe-variable] c++-untame-characters RET\"for more information.Key bindings:\\{c++-mode-map}These variables control indentation style. Those with names likec-<thing> are inherited from c-mode.  Those with names likec++-<thing> are unique for this mode, or have extended functionalityfrom their c-mode cousins. c-indent-level    Indentation of C statements within surrounding block.    The surrounding block's indentation is the indentation    of the line on which the open-brace appears. c-continued-statement-offset    Extra indentation given to a substatement, such as the    then-clause of an if or body of a while. c-continued-brace-offset    Extra indentation given to a brace that starts a substatement.    This is in addition to c-continued-statement-offset. c-brace-offset    Extra indentation for line if it starts with an open brace. c-brace-imaginary-offset    An open brace following other text is treated as if it were    this far to the right of the start of its line. c-argdecl-indent    Indentation level of declarations of C function arguments. c-label-offset    Extra indentation for line that is a label, or case or ``default:'', or    ``public:'' or ``private:'', or ``protected:''. c++-tab-always-indent    Controls the operation of the TAB key.  t means always just    reindent the current line.  nil means indent the current line only    if point is at the left margin or in the line's indentation;    otherwise insert a tab.  If not-nil-or-t, then the line is first    reindented, then if the indentation hasn't changed, a tab is    inserted. This last mode is useful if you like to add tabs after    the # of preprocessor commands. Default is value for    c-tab-always-indent. c++-block-close-brace-offset    Extra indentation give to braces which close a block. This does    not affect braces which close top-level constructs (e.g. functions). c++-continued-member-init-offset    Extra indentation for continuation lines of member initializations; nil    means to align with previous initializations rather than with the colon. c++-member-init-indent    Indentation level of member initializations in function declarations,    if they are on a separate line beginning with a colon. c++-friend-offset    Offset of C++ friend class declarations relative to member declarations. c++-access-specifier-offset    Extra indentation given to public, protected, and private keyword lines. c++-empty-arglist-indent    If non-nil, a function declaration or invocation which ends a line with a    left paren is indented this many extra spaces, instead of flush with the    left paren. If nil, it lines up with the left paren. c++-always-arglist-indent-p    Control indentation of continued arglists. When non-nil, arglists    continued on subsequent lines will always indent    c++-empty-arglist-indent spaces, otherwise, they will indent to    just under previous line's argument indentation. c++-comment-only-line-offset    Extra indentation for a line containing only a C or C++ style comment. c++-cleanup-list    A list of construct \"clean ups\" which c++-mode will perform when    auto-newline mode is on.  Current legal values are:    brace-else-brace, empty-defun-braces, defun-close-semi. c++-hanging-braces    Controls open brace hanging behavior when using auto-newline. Nil    says no braces hang, t says all open braces hang. Not nil or t    means top-level open braces don't hang, all others do. c++-hanging-member-init-colon    Defines how colons which introduce member initialization lists are    formatted. t means no newlines are inserted either before or after    the colon. Nil means newlines are inserted both before and after    the colon.  'before inserts newlines only before the colon, and    'after inserts newlines only after colon. c++-auto-hungry-initial-state    Initial state of auto/hungry mode when a C++ buffer is first visited. c++-auto-hungry-toggle    Enable/disable toggling of auto/hungry states. c++-mailer    Mailer to use when sending bug reports. c++-mode-help-address    Address to send bug report via email. c++-relative-offset-p    Control the calculation for indentation. When non-nil (the    default), indentation is calculated relative to the first    statement in the block.  When nil, the indentation is calculated    without regard to how the first statement is indented.  c++-default-macroize-column    Column to insert backslashes when macroizing a region. c++-untame-characters    When non-nil, inserts backslash escapes before certain untamed    characters in comment regions. It is recommended that you keep the    default setting to workaround a nasty emacs bug.  Otherwise, this    variable contains a list of characters to escape. c++-delete-function    Function called by c++-electric-delete when deleting a single char. c++-electric-pound-behavior    List of behaviors for electric pound insertion.Auto-newlining is no longer an all or nothing proposition. To bespecific I don't believe it is possible to implement a perfectauto-newline algorithm. Sometimes you want it and sometimes you don't.So now auto-newline (and its companion, hungry-delete) can be toggledon and off on the fly.  Hungry-delete is the optional behavior of thedelete key. When hungry-delete is enabled, hitting the delete keyonce consumes all preceeding whitespace, unless point is within aliteral (defined as a C or C++ comment, or string).  Inside literals,and with hungry-delete disabled, the delete key just callsbackward-delete-char-untabify.Behavior is controlled by c++-auto-hungry-initial-state andc++-auto-hungry-toggle.  Legal values for both variables are:   'none (or nil)      -- no auto-newline or hungry-delete.   'auto-only          -- function affects only auto-newline state.   'hungry-only        -- function affects only hungry-delete state.   'auto-hungry (or t) -- function affects both states.Thus if c++-auto-hungry-initial-state is 'hungry-only, then onlyhungry state is turned on when the buffer is first visited.  Ifc++-auto-hungry-toggle is 'auto-hungry, and both auto-newline andhungry-delete state are on, then hitting \"\\[c++-toggle-auto-hungry-state]\"will toggle both states.  Hitting \"\\[c++-toggle-hungry-state]\" willalways toggle hungry-delete state and hitting \"\\[c++-toggle-auto-state]\"will always toggle auto-newline state, regardless of the value ofc++-auto-hungry-toggle.   Hungry-delete state, when on, makes thedelete key consume all preceding whitespace.Settings for K&R, BSD, and Stroustrup indentation styles are  c-indent-level                5    8    4  c-continued-statement-offset  5    8    4  c-continued-brace-offset                0  c-brace-offset               -5   -8    0  c-brace-imaginary-offset                0  c-argdecl-indent              0    8    4  c-label-offset               -5   -8   -4  c++-access-specifier-offset  -5   -8   -4  c++-empty-arglist-indent                4  c++-friend-offset                       0Turning on C++ mode calls the value of the variable c++-mode-hook withno args, if that value is non-nil.Report bugs by entering \"\\[c++-submit-bug-report]\". Thisautomatically sets up a mail buffer with version information alreadyadded. You just need to add a description of the problem and send themessage."  (interactive)  (kill-all-local-variables)  (use-local-map c++-mode-map)  (set-syntax-table c++-mode-syntax-table)  (setq major-mode 'c++-mode	mode-name "C++"	local-abbrev-table c++-mode-abbrev-table)  (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))  (set (make-local-variable 'paragraph-separate) paragraph-start)  (set (make-local-variable 'paragraph-ignore-fill-prefix) t)  (set (make-local-variable 'require-final-newline) t)  (set (make-local-variable 'parse-sexp-ignore-comments) nil)  ;;   (set (make-local-variable 'indent-line-function) 'c++-indent-line)  (set (make-local-variable 'comment-start) "// ")  (set (make-local-variable 'comment-end) "")  (set (make-local-variable 'comment-column) 32)  (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")  (set (make-local-variable 'comment-indent-hook) 'c++-comment-indent)  ;; hack auto-hungry designators into mode-line-format  (if (listp mode-line-format)      (setq mode-line-format	    (let ((modeline nil))	      (mapcar	       (function		(lambda (element)		  (setq modeline			(append modeline				(if (eq element 'mode-name)				    '(mode-name (c++-hungry-delete-key						 (c++-auto-newline "/ah" "/h")						 (c++-auto-newline "/a")))				  (list element))))))	       mode-line-format)	      modeline)))  (run-hooks 'c++-mode-hook)  (c++-set-auto-hungry-state   (memq c++-auto-hungry-initial-state '(auto-only   auto-hungry t))   (memq c++-auto-hungry-initial-state '(hungry-only auto-hungry t))))(defun c++-c-mode ()  "Major mode for editing C code based on c++-mode. Revision: 2.195Documentation for this mode is available by doing a\"\\[describe-function] c++-mode\"."  (interactive)  (c++-mode)  (setq major-mode 'c++-c-mode	mode-name "C")  (setq comment-start "/* "	comment-end   " */")  ;; some syntax differences are necessary for C vs. C++  (set-syntax-table c++-c-mode-syntax-table)  (run-hooks 'c++-c-mode-hook))(defun c++-comment-indent ()  "Used by indent-for-comment to decide how much to indent a commentin C++ code based on its context."  (if (looking-at "^\\(/\\*\\|//\\)")      0					; Existing comment at bol stays there.    (save-excursion      (skip-chars-backward " \t")      (max       ;; leave at least one space on non-empty lines.       (if (zerop (current-column)) 0 (1+ (current-column)))       (let ((cur-pt (point)))	 (beginning-of-line 0)	 ;; If previous line had a comment, use it's indent	 (if (re-search-forward comment-start-skip cur-pt t)	     (progn	       (goto-char (match-beginning 0))	       (current-column))	   comment-column))))))		; otherwise indent at comment column.;; ======================================================================;; most command level (interactive) and related;; ======================================================================(defun c++-set-auto-hungry-state (auto-p hungry-p)  "Set auto/hungry to state indicated by AUTO-P and HUNGRY-P.Update mode line to indicate state to user."  (setq c++-auto-newline auto-p	c++-hungry-delete-key hungry-p)  (set-buffer-modified-p (buffer-modified-p)))(defun c++-toggle-auto-state (arg)  "Toggle auto-newline state.This function ignores c++-auto-hungry-toggle variable.  Optionalnumeric ARG, if supplied turns on auto-newline when positive, turnsoff auto-newline when negative and toggles when zero."  (interactive "P")  (let ((auto (cond ((not arg)		     (not c++-auto-newline))		    ((zerop (setq arg (prefix-numeric-value arg)))		     (not c++-auto-newline))		    ((< arg 0) nil)		    (t t))))    (c++-set-auto-hungry-state auto c++-hungry-delete-key)))(defun c++-toggle-hungry-state (arg)  "Toggle hungry-delete-key state.This function ignores c++-auto-hungry-toggle variable.  Optionalnumeric ARG, if supplied turns on hungry-delete-key when positive,turns off hungry-delete-key when negative and toggles when zero."  (interactive "P")  (let ((hungry (cond ((not arg)		       (not c++-hungry-delete-key))		      ((zerop (setq arg (prefix-numeric-value arg)))		       (not c++-hungry-delete-key))		      ((< arg 0) nil)		      (t t))))    (c++-set-auto-hungry-state c++-auto-newline hungry)))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -