Wednesday, September 12, 2007

Commenting out a block of C++ in emacs

Here are couple more simple functions, used for commenting out a block of C++ code.

below simple inserts "//" at the start of a line

c++-comment region will take the current region and run the c++comment-line on each line.

(defun c++-comment-region()
"Comment a region out"
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (> (point-max) (point))

(defun c++-comment-line()
"Comment a line of C++ out"
(insert "//"))


Alan said...

Any reason that M-x comment-dwim (bound by default to M-;) doesn't do what you want?

Justin said...

Nope and thanks for the heads up.

justin bartholomew said...

Interesting and important information. It is really beneficial for us. Thanks