From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] newcomment.el (comment-line): New command. Date: Sun, 1 Feb 2015 17:48:30 -0200 Message-ID: References: <68eca5a1-04b6-462a-bf70-4abb02b72460@default> Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1422820131 28047 80.91.229.3 (1 Feb 2015 19:48:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Feb 2015 19:48:51 +0000 (UTC) Cc: Stefan Monnier , emacs-devel To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 01 20:48:50 2015 Return-path: Envelope-to: ged-emacs-devel@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 1YI0Vl-0000Mu-Gi for ged-emacs-devel@m.gmane.org; Sun, 01 Feb 2015 20:48:49 +0100 Original-Received: from localhost ([::1]:51713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI0Vl-00079Z-0X for ged-emacs-devel@m.gmane.org; Sun, 01 Feb 2015 14:48:49 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI0VU-00077t-RI for emacs-devel@gnu.org; Sun, 01 Feb 2015 14:48:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YI0VT-0008Kd-DZ for emacs-devel@gnu.org; Sun, 01 Feb 2015 14:48:32 -0500 Original-Received: from mail-oi0-x234.google.com ([2607:f8b0:4003:c06::234]:64438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI0VT-0008KM-7d for emacs-devel@gnu.org; Sun, 01 Feb 2015 14:48:31 -0500 Original-Received: by mail-oi0-f52.google.com with SMTP id h136so41541968oig.11 for ; Sun, 01 Feb 2015 11:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=1KBl+RA6uTTBBHi1JoEJr1mH9SjpXjTsJHQMux+mr64=; b=nWz7U1aiBzaFIa5JoONFylxOqeEqFcw46RbqClXs1LSDUrNyAAnM7sZNWdfPhnARlK +270v7CvzrHJYTYdFmHsFuQDLa7KuIKoqp5yk4m6lNTR8UjW7QoXYSCi66G9mQqvhbrU Lka4DlSpKGpgyNkj0sWAa7qq949q8CJE4m6618OvOhcX1L8QQ2wlvL8RTq4OPu8VyiMT omykrwhslOClmPtwQB2tqsJb/HdT9WDsQ6eRwicarJW433Wj8bqYdy3uHYzmM03SJ8pz XyC9EpKB1wiSgnKCL9MFIxifoZvNOQ2XXNFf8rM/hOeHDDEBvg/NNL4KLfmYtBPSUssD ngAg== X-Received: by 10.60.135.3 with SMTP id po3mr9895605oeb.58.1422820110160; Sun, 01 Feb 2015 11:48:30 -0800 (PST) Original-Received: by 10.76.125.1 with HTTP; Sun, 1 Feb 2015 11:48:30 -0800 (PST) In-Reply-To: <68eca5a1-04b6-462a-bf70-4abb02b72460@default> X-Google-Sender-Auth: 0a40BDA3Pavuhp2K3fbhmHJeRlc X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::234 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182206 Archived-At: FWIW, the command I suggested is indeed repeatable because it moves `forward-line' after commenting the line. So you can just invoke it repeatedly to comment several lines (for those who don't use prefix arguments). I blogged about this feature this Monday [1], and there was an above-average amount of comments saying "I do something similar" (7 is by no means a crowd, but is above average :-P). This is a slight indicator that people do expect this feature. Also, as I mentioned before, the people coming from simpler IDEs are sure to miss this feature. Which is a shame given how simple it is to implement. [1]: http://endlessparentheses.com/implementing-comment-line.html Just to clarify, this is not meant as replacement for comment-dwim, this is a complement. For most languages, commenting a line is a very common action, and having to do `C-a C-SPC C-n M-;' for that is sad to say the least. comment-line is both faster and more natural when one is commenting 1 or a handful of lines. I would like to politely insist this gets included into newcomment.el (with a keybind). I can do it myself if I get approval on a keybind. I'd like something repeatable, like C-; or C-M-; but I'm also receptive of Drew's suggestion of C-x C-; Below is the most recent version, but I can also provide a version which acts on active region (see link). ---------------------------------------- (defun endless/comment-line (n) "Comment or uncomment current line and leave point after it. With positive prefix, apply to N lines including current one. With negative prefix, apply to -N lines above." (interactive "p") (let ((range (list (line-beginning-position) (goto-char (line-end-position n))))) (comment-or-uncomment-region (apply #'min range) (apply #'max range))) (forward-line 1) (back-to-indentation)) 2015-01-27 0:53 GMT-02:00 Drew Adams : >>> C-a C-SPC C-n M-; >>> >>> works for me when I need it. M-x comment-line RET is much longer (even >>> if you shorten it with something like partial-completion), so for such >>> a command to make sense, you'd need a key binding for it. >> >> Yes, you would. I didn't mention keybinds yet, because I was tackling this by parts. >> >> I bind it to `C-;'. Another viable key might be `C-M-;'. But it definitely >> needs a key. >> >> When you want to comment/uncomment something between 1 and 9 lines, it >> always requires less keypresses than the M-; alternative. >> Besides, commenting a single line is such a common scenario, I find it >> deserves a single key instead of a 4 key combo. >> It's also something that a lot of IDE's assign to a hotkey, so I'm sure >> I'm not the only one that finds it useful. :-) And people who come from >> other editors are sure to miss it. > > FWIW, I use a variant of `comment-region' (below). I bind it to > `C-x C-;'. (The other, repeatable, keys you mention are too good to > waste on a non-repeating command.) > > (defun comment-region-lines (beg end &optional arg) > "Like `comment-region' (which see), but comment/uncomment whole lines." > (interactive "*r\nP") > (if (> beg end) (let (mid) (setq mid beg beg end end mid))) > (let ((bol (save-excursion (goto-char beg) > (line-beginning-position))) > (eol (save-excursion (goto-char end) > (if (bolp) (point) (line-end-position))))) > (comment-region bol eol arg))) > > If the region is empty then it comments the current line. > > (But it does not distinguish active from inactive region. > That would be another possible behavior choice.) > > I use this all the time. I use `M-;' (`comment-dwim') only > for an end-of-line comment (as in the good old days). I find > that `M-;' is quite poor for commenting and uncommenting the > region (including nesting and unnesting comment levels etc.). > > `comment-region' is much better for that, IMO. And as enhanced > above, it comments whole lines, which is what I typically want.