(vc-svn-registered): Catch all errors.
[bpt/emacs.git] / lisp / newcomment.el
index 120777a..938cd5f 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 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,7 +91,8 @@ 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
@@ -99,7 +101,8 @@ 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
@@ -201,7 +204,8 @@ INDENT specifies that the `comment-start' markers should not be put at the
 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,7 +215,8 @@ 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
@@ -222,7 +227,8 @@ 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)
+  :type 'boolean
+  :group 'comment)
 
 (defcustom comment-empty-lines nil
   "If nil, `comment-region' does not comment out empty lines.
@@ -231,7 +237,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
@@ -423,7 +430,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)
@@ -435,7 +442,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)
@@ -496,7 +503,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
@@ -936,9 +943,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
@@ -1087,10 +1098,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