]> code.delx.au - gnu-emacs/blobdiff - lisp/newcomment.el
(tildify-ignored-environments-alist): Recognize \verb* right.
[gnu-emacs] / lisp / newcomment.el
index 610831bcff09ec60d1d2f34605097b791f42b93e..9ddcda42769cc40e30d8700ea95510e8a082c0ff 100644 (file)
@@ -1,12 +1,11 @@
 ;;; newcomment.el --- (un)comment regions of buffers
 
-;; Copyright (C) 1999-2000  Free Software Foundation Inc.
+;; Copyright (C) 19992000  Free Software Foundation Inc.
 
 ;; Author: code extracted from Emacs-20's simple.el
 ;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
 ;; Keywords: comment uncomment
-;; Version: $Name:  $
-;; Revision: $Id: newcomment.el,v 1.25 2000/11/21 21:31:16 monnier Exp $
+;; Revision: $Id: newcomment.el,v 1.30 2001/02/22 01:47:40 monnier Exp $
 
 ;; This file is part of GNU Emacs.
 
@@ -234,7 +233,9 @@ This is obsolete because you might as well use \\[newline-and-indent]."
       (set (make-local-variable 'comment-start-skip)
           (concat "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|"
                   (regexp-quote (comment-string-strip comment-start t t))
-                  "+\\)\\s-*")))
+                  ;; Let's not allow any \s- but only [ \t] since \n
+                  ;; might be both a comment-end marker and \s-.
+                  "+\\)[ \t]*")))
     (unless comment-end-skip
       (let ((ce (if (string= "" comment-end) "\n"
                  (comment-string-strip comment-end t t))))
@@ -347,15 +348,18 @@ and raises an error or returns nil of NOERROR is non-nil."
   "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'."
-  (let ((pt (point))
-       (cs (comment-search-backward nil t)))
-    (when cs
-      (if (save-excursion
-           (goto-char cs)
-           (if (comment-forward 1) (> (point) pt) (eobp)))
-         cs
-       (goto-char pt)
-       nil))))
+  ;; 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)
+    (let ((pt (point))
+         (cs (comment-search-backward nil t)))
+      (when cs
+       (if (save-excursion
+             (goto-char cs)
+             (if (comment-forward 1) (> (point) pt) (eobp)))
+           cs
+         (goto-char pt)
+         nil)))))
 
 (defun comment-forward (&optional n)
   "Skip forward over N comments.
@@ -368,6 +372,7 @@ and can use regexps instead of syntax."
        (skip-syntax-forward " ")
        (setq n
              (if (and (looking-at comment-start-skip)
+                      (goto-char (match-end 0))
                       (re-search-forward comment-end-skip nil 'move))
                  (1- n) -1)))
       (= n 0))))
@@ -788,7 +793,7 @@ rather than at left margin."
 ;;;###autoload
 (defun comment-region (beg end &optional arg)
   "Comment or uncomment each line in the region.
-With just \\[universal-prefix] prefix arg, uncomment each line in region BEG..END.
+With just \\[universal-argument] prefix arg, uncomment each line in region BEG..END.
 Numeric prefix arg ARG means use ARG comment characters.
 If ARG is negative, delete that many comment characters instead.
 By default, comments start at the left margin, are terminated on each line,
@@ -864,7 +869,7 @@ end- comment markers additionally to what `comment-add' already specifies."
 (defun comment-dwim (arg)
   "Call the comment command you want (Do What I Mean).
 If the region is active and `transient-mark-mode' is on, call
-  `comment-region' (unless it only consists in comments, in which
+  `comment-region' (unless it only consists of comments, in which
   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'.
@@ -928,8 +933,7 @@ unless optional argument SOFT is non-nil."
                          (setq comin (point))))))
 
       ;; Now we know we should auto-fill.
-      (delete-region (progn (skip-chars-backward " \t") (point))
-                    (progn (skip-chars-forward  " \t") (point)))
+      (delete-horizontal-space)
       (if soft (insert-and-inherit ?\n) (newline 1))
       (if fill-prefix
          (progn