From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::INFO-GNU-EMACS-REQUEST"  6-SEP-1989 19:41
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Commenting out C++ Code

Received: by life.ai.mit.edu (4.1/AI-4.10) id AA06471; Wed, 6 Sep 89 16:43:05 EDT
Return-Path: <info-gnu-emacs-request@prep.ai.mit.edu>
Received: from tut.cis.ohio-state.edu by life.ai.mit.edu (4.1/AI-4.10) id AA06231; Wed, 6 Sep 89 16:19:20 EDT
Received: by tut.cis.ohio-state.edu (5.61/4.890725)
	id AA21275; Wed, 6 Sep 89 16:04:53 -0400
Received: from USENET by tut.cis.ohio-state.edu with netnews
	for info-gnu-emacs@prep.ai.mit.edu (info-gnu-emacs@prep.ai.mit.edu)
	(contact usenet@tut.cis.ohio-state.edu if you have questions)
Date: 5 Sep 89 13:44:53 GMT
From: mcsun!cernvax!chx400!iam!metz@uunet.uu.net  (Igor Metz)
Organization: University of Berne, Dept. of Computer Science
Subject: Commenting out C++ Code
Message-Id: <1989Sep5.134453.26325@iam.unibe.ch>
Sender: info-gnu-emacs-request@prep.ai.mit.edu
To: info-gnu-emacs@prep.ai.mit.edu


Last week Dave Detlefs posted a new version of c++-mode. Below you'll find
a diff for it which adds two functions for commenting and uncommenting code.

*** /usr/local/src/emacs/c++-mode.el	Thu Aug 31 11:15:03 1989
--- c++-mode.el	Tue Sep  5 15:32:23 1989
***************
*** 4,9 ****
--- 4,13 ----
  ;; Done by fairly faithful modification of:
  ;; c-mode.el, Copyright (C) 1985 Richard M. Stallman.
  ;;
+ ;; Sep 5, 1989: Igor Metz <metz@iam.unibe.ch>
+ ;;   Added functions c++-comment-region and c++-uncomment-region and 
+ ;;   corresponding key-binding.
+ ;;
  ;; Aug 7, 1989; John Hagerman (hagerman@ece.cmu.edu):
  ;;   Changed calculate-c++-indent to handle member initializations
  ;;   more flexibly. Two new variables are used to control behavior:
***************
*** 64,69 ****
--- 68,75 ----
  (define-key c++-mode-map "\177" 'backward-delete-char-untabify)
  (define-key c++-mode-map "\t" 'c++-indent-command)
  (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header)
+ (define-key c++-mode-map "\C-c\C-c" 'c++-comment-region)
+ (define-key c++-mode-map "\C-c\C-u" 'c++-uncomment-region)
  (define-key c++-mode-map "\C-c\C-\\" 'c++-macroize-region)
  (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun)
  (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun)
***************
*** 925,927 ****
--- 931,961 ----
  	(next-line 1)
  	(beginning-of-line 1)))
      (goto-char restore)))
+ 
+ (defun c++-comment-region ()
+   "Comment out all lines in a region between mark and current point by
+ inserting \"// \" (comment-start)in front of each line."
+   (interactive)
+   (let ((start (mark)))
+     (save-excursion
+       (while (>= (point) start)
+ 	(beginning-of-line)
+ 	(insert comment-start)
+ 	(previous-line 1)))))
+ 
+ 
+ (defun c++-uncomment-region ()
+   "Uncomment all lines in region between mark and current point by deleting
+ the leading \"// \" from each line, if any."
+   (interactive)
+   (let ((start (mark))
+ 	(n     (length comment-start))
+ 	(char  (string-to-char comment-start)))
+     (save-excursion
+       (while (>= (point) start)
+ 	(beginning-of-line)
+ 	(if (looking-at (concat " *" comment-start))
+ 	  (progn
+ 	    (zap-to-char 1 char)
+ 	    (delete-char n)))
+ 	(previous-line 1)))))
-- 

Igor Metz                    X400: metz@iam.unibe.ch
Institut fuer Informatik     ARPA: metz%iam.unibe.ch@relay.cs.net
und angewandte Mathematik    UUCP: ..!uunet!mcvax!iam.unibe.ch!metz
