aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorAlan Mackenzie2017-06-15 20:47:11 +0000
committerAlan Mackenzie2017-06-15 21:03:03 +0000
commit7a2038d7c887e4fa08a91950a7494d1dd20c39e1 (patch)
tree3aca6adb27e83c129c9a2f2cebffef55e679fcde /doc
parent21d10e59f89a5bb72829ffb8ebe4463ba4fac124 (diff)
downloademacs-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.texi65
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
815When the commands in this section add comment delimiters, they use
816either line comments or block comments depending on the setting of the
817comment 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.
1133find useful while writing new code or editing old code: 1137find useful while writing new code or editing old code:
1134 1138
1135@table @asis 1139@table @asis
1140@item comment style
1141This specifies whether comment commands (such as @kbd{M-;}) insert
1142block comments or line comments.
1136@item electric mode 1143@item electric mode
1137When this is enabled, certain visible characters cause reformatting as 1144When this is enabled, certain visible characters cause reformatting as
1138they are typed. This is normally helpful, but can be a nuisance when 1145they are typed. This is normally helpful, but can be a nuisance when
@@ -1168,20 +1175,32 @@ and @ref{Indentation Engine Basics}.
1168You can toggle each of these minor modes on and off, and you can 1175You can toggle each of these minor modes on and off, and you can
1169configure @ccmode{} so that it starts up with your favorite 1176configure @ccmode{} so that it starts up with your favorite
1170combination of them (@pxref{Sample Init File}). By default, when 1177combination of them (@pxref{Sample Init File}). By default, when
1171you initialize a buffer, electric mode and syntactic-indentation mode 1178you initialize a buffer, the comment style is set to the default for
1172are enabled but the other three modes are disabled. 1179the major mode, electric mode and syntactic-indentation mode are
1173 1180enabled, but the other three modes are disabled.
1174@ccmode{} displays the current state of the first four of these minor 1181
1175modes 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
1176one letter for each enabled minor mode: @samp{l} for electric mode, 1183modes 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 1184name: @samp{/} or @samp{*} to indicate the comment style (respectively
1178@samp{w} for subword mode. If all these modes were enabled, you'd see 1185line 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 1186is enabled - @samp{l} for electric mode, @samp{a} for auto-newline
1180the language in question for the other languages @ccmode{} supports.}. 1187mode, @samp{h} for hungry delete mode, and @samp{w} for subword mode.
1188If the comment style was block and all the other modes were enabled,
1189you'd see @samp{C/*lahw}@footnote{The @samp{C} would be replaced with
1190the name of the language in question for the other languages @ccmode{}
1191supports.}.
1181 1192
1182Here are the commands to toggle these modes: 1193Here 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-)
1200Toggle 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
1202does 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
1220Common to all the toggle functions above is that if they are called 1239Common to all the toggle functions above is that if they are called
1221programmatically, they take an optional numerical argument. A 1240programmatically, they take an optional numerical argument. For
1222positive 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
1223case of @code{c-toggle-auto-hungry-state}) and a negative value will 1242comments, a negative value will select line comments. For the other
1224turn it (or them) off. 1243functions, a positive value will turn on the minor mode (or both of
1244them in the case of @code{c-toggle-auto-hungry-state}) and a negative
1245value 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
7258Interactively, change the comment style with @kbd{C-c C-k}.
7259@xref{Minor Modes}.
7260
7261To configure this setting, say, for files within the gdb project, you
7262could 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
7236to the right?} 7273to the right?}
7237 7274