diff options
author | Alan Mackenzie <acm@muc.de> | 2017-06-15 20:47:11 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2017-06-15 21:03:03 +0000 |
commit | 7a2038d7c887e4fa08a91950a7494d1dd20c39e1 (patch) | |
tree | 3aca6adb27e83c129c9a2f2cebffef55e679fcde /doc/misc | |
parent | 21d10e59f89a5bb72829ffb8ebe4463ba4fac124 (diff) | |
download | emacs-7a2038d7c887e4fa08a91950a7494d1dd20c39e1.tar.gz emacs-7a2038d7c887e4fa08a91950a7494d1dd20c39e1.tar.bz2 emacs-7a2038d7c887e4fa08a91950a7494d1dd20c39e1.zip |
Create a toggle between block and line comments in CC Mode.
Also (unrelated change) initialize the modes' keymaps at each loading.
* lisp/progmodes/cc-cmds.el (c-update-modeline): amend for the new information
on the modeline.
(c-block-comment-flag): New variable.
(c-toggle-comment-style): New function.
* lisp/progmodes/cc-langs.el (c-block-comment-starter)
(c-line-comment-starter): Make them c-lang-defvars.
(c-block-comment-is-default): New c-lang-defvar.
(comment-start, comment-end): Make the default values dependent on
c-block-comment-is-default.
* lisp/progmodes/cc-mode.el (c-mode-base-map): Define C-c C-k in this map.
(c-basic-common-init): Initialize c-block-comment-flag.
(c-mode-map, c++-mode-map, objc-mode-map, java-mode-map, idl-mode-map)
(pike-mode-map, awk-mode-map): Make entries in these key maps each time the
mode is loaded rather than just once per Emacs session.
* doc/misc/cc-mode.texi (Comment Commands): Introduce the notion of comment
style.
(Minor Modes): Define comment style. Describe how comment style influences
the information displayed on the modeline. Document c-toggle-comment-style.
(FAQ): Add a question about toggling the comment style.
Diffstat (limited to 'doc/misc')
-rw-r--r-- | doc/misc/cc-mode.texi | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 91e20fa7247..f9ba5cc3921 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi @@ -812,6 +812,10 @@ often (in seconds) progress messages are to be displayed. @cindex comments (insertion of) @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +When the commands in this section add comment delimiters, they use +either line comments or block comments depending on the setting of the +comment style (@pxref{Minor Modes}). + @table @asis @item @kbd{C-c C-c} (@code{comment-region}) @kindex C-c C-c @@ -1133,6 +1137,9 @@ line break. find useful while writing new code or editing old code: @table @asis +@item comment style +This specifies whether comment commands (such as @kbd{M-;}) insert +block comments or line comments. @item electric mode When this is enabled, certain visible characters cause reformatting as they are typed. This is normally helpful, but can be a nuisance when @@ -1168,20 +1175,32 @@ and @ref{Indentation Engine Basics}. You can toggle each of these minor modes on and off, and you can configure @ccmode{} so that it starts up with your favorite combination of them (@pxref{Sample Init File}). By default, when -you initialize a buffer, electric mode and syntactic-indentation mode -are enabled but the other three modes are disabled. - -@ccmode{} displays the current state of the first four of these minor -modes on the modeline by appending letters to the major mode's name, -one letter for each enabled minor mode: @samp{l} for electric mode, -@samp{a} for auto-newline mode, @samp{h} for hungry delete mode, and -@samp{w} for subword mode. If all these modes were enabled, you'd see -@samp{C/lahw}@footnote{The @samp{C} would be replaced with the name of -the language in question for the other languages @ccmode{} supports.}. +you initialize a buffer, the comment style is set to the default for +the major mode, electric mode and syntactic-indentation mode are +enabled, but the other three modes are disabled. + +@ccmode{} displays the current state of the first five of these minor +modes on the mode line by appending characters to the major mode's +name: @samp{/} or @samp{*} to indicate the comment style (respectively +line or block), and one letter for each of the other minor modes which +is enabled - @samp{l} for electric mode, @samp{a} for auto-newline +mode, @samp{h} for hungry delete mode, and @samp{w} for subword mode. +If the comment style was block and all the other modes were enabled, +you'd see @samp{C/*lahw}@footnote{The @samp{C} would be replaced with +the name of the language in question for the other languages @ccmode{} +supports.}. Here are the commands to toggle these modes: @table @asis +@item @kbd{C-c C-k} (@code{c-toggle-comment-style}) +@kindex C-c C-k +@findex c-toggle-comment-style +@findex toggle-comment-style (c-) +Toggle the comment style between line style and block style. In modes +(such as AWK Mode) which only have one of these styles, this function +does nothing. + @item @kbd{C-c C-l} (@code{c-toggle-electric-state}) @kindex C-c C-l @findex c-toggle-electric-state @@ -1218,10 +1237,12 @@ Toggle syntactic-indentation mode. @end table Common to all the toggle functions above is that if they are called -programmatically, they take an optional numerical argument. A -positive value will turn on the minor mode (or both of them in the -case of @code{c-toggle-auto-hungry-state}) and a negative value will -turn it (or them) off. +programmatically, they take an optional numerical argument. For +@code{c-toggle-comment style}, a positive value will select block +comments, a negative value will select line comments. For the other +functions, a positive value will turn on the minor mode (or both of +them in the case of @code{c-toggle-auto-hungry-state}) and a negative +value will turn it (or them) off. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -7232,6 +7253,22 @@ too, add this to your @code{c-initialization-hook}: @xref{Getting Started}. This was a very common question. @item +@emph{How do I get block comments in my C++ files?} + +Interactively, change the comment style with @kbd{C-c C-k}. +@xref{Minor Modes}. + +To configure this setting, say, for files within the gdb project, you +could amend your C++ Mode hook like this: + +@example +(defun my-c++-mode-hook () + (if (string-match "/gdb/" (buffer-file-name)) + (c-toggle-comment-style 1))) +(add-hook 'c++-mode-hook 'my-c++-mode-hook) +@end example + +@item @emph{How do I stop my C++ lambda expressions being indented way over to the right?} |