From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: one key-press to comment out lines of code? Date: Wed, 30 Apr 2014 13:54:45 -0700 (PDT) Message-ID: <9477b732-7c9e-4a16-b11c-6b09e359cf8e@default> References: <87fvku94ms.fsf@skimble.plus.com> <874n1ak5b9.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1398891330 7222 80.91.229.3 (30 Apr 2014 20:55:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Apr 2014 20:55:30 +0000 (UTC) To: Emanuel Berg , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 30 22:55:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WfbXH-00031L-9n for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Apr 2014 22:55:23 +0200 Original-Received: from localhost ([::1]:59252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfbXG-00074s-QK for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Apr 2014 16:55:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfbWv-0006qS-7b for help-gnu-emacs@gnu.org; Wed, 30 Apr 2014 16:55:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WfbWm-0005Qw-Fk for help-gnu-emacs@gnu.org; Wed, 30 Apr 2014 16:55:01 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:31828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfbWm-0005Qr-9a for help-gnu-emacs@gnu.org; Wed, 30 Apr 2014 16:54:52 -0400 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s3UKsnCO000627 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 Apr 2014 20:54:50 GMT Original-Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3UKsknq026875 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 30 Apr 2014 20:54:47 GMT Original-Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3UKsj7C026858; Wed, 30 Apr 2014 20:54:45 GMT In-Reply-To: <874n1ak5b9.fsf@nl106-137-194.student.uu.se> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6691.5000 (x86)] X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97501 Archived-At: > > I prefer to use `comment-region', which I bind to `C-x ;'. Sorry, I mistyped the key I use. I meant `C-x C-;' - hold down Control and hit `x ;' (or `u x ;', to uncomment). > Why not use M-; for that as well? C-SPC, move point, M-; last. Read what I wrote. I already said why I use `comment-region'. You are free to use anything you like. And I started out by saying that someone else would no doubt laud `M-;'. `comment-region' lets you uncomment or comment (any number of comment chars), whatever is selected (whether some or all of the selected text is already commented or not). I do also use `M-;', but only for what it has always done, even when it was bound to `indent-for-comment': add/indent inline comments. I really have no use for the rest of what it tries to do. YMMV. > > To uncomment, provide a plain prefix arg (`C-u'): > > `C-u C-x ;'. To comment using N comment chars, use a > > numeric prefix arg: `C-3 C-x ;'. (And you can use > > that to nest commented text.) >=20 > Yeah, but again, I think it is much simpler to C-SPC, > move point, and M-; (if the region is commented) to > uncomment. You need to select the text in any case. I don't consider that `M-;' is "much simpler" than `C-x C-;'. But you can of course bind `comment-region' to whatever key you like. Or not. But no; sorry. `comment-dwim' simply does NOT do what `comment-region' does. (define-key isearch-mode-map (kbd "C-y C-a") 'foo) ;;; (define-key isearch-mode-map "\C-a" nil) Select both lines as the region. Each of `M-;' and `C-x C-;' produce this result: ;; (define-key isearch-mode-map (kbd "C-y C-a") 'foo) ;; ;;; (define-key isearch-mode-map "\C-a" nil) But `C-u C-x C-;' produces this: (define-key isearch-mode-map (kbd "C-y C-a") 'foo) (define-key isearch-mode-map "\C-a" nil) It uncomments one level. It always uncomments. `M-;' cannot uncomment the commented lines in the region when there are also uncommented lines. Now select only the second line, the one which is commented: ;;; (define-key isearch-mode-map "\C-a" nil) Now `M-;' uncomments it. `C-u C-x C-;' uncomments it too (it does so always). `C-2 M-;' removes two of the semicolons. `C-x C-;' still comments here, nesting the existing block comment, just as in the case where the selected text contained an uncommented line: ;; ;;; (define-key isearch-mode-map "\C-a" nil) And it uncomments just one level of nesting, giving this: ;;; (define-key isearch-mode-map "\C-a" nil) from this: ;; ;;; (define-key isearch-mode-map "\C-a" nil) `comment-region' does not try to outsmart you: a plain `C-u' uncomments one level. No prefix arg comments one level. A positive prefix arg comments using that many `;'. A negative prefix arg uncomments that many `;'. It is especially the behavior wrt nesting and unnesting of block comments that I appreciate. I often comment out a block of text and then comment out some more, surrounding text. Nesting of the commented lines means I can quickly unnest one level, to return to the previous state. =20 (And yes, like the other Emacs comment functions, `comment-region' is not limited to Lisp code. `M-x' is not special in this regard.) > So for all three cases: M-;. No - see above. Most Emacs users already know about `M-;'. Far fewer know about `comment-region', which is not bound to a key by default. Which is why I mentioned it - in case it helps someone. I assumed that there are users like you who take a quick look (or no look) at `comment-region' and figure that `comment-dwim' does everything it does - everything they need. A DWIM command is often limited this way; it is a compromise. Whether `comment-dwim' is your cup of tea is up to you.