From: Will Farrington <wcfarrington@gmail.com>
To: emacs-devel@gnu.org
Subject: comment-dwim has no behavior to comment out the current line without a region
Date: Tue, 9 Dec 2008 03:28:29 -0500 [thread overview]
Message-ID: <492E5CDD-4C3A-4995-97DD-C2A65133F8D5@gmail.com> (raw)
In-Reply-To: <D2129C42-3116-49C3-BAEF-F4352DACBD52@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 800 bytes --]
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:
[-- Attachment #2: 0001-Change-comment-dwim-behavior-to-comment-out-the-curr.patch --]
[-- Type: application/octet-stream, Size: 3507 bytes --]
From b3a783075ad4eafe9e2303442d68f6bec41cfaa6 Mon Sep 17 00:00:00 2001
From: Will Farrington <wcfarrington@gmail.com>
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
next prev parent reply other threads:[~2008-12-09 8:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-09 6:06 comment-dwim has no behavior to comment out the current line without a region Will Farrington
2008-12-09 8:28 ` Will Farrington [this message]
2008-12-09 9:22 ` Will Farrington
2008-12-09 12:40 ` Eli Zaretskii
2008-12-09 18:27 ` Stefan Monnier
2008-12-09 22:54 ` Eli Zaretskii
2008-12-09 18:40 ` Stefan Monnier
2008-12-09 18:50 ` Will Farrington
2008-12-09 19:48 ` Stefan Monnier
2008-12-09 20:03 ` Will Farrington
2008-12-10 12:22 ` Will Farrington
2008-12-11 15:27 ` Stefan Monnier
2008-12-11 18:26 ` Ted Zlatanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=492E5CDD-4C3A-4995-97DD-C2A65133F8D5@gmail.com \
--to=wcfarrington@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.