emacs-devel
[Top][All Lists]
Advanced

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

Re: Space after inline comment char


From: Stefan Monnier
Subject: Re: Space after inline comment char
Date: Sun, 16 Apr 2006 23:51:46 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>>>> That's easy: change comment-start from ";" to "; ".
>>> Then commenting at the beginning of a line will not work correctly
>>> anymore.
>> What makes you think so?
>> AFAIK, the only side-effect it'll have is that there won't be a difference
>> between a comment-padding set to 1 or to 0.

> Try
> emacs -Q -eval '(progn (setq comment-start "; ") (insert "foo\n") 
> (comment-region (point-max) (point-min)))'

> That will result in
> ; foo
> whereas it should be
> ;; foo

Good point.  I believe the patch below has fixed it,


        Stefan


--- newcomment.el       03 fév 2006 10:56:11 -0500      1.91
+++ newcomment.el       16 avr 2006 23:48:30 -0400      
@@ -895,6 +895,11 @@
                   (delete-char n)
                   (setq ,bindent (- ,bindent n)))))))))))
 
+(defun comment-add (arg)
+  (if (and (null arg) (= (string-match "[ \t]*\\'" comment-start) 1))
+      comment-add
+    (1- (prefix-numeric-value arg))))
+
 (defun comment-region-internal (beg end cs ce
                                 &optional ccs cce block lines indent)
   "Comment region BEG .. END.
@@ -999,7 +1004,6 @@
 
 (defun comment-region-default (beg end &optional arg)
   (let* ((numarg (prefix-numeric-value arg))
-        (add comment-add)
         (style (cdr (assoc comment-style comment-styles)))
         (lines (nth 2 style))
         (block (nth 1 style))
@@ -1032,8 +1036,7 @@
      ((consp arg) (uncomment-region beg end))
      ((< numarg 0) (uncomment-region beg end (- numarg)))
      (t
-      (setq numarg (if (and (null arg) (= (length comment-start) 1))
-                      add (1- numarg)))
+      (setq numarg (comment-add arg))
       (comment-region-internal
        beg end
        (let ((s (comment-padright comment-start numarg)))
@@ -1091,8 +1094,7 @@
        ;; 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))
-      (let ((add (if arg (prefix-numeric-value arg)
-                  (if (= (length comment-start) 1) comment-add 0))))
+      (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)




reply via email to

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