]> code.delx.au - gnu-emacs/blobdiff - lisp/newcomment.el
(add-to-history): New function.
[gnu-emacs] / lisp / newcomment.el
index 22713f87a968903888cd5d2c58dd45899cfc4ef3..d5a2cea914afd534453cf613d36c97b8705b46cf 100644 (file)
@@ -1,9 +1,10 @@
 ;;; newcomment.el --- (un)comment regions of buffers
 
-;; Copyright (C) 1999,2000,2003,2004  Free Software Foundation Inc.
+;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: code extracted from Emacs-20's simple.el
-;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
+;; Maintainer: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: comment uncomment
 
 ;; This file is part of GNU Emacs.
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -90,36 +91,42 @@ Major modes should set this variable.")
 
 (defcustom comment-fill-column nil
   "Column to use for `comment-indent'.  If nil, use `fill-column' instead."
-  :type '(choice (const nil) integer))
+  :type '(choice (const nil) integer)
+  :group 'comment)
 
 ;;;###autoload
 (defcustom comment-column 32
-  "*Column to indent right-margin comments to.
+  "Column to indent right-margin comments to.
 Each mode establishes a different default value for this variable; you
 can set the value for a particular mode using that mode's hook.
 Comments might be indented to a value smaller than this in order
 not to go beyond `comment-fill-column'."
-  :type 'integer)
+  :type 'integer
+  :group 'comment)
 (make-variable-buffer-local 'comment-column)
 
 ;;;###autoload
 (defvar comment-start nil
   "*String to insert to start a new comment, or nil if no comment syntax.")
+;;;###autoload(put 'comment-start 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-start-skip nil
   "*Regexp to match the start of a comment plus everything up to its body.
 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
 at the place matched by the close of the first pair.")
+;;;###autoload(put 'comment-start-skip 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-end-skip nil
   "Regexp to match the end of a comment plus everything up to its body.")
+;;;###autoload(put 'comment-end-skip 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-end ""
   "*String to insert to end a new comment.
 Should be an empty string if comments are terminated by end-of-line.")
+;;;###autoload(put 'comment-end 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-indent-function 'comment-indent-default
@@ -137,7 +144,7 @@ The function has no args.
 Applicable at least in modes for languages like fixed-format Fortran where
 comments always start in column zero.")
 
-(defvar comment-region-function nil
+(defvar comment-region-function 'comment-region-default
   "Function to comment a region.
 Its args are the same as those of `comment-region', but BEG and END are
 guaranteed to be correctly ordered.  It is called within `save-excursion'.
@@ -145,7 +152,7 @@ guaranteed to be correctly ordered.  It is called within `save-excursion'.
 Applicable at least in modes for languages like fixed-format Fortran where
 comments always start in column zero.")
 
-(defvar uncomment-region-function nil
+(defvar uncomment-region-function 'uncomment-region-default
   "Function to uncomment a region.
 Its args are the same as those of `uncomment-region', but BEG and END are
 guaranteed to be correctly ordered.  It is called within `save-excursion'.
@@ -197,11 +204,12 @@ INDENT specifies that the `comment-start' markers should not be put at the
 
 ;;;###autoload
 (defcustom comment-style 'plain
-  "*Style to be used for `comment-region'.
+  "Style to be used for `comment-region'.
 See `comment-styles' for a list of available styles."
   :type (if (boundp 'comment-styles)
            `(choice ,@(mapcar (lambda (s) `(const ,(car s))) comment-styles))
-         'symbol))
+         'symbol)
+  :group 'comment)
 
 ;;;###autoload
 (defcustom comment-padding " "
@@ -211,13 +219,20 @@ of the corresponding number of spaces.
 
 Extra spacing between the comment characters and the comment text
 makes the comment easier to read.  Default is 1.  nil means 0."
-  :type '(choice string integer (const nil)))
+  :type '(choice string integer (const nil))
+  :group 'comment)
 
 ;;;###autoload
 (defcustom comment-multi-line nil
-  "*Non-nil means \\[comment-indent-new-line] continues comments, with no new terminator or starter.
-This is obsolete because you might as well use \\[newline-and-indent]."
-  :type 'boolean)
+  "Non-nil means `comment-indent-new-line' continues comments.
+That is, it inserts no new terminator or starter.
+This affects `auto-fill-mode', which is the main reason to
+customize this variable.
+
+It also affects \\[indent-new-comment-line].  However, if you want this
+behavior for explicit filling, you might as well use \\[newline-and-indent]."
+  :type 'boolean
+  :group 'comment)
 
 (defcustom comment-empty-lines nil
   "If nil, `comment-region' does not comment out empty lines.
@@ -226,7 +241,8 @@ if `eol' it only comments out empty lines if comments are
 terminated by the end of line (i.e. `comment-end' is empty)."
   :type '(choice (const :tag "Never" nil)
          (const :tag "Always" t)
-         (const :tag "EOl-terminated" 'eol)))
+         (const :tag "EOl-terminated" 'eol))
+  :group 'comment)
 
 ;;;;
 ;;;; Helpers
@@ -368,12 +384,12 @@ and raises an error or returns nil if NOERROR is non-nil."
                                  (if comment-use-global-state (syntax-ppss pt))
                                  t)))
       (when (and (nth 8 s) (nth 3 s) (not comment-use-global-state))
-         ;; The search ended inside a string.  Try to see if it
-         ;; works better when we assume that pt is inside a string.
-         (setq s (parse-partial-sexp
-                  pt (or limit (point-max)) nil nil
-                  (list nil nil nil (nth 3 s) nil nil nil nil)
-                  t)))
+       ;; The search ended at eol inside a string.  Try to see if it
+       ;; works better when we assume that pt is inside a string.
+       (setq s (parse-partial-sexp
+                pt (or limit (point-max)) nil nil
+                (list nil nil nil (nth 3 s) nil nil nil nil)
+                t)))
       (if (not (and (nth 8 s) (not (nth 3 s))))
          (unless noerror (error "No comment"))
        ;; We found the comment.
@@ -418,7 +434,7 @@ and raises an error or returns nil if NOERROR is non-nil."
 (defun comment-beginning ()
   "Find the beginning of the enclosing comment.
 Returns nil if not inside a comment, else moves point and returns
-the same as `comment-search-forward'."
+the same as `comment-search-backward'."
   ;; HACK ATTACK!
   ;; We should really test `in-string-p' but that can be expensive.
   (unless (eq (get-text-property (point) 'face) 'font-lock-string-face)
@@ -430,7 +446,7 @@ the same as `comment-search-forward'."
              (and
               ;; For modes where comment-start and comment-end are the same,
               ;; the search above may have found a `ce' rather than a `cs'.
-              (or (not (looking-at comment-end-skip))
+              (or (if comment-end-skip (not (looking-at comment-end-skip)))
                   ;; Maybe font-lock knows that it's a `cs'?
                   (eq (get-text-property (match-end 0) 'face)
                       'font-lock-comment-face)
@@ -466,19 +482,22 @@ Point is assumed to be just at the end of a comment."
   (if (bolp)
       ;; comment-end = ""
       (progn (backward-char) (skip-syntax-backward " "))
-    (let ((end (point)))
-      (beginning-of-line)
-      (save-restriction
-       (narrow-to-region (point) end)
-       (if (re-search-forward (concat comment-end-skip "\\'") nil t)
-           (goto-char (match-beginning 0))
-         ;; comment-end-skip not found probably because it was not set right.
-         ;; Since \\s> should catch the single-char case, we'll blindly
-         ;; assume we're at the end of a two-char comment-end.
-         (goto-char (point-max))
-         (backward-char 2)
-         (skip-chars-backward (string (char-after)))
-         (skip-syntax-backward " "))))))
+    (cond
+     ((save-restriction
+        (narrow-to-region (line-beginning-position) (point))
+        (goto-char (point-min))
+        (re-search-forward (concat comment-end-skip "\\'") nil t))
+      (goto-char (match-beginning 0)))
+     ;; comment-end-skip not found.  Maybe we're at EOB which implicitly
+     ;; closes the comment.
+     ((eobp) (skip-syntax-backward " "))
+     (t
+      ;; else comment-end-skip was not found probably because it was not
+      ;; set right.  Since \\s> should catch the single-char case, we'll
+      ;; blindly assume we're at the end of a two-char comment-end.
+      (backward-char 2)
+      (skip-chars-backward (string (char-after)))
+      (skip-syntax-backward " ")))))
 
 ;;;;
 ;;;; Commands
@@ -491,7 +510,7 @@ Point is assumed to be just at the end of a comment."
           (or (match-end 1) (/= (current-column) (current-indentation))))
       0
     (when (or (/= (current-column) (current-indentation))
-             (and (> comment-add 0) (looking-at "\\s<\\S<")))
+             (and (> comment-add 0) (looking-at "\\s<\\(\\S<\\|\\'\\)")))
       comment-column)))
 
 ;;;###autoload
@@ -710,100 +729,108 @@ comment markers."
   (interactive "*r\nP")
   (comment-normalize-vars)
   (when (> beg end) (setq beg (prog1 end (setq end beg))))
-  (save-excursion
-    (if uncomment-region-function
-       (funcall uncomment-region-function beg end arg)
-      (goto-char beg)
-      (setq end (copy-marker end))
-      (let* ((numarg (prefix-numeric-value arg))
-            (ccs comment-continue)
-            (srei (comment-padright ccs 're))
-            (csre (comment-padright comment-start 're))
-            (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
-            spt)
-       (while (and (< (point) end)
-                   (setq spt (comment-search-forward end t)))
-         (let ((ipt (point))
-               ;; Find the end of the comment.
-               (ept (progn
-                      (goto-char spt)
-                      (unless (or (comment-forward)
-                                  ;; Allow non-terminated comments.
-                                  (eobp))
-                        (error "Can't find the comment end"))
-                      (point)))
-               (box nil)
-               (box-equal nil)) ;Whether we might be using `=' for boxes.
-           (save-restriction
-             (narrow-to-region spt ept)
-
-             ;; Remove the comment-start.
-             (goto-char ipt)
-           (skip-syntax-backward " ")
-           ;; A box-comment starts with a looong comment-start marker.
-           (when (and (or (and (= (- (point) (point-min)) 1)
-                               (setq box-equal t)
-                               (looking-at "=\\{7\\}")
-                               (not (eq (char-before (point-max)) ?\n))
-                               (skip-chars-forward "="))
-                          (> (- (point) (point-min) (length comment-start)) 7))
-                      (> (count-lines (point-min) (point-max)) 2))
-             (setq box t))
-           ;; Skip the padding.  Padding can come from comment-padding and/or
-           ;; from comment-start, so we first check comment-start.
-           (if (or (save-excursion (goto-char (point-min)) (looking-at csre))
-                   (looking-at (regexp-quote comment-padding)))
-               (goto-char (match-end 0)))
-           (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
+  ;; Bind `comment-use-global-state' to nil.  While uncommenting a region
+  ;; (which works a line at a time), a comment can appear to be
+  ;; included in a mult-line string, but it is actually not.
+  (let ((comment-use-global-state nil))
+    (save-excursion
+      (funcall uncomment-region-function beg end arg))))
+
+(defun uncomment-region-default (beg end &optional arg)
+  "Uncomment each line in the BEG .. END region.
+The numeric prefix ARG can specify a number of chars to remove from the
+comment markers."
+  (goto-char beg)
+  (setq end (copy-marker end))
+  (let* ((numarg (prefix-numeric-value arg))
+        (ccs comment-continue)
+        (srei (comment-padright ccs 're))
+        (csre (comment-padright comment-start 're))
+        (sre (and srei (concat "^\\s-*?\\(" srei "\\)")))
+        spt)
+    (while (and (< (point) end)
+               (setq spt (comment-search-forward end t)))
+      (let ((ipt (point))
+           ;; Find the end of the comment.
+           (ept (progn
+                  (goto-char spt)
+                  (unless (or (comment-forward)
+                              ;; Allow non-terminated comments.
+                              (eobp))
+                    (error "Can't find the comment end"))
+                  (point)))
+           (box nil)
+           (box-equal nil))       ;Whether we might be using `=' for boxes.
+       (save-restriction
+         (narrow-to-region spt ept)
+               
+         ;; Remove the comment-start.
+         (goto-char ipt)
+         (skip-syntax-backward " ")
+         ;; A box-comment starts with a looong comment-start marker.
+         (when (and (or (and (= (- (point) (point-min)) 1)
+                             (setq box-equal t)
+                             (looking-at "=\\{7\\}")
+                             (not (eq (char-before (point-max)) ?\n))
+                             (skip-chars-forward "="))
+                        (> (- (point) (point-min) (length comment-start)) 7))
+                    (> (count-lines (point-min) (point-max)) 2))
+           (setq box t))
+         ;; Skip the padding.  Padding can come from comment-padding and/or
+         ;; from comment-start, so we first check comment-start.
+         (if (or (save-excursion (goto-char (point-min)) (looking-at csre))
+                 (looking-at (regexp-quote comment-padding)))
              (goto-char (match-end 0)))
-           (if (null arg) (delete-region (point-min) (point))
-             (skip-syntax-backward " ")
-                 (delete-char (- numarg))
-                 (unless (or (bobp)
-                             (save-excursion (goto-char (point-min))
-                                             (looking-at comment-start-skip)))
-                   ;; If there's something left but it doesn't look like
-                   ;; a comment-start any more, just remove it.
-                   (delete-region (point-min) (point))))
-
-               ;; Remove the end-comment (and leading padding and such).
-               (goto-char (point-max)) (comment-enter-backward)
-               ;; Check for special `=' used sometimes in comment-box.
-               (when (and box-equal (not (eq (char-before (point-max)) ?\n)))
-                 (let ((pos (point)))
-                   ;; skip `=' but only if there are at least 7.
-                   (when (> (skip-chars-backward "=") -7) (goto-char pos))))
-               (unless (looking-at "\\(\n\\|\\s-\\)*\\'")
-                 (when (and (bolp) (not (bobp))) (backward-char))
-                 (if (null arg) (delete-region (point) (point-max))
-                   (skip-syntax-forward " ")
-                   (delete-char numarg)
-                   (unless (or (eobp) (looking-at comment-end-skip))
-                     ;; If there's something left but it doesn't look like
-                     ;; a comment-end any more, just remove it.
-                     (delete-region (point) (point-max)))))
-
-               ;; Unquote any nested end-comment.
-               (comment-quote-nested comment-start comment-end t)
-
-               ;; Eliminate continuation markers as well.
-               (when sre
-                 (let* ((cce (comment-string-reverse (or comment-continue
-                                                         comment-start)))
-                        (erei (and box (comment-padleft cce 're)))
-                        (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
-                   (goto-char (point-min))
-                   (while (progn
-                            (if (and ere (re-search-forward
-                                          ere (line-end-position) t))
-                                (replace-match "" t t nil (if (match-end 2) 2 1))
-                              (setq ere nil))
-                            (forward-line 1)
-                            (re-search-forward sre (line-end-position) t))
-                     (replace-match "" t t nil (if (match-end 2) 2 1)))))
-               ;; Go to the end for the next comment.
-               (goto-char (point-max)))))))
-      (set-marker end nil)))
+         (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
+           (goto-char (match-end 0)))
+         (if (null arg) (delete-region (point-min) (point))
+           (skip-syntax-backward " ")
+           (delete-char (- numarg))
+           (unless (or (bobp)
+                       (save-excursion (goto-char (point-min))
+                                       (looking-at comment-start-skip)))
+             ;; If there's something left but it doesn't look like
+             ;; a comment-start any more, just remove it.
+             (delete-region (point-min) (point))))
+               
+         ;; Remove the end-comment (and leading padding and such).
+         (goto-char (point-max)) (comment-enter-backward)
+         ;; Check for special `=' used sometimes in comment-box.
+         (when (and box-equal (not (eq (char-before (point-max)) ?\n)))
+           (let ((pos (point)))
+             ;; skip `=' but only if there are at least 7.
+             (when (> (skip-chars-backward "=") -7) (goto-char pos))))
+         (unless (looking-at "\\(\n\\|\\s-\\)*\\'")
+           (when (and (bolp) (not (bobp))) (backward-char))
+           (if (null arg) (delete-region (point) (point-max))
+             (skip-syntax-forward " ")
+             (delete-char numarg)
+             (unless (or (eobp) (looking-at comment-end-skip))
+               ;; If there's something left but it doesn't look like
+               ;; a comment-end any more, just remove it.
+               (delete-region (point) (point-max)))))
+
+         ;; Unquote any nested end-comment.
+         (comment-quote-nested comment-start comment-end t)
+
+         ;; Eliminate continuation markers as well.
+         (when sre
+           (let* ((cce (comment-string-reverse (or comment-continue
+                                                   comment-start)))
+                  (erei (and box (comment-padleft cce 're)))
+                  (ere (and erei (concat "\\(" erei "\\)\\s-*$"))))
+             (goto-char (point-min))
+             (while (progn
+                      (if (and ere (re-search-forward
+                                    ere (line-end-position) t))
+                          (replace-match "" t t nil (if (match-end 2) 2 1))
+                        (setq ere nil))
+                      (forward-line 1)
+                      (re-search-forward sre (line-end-position) t))
+               (replace-match "" t t nil (if (match-end 2) 2 1)))))
+         ;; Go to the end for the next comment.
+         (goto-char (point-max))))))
+  (set-marker end nil))
 
 (defun comment-make-extra-lines (cs ce ccs cce min-indent max-indent &optional block)
   "Make the leading and trailing extra lines.
@@ -872,6 +899,11 @@ indentation to be kept as it was before narrowing."
                   (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.
@@ -923,9 +955,13 @@ the region rather than at left margin."
                (setq max-indent (max max-indent (current-column)))
                (not (or (eobp) (progn (forward-line) nil)))))
 
-         ;; Inserting ccs can change max-indent by (1- tab-width).
          (setq max-indent
-               (+ max-indent (max (length cs) (length ccs)) tab-width -1))
+               (+ max-indent (max (length cs) (length ccs))
+                   ;; Inserting ccs can change max-indent by (1- tab-width)
+                   ;; but only if there are TABs in the boxed text, of course.
+                   (if (save-excursion (goto-char beg)
+                                       (search-forward "\t" end t))
+                       (1- tab-width) 0)))
          (unless indent (setq min-indent 0))
 
          ;; make the leading and trailing lines if requested
@@ -966,59 +1002,59 @@ The strings used as comment starts are built from
   (interactive "*r\nP")
   (comment-normalize-vars)
   (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
+  (save-excursion
+    ;; FIXME: maybe we should call uncomment depending on ARG.
+    (funcall comment-region-function beg end arg)))
+
+(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))
         (multi (nth 0 style)))
-    (save-excursion
-      (if comment-region-function
-         (funcall comment-region-function beg end arg)
-       ;; we use `chars' instead of `syntax' because `\n' might be
-       ;; of end-comment syntax rather than of whitespace syntax.
-       ;; sanitize BEG and END
-       (goto-char beg) (skip-chars-forward " \t\n\r") (beginning-of-line)
-       (setq beg (max beg (point)))
-       (goto-char end) (skip-chars-backward " \t\n\r") (end-of-line)
-       (setq end (min end (point)))
-       (if (>= beg end) (error "Nothing to comment"))
-
-       ;; sanitize LINES
-       (setq lines
-             (and
-              lines ;; multi
-              (progn (goto-char beg) (beginning-of-line)
-                     (skip-syntax-forward " ")
-                     (>= (point) beg))
-              (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
-                     (<= (point) end))
-              (or block (not (string= "" comment-end)))
-              (or block (progn (goto-char beg) (search-forward "\n" end t))))))
-
-      ;; don't add end-markers just because the user asked for `block'
-      (unless (or lines (string= "" comment-end)) (setq block nil))
-
-      (cond
-       ((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)))
-       (comment-region-internal
-        beg end
-        (let ((s (comment-padright comment-start numarg)))
-          (if (string-match comment-start-skip s) s
-            (comment-padright comment-start)))
-        (let ((s (comment-padleft comment-end numarg)))
-          (and s (if (string-match comment-end-skip s) s
-                   (comment-padright comment-end))))
-        (if multi (comment-padright comment-continue numarg))
-        (if multi
-            (comment-padleft (comment-string-reverse comment-continue) numarg))
-        block
-        lines
-        (nth 3 style)))))))
+    ;; we use `chars' instead of `syntax' because `\n' might be
+    ;; of end-comment syntax rather than of whitespace syntax.
+    ;; sanitize BEG and END
+    (goto-char beg) (skip-chars-forward " \t\n\r") (beginning-of-line)
+    (setq beg (max beg (point)))
+    (goto-char end) (skip-chars-backward " \t\n\r") (end-of-line)
+    (setq end (min end (point)))
+    (if (>= beg end) (error "Nothing to comment"))
+
+    ;; sanitize LINES
+    (setq lines
+         (and
+          lines ;; multi
+          (progn (goto-char beg) (beginning-of-line)
+                 (skip-syntax-forward " ")
+                 (>= (point) beg))
+          (progn (goto-char end) (end-of-line) (skip-syntax-backward " ")
+                 (<= (point) end))
+          (or block (not (string= "" comment-end)))
+          (or block (progn (goto-char beg) (search-forward "\n" end t)))))
+
+    ;; don't add end-markers just because the user asked for `block'
+    (unless (or lines (string= "" comment-end)) (setq block nil))
+
+    (cond
+     ((consp arg) (uncomment-region beg end))
+     ((< numarg 0) (uncomment-region beg end (- numarg)))
+     (t
+      (setq numarg (comment-add arg))
+      (comment-region-internal
+       beg end
+       (let ((s (comment-padright comment-start numarg)))
+        (if (string-match comment-start-skip s) s
+          (comment-padright comment-start)))
+       (let ((s (comment-padleft comment-end numarg)))
+        (and s (if (string-match comment-end-skip s) s
+                 (comment-padright comment-end))))
+       (if multi (comment-padright comment-continue numarg))
+       (if multi
+          (comment-padleft (comment-string-reverse comment-continue) numarg))
+       block
+       lines
+       (nth 3 style))))))
 
 (defun comment-box (beg end &optional arg)
   "Comment out the BEG .. END region, putting it inside a box.
@@ -1052,7 +1088,8 @@ If the region is active and `transient-mark-mode' is on, call
   case it calls `uncomment-region').
 Else, if the current line is empty, insert a comment and indent it.
 Else if a prefix ARG is specified, call `comment-kill'.
-Else, call `comment-indent'."
+Else, call `comment-indent'.
+You can configure `comment-style' to change the way regions are commented."
   (interactive "*P")
   (comment-normalize-vars)
   (if (and mark-active transient-mark-mode)
@@ -1061,9 +1098,8 @@ Else, call `comment-indent'."
        ;; 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))))
-       ;; Some modes insist on keeping column 0 comment in column 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)
        (insert (comment-padright comment-start add))
@@ -1072,10 +1108,12 @@ Else, call `comment-indent'."
            (insert (comment-padleft comment-end add)))
          (indent-according-to-mode))))))
 
+;;;###autoload
 (defcustom comment-auto-fill-only-comments nil
   "Non-nil means to only auto-fill inside comments.
 This has no effect in modes that do not define a comment syntax."
-  :type 'boolean)
+  :type 'boolean
+  :group 'comment)
 
 (defun comment-valid-prefix-p (prefix compos)
   (or
@@ -1193,5 +1231,5 @@ unless optional argument SOFT is non-nil."
 
 (provide 'newcomment)
 
-;;; arch-tag: 01e3320a-00c8-44ea-a696-8f8e7354c858
+;; arch-tag: 01e3320a-00c8-44ea-a696-8f8e7354c858
 ;;; newcomment.el ends here