unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* comment-dwim has no behavior to comment out the current line without a region
@ 2008-12-09  6:06 Will Farrington
  2008-12-09  8:28 ` Will Farrington
  2008-12-09 18:40 ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: Will Farrington @ 2008-12-09  6:06 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-12-11 18:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).