comparison man/programs.texi @ 31025:45d3aa851fff

Document comment-dwim and the new binding of M-;. Document that kill-comment is now an alias for comment-kill.
author Eli Zaretskii <eliz@gnu.org>
date Tue, 22 Aug 2000 09:02:40 +0000
parents 2dfd4d6a9043
children 2c91a34c8db3
comparison
equal deleted inserted replaced
31024:147670916de0 31025:45d3aa851fff
1215 @subsection Comment Commands 1215 @subsection Comment Commands
1216 1216
1217 @kindex M-; 1217 @kindex M-;
1218 @cindex indentation for comments 1218 @cindex indentation for comments
1219 @findex indent-for-comment 1219 @findex indent-for-comment
1220 @findex comment-dwim
1220 1221
1221 The comment commands insert, kill and align comments. 1222 The comment commands insert, kill and align comments.
1222 1223
1223 @c WideCommands 1224 @c WideCommands
1224 @table @kbd 1225 @table @kbd
1225 @item M-; 1226 @item M-;
1226 Insert or align comment (@code{indent-for-comment}). 1227 Call the comment command that is appropriate for the context
1228 (@code{comment-dwim}).
1229 @item M-x indent-for-comment
1230 Insert or align comment.
1227 @item C-x ; 1231 @item C-x ;
1228 Set comment column (@code{set-comment-column}). 1232 Set comment column (@code{set-comment-column}).
1229 @item C-u - C-x ; 1233 @item C-u - C-x ;
1230 Kill comment on current line (@code{kill-comment}). 1234 Kill comment on current line (@code{comment-kill}).
1231 @item C-M-j 1235 @item C-M-j
1232 Like @key{RET} followed by inserting and aligning a comment 1236 Like @key{RET} followed by inserting and aligning a comment
1233 (@code{indent-new-comment-line}). 1237 (@code{indent-new-comment-line}).
1234 @item M-x comment-region 1238 @item M-x comment-region
1235 Add or remove comment delimiters on all the lines in the region. 1239 Add or remove comment delimiters on all the lines in the region.
1236 @end table 1240 @end table
1237 1241
1238 The command that creates a comment is @kbd{M-;} (@code{indent-for-comment}). 1242 The command that creates a comment is @kbd{M-x indent-for-comment}.
1239 If there is no comment already on the line, a new comment is created, 1243 If there is no comment already on the line, a new comment is created,
1240 aligned at a specific column called the @dfn{comment column}. The comment 1244 aligned at a specific column called the @dfn{comment column}. The comment
1241 is created by inserting the string Emacs thinks comments should start with 1245 is created by inserting the string Emacs thinks comments should start with
1242 (the value of @code{comment-start}; see below). Point is left after that 1246 (the value of @code{comment-start}; see below). Point is left after that
1243 string. If the text of the line extends past the comment column, then the 1247 string. If the text of the line extends past the comment column, then the
1244 indentation is done to a suitable boundary (usually, at least one space is 1248 indentation is done to a suitable boundary (usually, at least one space is
1245 inserted). If the major mode has specified a string to terminate comments, 1249 inserted). If the major mode has specified a string to terminate comments,
1246 that is inserted after point, to keep the syntax valid. 1250 that is inserted after point, to keep the syntax valid.
1247 1251
1248 @kbd{M-;} can also be used to align an existing comment. If a line 1252 @kbd{M-x indent-for-comment} can also be used to align an existing
1249 already contains the string that starts comments, then @kbd{M-;} just moves 1253 comment. If a line already contains the string that starts comments,
1250 point after it and reindents it to the conventional place. Exception: 1254 then @kbd{M-x indent-for-comment} just moves point after it and
1251 comments starting in column 0 are not moved. 1255 reindents it to the conventional place. Exception: comments starting in
1256 column 0 are not moved.
1257
1258 @kbd{M-;} (@code{comment-dwim}) conveniently combines
1259 @code{indent-for-comment} with @code{comment-region} and
1260 @code{uncomment-region}, described below in @ref{Multi-Line Comments},
1261 as appropriate for the current context. If the region is active and the
1262 Transient Mark mode is on (@pxref{Transient Mark}), @kbd{M-;} invokes
1263 @code{comment-region}, unless the region consists only of comments, in
1264 which case it invokes @code{uncomment-region}. Otherwise, if the
1265 current line is empty, @kbd{M-;} inserts a comment and indents it. If
1266 the current line is not empty, @kbd{M-;} invokes @code{comment-kill} if
1267 a numeric argument was given, else it reindents the comment on the
1268 current line. (The @dfn{dwim} in @code{comment-dwim} is an acronym for
1269 ``Do What I Mean''.)
1252 1270
1253 Some major modes have special rules for indenting certain kinds of 1271 Some major modes have special rules for indenting certain kinds of
1254 comments in certain contexts. For example, in Lisp code, comments which 1272 comments in certain contexts. For example, in Lisp code, comments which
1255 start with two semicolons are indented as if they were lines of code, 1273 start with two semicolons are indented as if they were lines of code,
1256 instead of at the comment column. Comments which start with three 1274 instead of at the comment column. Comments which start with three
1273 Even when an existing comment is properly aligned, @kbd{M-;} is still 1291 Even when an existing comment is properly aligned, @kbd{M-;} is still
1274 useful for moving directly to the start of the comment. 1292 useful for moving directly to the start of the comment.
1275 1293
1276 @kindex C-u - C-x ; 1294 @kindex C-u - C-x ;
1277 @findex kill-comment 1295 @findex kill-comment
1278 @kbd{C-u - C-x ;} (@code{kill-comment}) kills the comment on the current line, 1296 @findex comment-kill
1297 @kbd{C-u - C-x ;} (@code{comment-kill}) kills the comment on the current line,
1279 if there is one. The indentation before the start of the comment is killed 1298 if there is one. The indentation before the start of the comment is killed
1280 as well. If there does not appear to be a comment in the line, nothing is 1299 as well. If there does not appear to be a comment in the line, nothing is
1281 done. To reinsert the comment on another line, move to the end of that 1300 done. To reinsert the comment on another line, move to the end of that
1282 line, do @kbd{C-y}, and then do @kbd{M-;} to realign it. Note that 1301 line, do @kbd{C-y}, and then do @kbd{M-;} to realign it. Note that
1283 @kbd{C-u - C-x ;} is not a distinct key; it is @kbd{C-x ;} (@code{set-comment-column}) 1302 @kbd{C-u - C-x ;} is not a distinct key; it is @kbd{C-x ;} (@code{set-comment-column})
1284 with a negative argument. That command is programmed so that when it 1303 with a negative argument. That command is programmed so that when it
1285 receives a negative argument it calls @code{kill-comment}. However, 1304 receives a negative argument it calls @code{comment-kill}. However,
1286 @code{kill-comment} is a valid command which you could bind directly to a 1305 @code{comment-kill} is a valid command which you could bind directly to a
1287 key if you wanted to. 1306 key if you wanted to. (For compatibility with previous versions,
1307 @code{kill-comment} is provided as an alias to @code{comment-kill}.)
1288 1308
1289 @node Multi-Line Comments 1309 @node Multi-Line Comments
1290 @subsection Multiple Lines of Comments 1310 @subsection Multiple Lines of Comments
1291 1311
1292 @kindex C-M-j 1312 @kindex C-M-j
1332 can set it to a number explicitly. Alternatively, the command @kbd{C-x ;} 1352 can set it to a number explicitly. Alternatively, the command @kbd{C-x ;}
1333 (@code{set-comment-column}) sets the comment column to the column point is 1353 (@code{set-comment-column}) sets the comment column to the column point is
1334 at. @kbd{C-u C-x ;} sets the comment column to match the last comment 1354 at. @kbd{C-u C-x ;} sets the comment column to match the last comment
1335 before point in the buffer, and then does a @kbd{M-;} to align the 1355 before point in the buffer, and then does a @kbd{M-;} to align the
1336 current line's comment under the previous one. Note that @kbd{C-u - C-x ;} 1356 current line's comment under the previous one. Note that @kbd{C-u - C-x ;}
1337 runs the function @code{kill-comment} as described above. 1357 runs the function @code{comment-kill} as described above.
1338 1358
1339 The variable @code{comment-column} is per-buffer: setting the variable 1359 The variable @code{comment-column} is per-buffer: setting the variable
1340 in the normal fashion affects only the current buffer, but there is a 1360 in the normal fashion affects only the current buffer, but there is a
1341 default value which you can change with @code{setq-default}. 1361 default value which you can change with @code{setq-default}.
1342 @xref{Locals}. Many major modes initialize this variable for the 1362 @xref{Locals}. Many major modes initialize this variable for the