emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comment-dwim has no behavior to comment out the current line without


From: Will Farrington
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

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 <address@hidden>
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>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]