emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/lisp/newcomment.el,v


From: Richard M. Stallman
Subject: [Emacs-diffs] Changes to emacs/lisp/newcomment.el,v
Date: Fri, 26 Oct 2007 09:52:12 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Richard M. Stallman <rms>       07/10/26 09:52:12

Index: newcomment.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/newcomment.el,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -b -r1.105 -r1.106
--- newcomment.el       20 Sep 2007 16:31:35 -0000      1.105
+++ newcomment.el       26 Oct 2007 09:52:12 -0000      1.106
@@ -182,13 +182,16 @@
 (defvar comment-add 0
   "How many more comment chars should be inserted by `comment-region'.
 This determines the default value of the numeric argument of `comment-region'.
+The `plain' comment style doubles this value.
+
 This should generally stay 0, except for a few modes like Lisp where
-it can be convenient to set it to 1 so that regions are commented with
-two semi-colons.")
+it is 1 so that regions are commented with two or three semi-colons.")
 
 (defconst comment-styles
   '((plain     . (nil nil nil nil))
     (indent    . (nil nil nil t))
+    (indent-or-triple
+                . (nil nil nil multi-char))
     (aligned   . (nil t nil t))
     (multi-line        . (t nil nil t))
     (extra-line        . (t nil t t))
@@ -201,10 +204,12 @@
 EXTRA specifies that an extra line should be used before and after the
   region to comment (to put the `comment-end' and `comment-start').
 INDENT specifies that the `comment-start' markers should not be put at the
-  left margin but at the current indentation of the region to comment.")
+  left margin but at the current indentation of the region to comment.
+If INDENT is `multi-char', that means indent multi-character
+  comment starters, but not one-character comment starters.")
 
 ;;;###autoload
-(defcustom comment-style 'plain
+(defcustom comment-style 'indent-or-triple
   "Style to be used for `comment-region'.
 See `comment-styles' for a list of available styles."
   :type (if (boundp 'comment-styles)
@@ -939,14 +944,14 @@
                   (delete-char n)
                   (setq ,bindent (- ,bindent n)))))))))))
 
-;; Compute the number of extra semicolons to add to the comment starter
-;; in Lisp mode, extra stars in C mode, etc.
+;; Compute the number of extra comment starter characters
+;; (extra semicolons in Lisp mode, extra stars in C mode, etc.)
 ;; If ARG is non-nil, just follow ARG.
 ;; If the comment-starter is multi-char, just follow ARG.
 ;; Otherwise obey comment-add, and double it if EXTRA is non-nil.
-(defun comment-add (arg &optional extra)
+(defun comment-add (arg)
   (if (and (null arg) (= (string-match "[ \t]*\\'" comment-start) 1))
-      (* comment-add (if extra 2 1))
+      (* comment-add 1)
     (1- (prefix-numeric-value arg))))
 
 (defun comment-region-internal (beg end cs ce
@@ -1086,10 +1091,19 @@
      ((consp arg) (uncomment-region beg end))
      ((< numarg 0) (uncomment-region beg end (- numarg)))
      (t
-      ;; Add an extra semicolon in Lisp and similar modes.
-      ;; If STYLE doesn't specify indenting the comments,
-      ;; then double the value of `comment-add'.
-      (setq numarg (comment-add arg (null (nth 3 style))))
+      (let ((multi-char (/= (string-match "[ \t]*\\'" comment-start) 1))
+           indent)
+       (if (eq (nth 3 style) 'multi-char)
+           (setq indent multi-char)
+         (setq indent (nth 3 style)))
+
+       ;; In Lisp and similar modes with one-character comment starters,
+       ;; double it by default if `comment-add' says so.
+       ;; If it isn't indented, triple it.
+       (if (and (null arg) (not multi-char))
+           (setq numarg (* comment-add (if indent 1 2)))
+         (setq numarg (1- (prefix-numeric-value arg))))
+
       (comment-region-internal
        beg end
        (let ((s (comment-padright comment-start numarg)))
@@ -1103,7 +1117,7 @@
           (comment-padleft (comment-string-reverse comment-continue) numarg))
        block
        lines
-       (nth 3 style))))))
+        indent))))))
 
 ;;;###autoload
 (defun comment-box (beg end &optional arg)




reply via email to

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