Fix bug #14842 with doc strings of next-line and previous-line.
[bpt/emacs.git] / lisp / newcomment.el
index e10b96f..19a06bf 100644 (file)
@@ -446,7 +446,9 @@ in strings will not confuse Emacs.")
   "Find a comment start between point and LIMIT.
 Moves point to inside the comment and returns the position of the
 comment-starter.  If no comment is found, moves point to LIMIT
-and raises an error or returns nil if NOERROR is non-nil."
+and raises an error or returns nil if NOERROR is non-nil.
+
+Ensure that `comment-normalize-vars' has been called before you use this."
   (if (not comment-use-syntax)
       (if (re-search-forward comment-start-skip limit noerror)
          (or (match-end 1) (match-beginning 0))
@@ -484,30 +486,30 @@ and raises an error or returns nil if NOERROR is non-nil."
   "Find a comment start between LIMIT and point.
 Moves point to inside the comment and returns the position of the
 comment-starter.  If no comment is found, moves point to LIMIT
-and raises an error or returns nil if NOERROR is non-nil."
-  (let (found end)
-    (while (and (not found)
-               (re-search-backward comment-start-skip limit t))
-      (setq end (match-end 0))
-      (unless (and comment-use-syntax
-                  (nth 8 (syntax-ppss (or (match-end 1)
-                                          (match-beginning 0)))))
-       (setq found t)))
-    (if (not found)
-       (unless noerror (error "No comment"))
-      (beginning-of-line)
-      (let ((cs (comment-search-forward end t))
-           (pt (point)))
-       (if (not cs)
-           (progn (beginning-of-line)
-                  (comment-search-backward limit noerror))
-         (while (progn (goto-char cs)
-                       (comment-forward)
-                       (and (< (point) end)
-                            (setq cs (comment-search-forward end t))))
-           (setq pt (point)))
-         (goto-char pt)
-         cs)))))
+and raises an error or returns nil if NOERROR is non-nil.
+
+Ensure that `comment-normalize-vars' has been called before you use this."
+  ;; FIXME: If a comment-start appears inside a comment, we may erroneously
+  ;; stop there.  This can be rather bad in general, but since
+  ;; comment-search-backward is only used to find the comment-column (in
+  ;; comment-set-column) and to find the comment-start string (via
+  ;; comment-beginning) in indent-new-comment-line, it should be harmless.
+  (if (not (re-search-backward comment-start-skip limit t))
+      (unless noerror (error "No comment"))
+    (beginning-of-line)
+    (let* ((end (match-end 0))
+          (cs (comment-search-forward end t))
+          (pt (point)))
+      (if (not cs)
+         (progn (beginning-of-line)
+                (comment-search-backward limit noerror))
+       (while (progn (goto-char cs)
+                     (comment-forward)
+                     (and (< (point) end)
+                          (setq cs (comment-search-forward end t))))
+         (setq pt (point)))
+       (goto-char pt)
+       cs))))
 
 (defun comment-beginning ()
   "Find the beginning of the enclosing comment.