From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Will Farrington Newsgroups: gmane.emacs.devel Subject: Re: comment-dwim has no behavior to comment out the current line without a region Date: Tue, 9 Dec 2008 04:22:38 -0500 Message-ID: <747769BF-A786-42C9-B35B-CA29F599FFA8@gmail.com> References: <492E5CDD-4C3A-4995-97DD-C2A65133F8D5@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v929.2) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1228814579 16295 80.91.229.12 (9 Dec 2008 09:22:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Dec 2008 09:22:59 +0000 (UTC) To: emacs-devel@gnu.org, Will Farrington Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 09 10:24:04 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L9yp2-0002sV-FG for ged-emacs-devel@m.gmane.org; Tue, 09 Dec 2008 10:24:04 +0100 Original-Received: from localhost ([127.0.0.1]:56675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L9ynq-0005HH-QB for ged-emacs-devel@m.gmane.org; Tue, 09 Dec 2008 04:22:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L9ynl-0005FY-RT for emacs-devel@gnu.org; Tue, 09 Dec 2008 04:22:45 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L9ynj-0005FA-Ec for emacs-devel@gnu.org; Tue, 09 Dec 2008 04:22:44 -0500 Original-Received: from [199.232.76.173] (port=44304 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L9ynj-0005F6-8Y for emacs-devel@gnu.org; Tue, 09 Dec 2008 04:22:43 -0500 Original-Received: from yx-out-1718.google.com ([74.125.44.154]:52198) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L9yni-0003Qj-Rx for emacs-devel@gnu.org; Tue, 09 Dec 2008 04:22:43 -0500 Original-Received: by yx-out-1718.google.com with SMTP id 34so662650yxf.66 for ; Tue, 09 Dec 2008 01:22:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=D+ZyCju7kHnFu3hemJIKA3hk9q1ycP1v3CC2u8CxiFA=; b=Gb7bJTL/qF+NZZC50EeDl2pmubJej8YyyHJHNbh1WPblfVniCOCuge2qeCwkQccIBO pkakiy2pJdParW2sxnbxTp2SPkRxWC4DJTgM0MXT28ppcAb21kQSmUNc7pFAnoWAhWlI 3N296EI8k22AnSrtijEU9+fOhyuODQ1UnXcTE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=Y+Glz/yoy/MThXn1KAoWYSV7JP1P7aQwLBozg+f3nwbVunhTRXYdJN7CxkhBvcCYpK qddNY0Q2ZsYkbqK6BkILQd2mmDyGwBiZj9/8KO5ifdbk9T79IbIZRVEHxPWxgjfvT07w xZ+Ux9sNn+ZJWzKp/eUoiEqYgHl1rb0UVmGZU= Original-Received: by 10.100.108.20 with SMTP id g20mr2042121anc.14.1228814561928; Tue, 09 Dec 2008 01:22:41 -0800 (PST) Original-Received: from lawn-128-61-25-5.lawn.gatech.edu (lawn-128-61-25-5.lawn.gatech.edu [128.61.25.5]) by mx.google.com with ESMTPS id c9sm20734230ana.59.2008.12.09.01.22.40 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 09 Dec 2008 01:22:40 -0800 (PST) In-Reply-To: <492E5CDD-4C3A-4995-97DD-C2A65133F8D5@gmail.com> X-Mailer: Apple Mail (2.929.2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106710 Archived-At: It seems that for whatever reason the .patch got treated as binary data. Here's the patch in-line: From b3a783075ad4eafe9e2303442d68f6bec41cfaa6 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Dec 2008 01:00:18 -0500 Subject: [PATCH] Change comment-dwim behavior to comment out the current line when region is inactive and point is at the line- beginning-position. diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 91ece5a..acac17b 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1159,6 +1159,9 @@ is passed on to the respective function." If the region is active and `transient-mark-mode' is on, call `comment-region' (unless it only consists of comments, in which case it calls `uncomment-region'). +Else, if the point is at `line-beginning-position', call `comment- region' + on the whole line (unless the line consists of comments, in which + case it calls `uncomment-region'). Else, if the current line is empty, call `comment-insert-comment- function' if it is defined, otherwise insert a comment and indent it. Else if a prefix ARG is specified, call `comment-kill'. @@ -1168,23 +1171,25 @@ You can configure `comment-style' to change the way regions are commented." (comment-normalize-vars) (if (and mark-active transient-mark-mode) (comment-or-uncomment-region (region-beginning) (region-end) arg) - (if (save-excursion (beginning-of-line) (not (looking-at "\\s-* $"))) - ;; FIXME: If there's no comment to kill on this line and ARG is - ;; specified, calling comment-kill is not very clever. - (if arg (comment-kill (and (integerp arg) arg)) (comment-indent)) - ;; Inserting a comment on a blank line. comment-indent calls - ;; c-i-c-f if needed in the non-blank case. - (if comment-insert-comment-function - (funcall comment-insert-comment-function) - (let ((add (comment-add arg))) - ;; Some modes insist on keeping column 0 comment in column 0 - ;; so we need to move away from it before inserting the comment. - (indent-according-to-mode) - (insert (comment-padright comment-start add)) - (save-excursion - (unless (string= "" comment-end) - (insert (comment-padleft comment-end add))) - (indent-according-to-mode))))))) + (if (eq (point) (line-beginning-position)) + (comment-or-uncomment-region (line-beginning-position) (line- end-position)) + (if (save-excursion (beginning-of-line) (not (looking-at "\\s-* $"))) + ;; FIXME: If there's no comment to kill on this line and ARG is + ;; specified, calling comment-kill is not very clever. + (if arg (comment-kill (and (integerp arg) arg)) (comment- indent)) + ;; Inserting a comment on a blank line. comment-indent calls + ;; c-i-c-f if needed in the non-blank case. + (if comment-insert-comment-function + (funcall comment-insert-comment-function) + (let ((add (comment-add arg))) + ;; Some modes insist on keeping column 0 comment in column 0 + ;; so we need to move away from it before inserting the comment. + (indent-according-to-mode) + (insert (comment-padright comment-start add)) + (save-excursion + (unless (string= "" comment-end) + (insert (comment-padleft comment-end add))) + (indent-according-to-mode)))))))) ;;;###autoload (defcustom comment-auto-fill-only-comments nil -- 1.6.0.4 On Dec 9, 2008, at 3:28 AM, Will Farrington wrote: > Resending this because it seems to have gotten lost along the way > (at least from what I could tell): > -------------- > > The subject states my specific objection to the current behavior. > > Yes, for many languages, it takes the same number of keystrokes to > insert a comment character; however, there are languages/modes where > this is *not* true (for example, C89 or anything based on XML). > Additionally, it makes sense to have comment-dwim handle all cases > of managing commented material and comments. > > The proposed diff adds the following additional behavior: > > If the point is at `line-beginning-position' (and the region is > inactive), call `comment-region' > on the whole line (unless the line consists of comments, in which > case it calls `uncomment-region'). > > The patch is attached below: > <0001-Change-comment-dwim-behavior-to-comment-out-the-curr.patch>