diff options
| author | Alan Mackenzie | 2017-06-15 20:47:11 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-06-15 21:03:03 +0000 |
| commit | 7a2038d7c887e4fa08a91950a7494d1dd20c39e1 (patch) | |
| tree | 3aca6adb27e83c129c9a2f2cebffef55e679fcde /doc | |
| parent | 21d10e59f89a5bb72829ffb8ebe4463ba4fac124 (diff) | |
| download | emacs-7a2038d7c887e4fa08a91950a7494d1dd20c39e1.tar.gz 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')
| -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. | |||
| 812 | @cindex comments (insertion of) | 812 | @cindex comments (insertion of) |
| 813 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 813 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 814 | 814 | ||
| 815 | When the commands in this section add comment delimiters, they use | ||
| 816 | either line comments or block comments depending on the setting of the | ||
| 817 | comment style (@pxref{Minor Modes}). | ||
| 818 | |||
| 815 | @table @asis | 819 | @table @asis |
| 816 | @item @kbd{C-c C-c} (@code{comment-region}) | 820 | @item @kbd{C-c C-c} (@code{comment-region}) |
| 817 | @kindex C-c C-c | 821 | @kindex C-c C-c |
| @@ -1133,6 +1137,9 @@ line break. | |||
| 1133 | find useful while writing new code or editing old code: | 1137 | find useful while writing new code or editing old code: |
| 1134 | 1138 | ||
| 1135 | @table @asis | 1139 | @table @asis |
| 1140 | @item comment style | ||
| 1141 | This specifies whether comment commands (such as @kbd{M-;}) insert | ||
| 1142 | block comments or line comments. | ||
| 1136 | @item electric mode | 1143 | @item electric mode |
| 1137 | When this is enabled, certain visible characters cause reformatting as | 1144 | When this is enabled, certain visible characters cause reformatting as |
| 1138 | they are typed. This is normally helpful, but can be a nuisance when | 1145 | they are typed. This is normally helpful, but can be a nuisance when |
| @@ -1168,20 +1175,32 @@ and @ref{Indentation Engine Basics}. | |||
| 1168 | You can toggle each of these minor modes on and off, and you can | 1175 | You can toggle each of these minor modes on and off, and you can |
| 1169 | configure @ccmode{} so that it starts up with your favorite | 1176 | configure @ccmode{} so that it starts up with your favorite |
| 1170 | combination of them (@pxref{Sample Init File}). By default, when | 1177 | combination of them (@pxref{Sample Init File}). By default, when |
| 1171 | you initialize a buffer, electric mode and syntactic-indentation mode | 1178 | you initialize a buffer, the comment style is set to the default for |
| 1172 | are enabled but the other three modes are disabled. | 1179 | the major mode, electric mode and syntactic-indentation mode are |
| 1173 | 1180 | enabled, but the other three modes are disabled. | |
| 1174 | @ccmode{} displays the current state of the first four of these minor | 1181 | |
| 1175 | modes on the modeline by appending letters to the major mode's name, | 1182 | @ccmode{} displays the current state of the first five of these minor |
| 1176 | one letter for each enabled minor mode: @samp{l} for electric mode, | 1183 | modes on the mode line by appending characters to the major mode's |
| 1177 | @samp{a} for auto-newline mode, @samp{h} for hungry delete mode, and | 1184 | name: @samp{/} or @samp{*} to indicate the comment style (respectively |
| 1178 | @samp{w} for subword mode. If all these modes were enabled, you'd see | 1185 | line or block), and one letter for each of the other minor modes which |
| 1179 | @samp{C/lahw}@footnote{The @samp{C} would be replaced with the name of | 1186 | is enabled - @samp{l} for electric mode, @samp{a} for auto-newline |
| 1180 | the language in question for the other languages @ccmode{} supports.}. | 1187 | mode, @samp{h} for hungry delete mode, and @samp{w} for subword mode. |
| 1188 | If the comment style was block and all the other modes were enabled, | ||
| 1189 | you'd see @samp{C/*lahw}@footnote{The @samp{C} would be replaced with | ||
| 1190 | the name of the language in question for the other languages @ccmode{} | ||
| 1191 | supports.}. | ||
| 1181 | 1192 | ||
| 1182 | Here are the commands to toggle these modes: | 1193 | Here are the commands to toggle these modes: |
| 1183 | 1194 | ||
| 1184 | @table @asis | 1195 | @table @asis |
| 1196 | @item @kbd{C-c C-k} (@code{c-toggle-comment-style}) | ||
| 1197 | @kindex C-c C-k | ||
| 1198 | @findex c-toggle-comment-style | ||
| 1199 | @findex toggle-comment-style (c-) | ||
| 1200 | Toggle the comment style between line style and block style. In modes | ||
| 1201 | (such as AWK Mode) which only have one of these styles, this function | ||
| 1202 | does nothing. | ||
| 1203 | |||
| 1185 | @item @kbd{C-c C-l} (@code{c-toggle-electric-state}) | 1204 | @item @kbd{C-c C-l} (@code{c-toggle-electric-state}) |
| 1186 | @kindex C-c C-l | 1205 | @kindex C-c C-l |
| 1187 | @findex c-toggle-electric-state | 1206 | @findex c-toggle-electric-state |
| @@ -1218,10 +1237,12 @@ Toggle syntactic-indentation mode. | |||
| 1218 | @end table | 1237 | @end table |
| 1219 | 1238 | ||
| 1220 | Common to all the toggle functions above is that if they are called | 1239 | Common to all the toggle functions above is that if they are called |
| 1221 | programmatically, they take an optional numerical argument. A | 1240 | programmatically, they take an optional numerical argument. For |
| 1222 | positive value will turn on the minor mode (or both of them in the | 1241 | @code{c-toggle-comment style}, a positive value will select block |
| 1223 | case of @code{c-toggle-auto-hungry-state}) and a negative value will | 1242 | comments, a negative value will select line comments. For the other |
| 1224 | turn it (or them) off. | 1243 | functions, a positive value will turn on the minor mode (or both of |
| 1244 | them in the case of @code{c-toggle-auto-hungry-state}) and a negative | ||
| 1245 | value will turn it (or them) off. | ||
| 1225 | 1246 | ||
| 1226 | 1247 | ||
| 1227 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1248 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @@ -7232,6 +7253,22 @@ too, add this to your @code{c-initialization-hook}: | |||
| 7232 | @xref{Getting Started}. This was a very common question. | 7253 | @xref{Getting Started}. This was a very common question. |
| 7233 | 7254 | ||
| 7234 | @item | 7255 | @item |
| 7256 | @emph{How do I get block comments in my C++ files?} | ||
| 7257 | |||
| 7258 | Interactively, change the comment style with @kbd{C-c C-k}. | ||
| 7259 | @xref{Minor Modes}. | ||
| 7260 | |||
| 7261 | To configure this setting, say, for files within the gdb project, you | ||
| 7262 | could amend your C++ Mode hook like this: | ||
| 7263 | |||
| 7264 | @example | ||
| 7265 | (defun my-c++-mode-hook () | ||
| 7266 | (if (string-match "/gdb/" (buffer-file-name)) | ||
| 7267 | (c-toggle-comment-style 1))) | ||
| 7268 | (add-hook 'c++-mode-hook 'my-c++-mode-hook) | ||
| 7269 | @end example | ||
| 7270 | |||
| 7271 | @item | ||
| 7235 | @emph{How do I stop my C++ lambda expressions being indented way over | 7272 | @emph{How do I stop my C++ lambda expressions being indented way over |
| 7236 | to the right?} | 7273 | to the right?} |
| 7237 | 7274 | ||