From: Leo Liu Date: Fri, 17 May 2013 22:46:10 +0000 (+0800) Subject: * newcomment.el (comment-search-backward): Stricter in finding X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~229^2~46 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=42caeb895d159d7b3d32e5f4873b063b6759e244;p=emacs.git * newcomment.el (comment-search-backward): Stricter in finding comment start. * progmodes/octave.el (octave-comment-start): Remove the SPC char. (octave-comment-start-skip): Properly anchored. Fixes: debbugs:14303 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 12ae5239f13..f07354cfe5d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-05-17 Leo Liu + + * newcomment.el (comment-search-backward): Stricter in finding + comment start. (Bug#14303) + + * progmodes/octave.el (octave-comment-start): Remove the SPC char. + (octave-comment-start-skip): Properly anchored. + 2013-05-17 Leo Liu * emacs-lisp/smie.el (smie-highlight-matching-block-mode): Clean diff --git a/lisp/newcomment.el b/lisp/newcomment.el index bcb5f721ae8..e10b96f97f9 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -485,27 +485,29 @@ and raises an error or returns nil if NOERROR is non-nil." 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." - ;; 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)))) + (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))))) (defun comment-beginning () "Find the beginning of the enclosing comment. diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 451ac2791a7..26fb254af5f 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -62,12 +62,11 @@ Used in `octave-mode' and `inferior-octave-mode' buffers.") (defvar octave-comment-char ?# "Character to start an Octave comment.") -(defvar octave-comment-start - (string octave-comment-char ?\s) - "String to insert to start a new Octave in-line comment.") +(defvar octave-comment-start (char-to-string octave-comment-char) + "Octave-specific `comment-start' (which see).") -(defvar octave-comment-start-skip "\\(?:%!\\|\\s<+\\)\\s-*" - "Regexp to match the start of an Octave comment up to its body.") +(defvar octave-comment-start-skip "\\(^\\|\\S<\\)\\(?:%!\\|\\s<+\\)\\s-*" + "Octave-specific `comment-start-skip' (which see).") (defvar octave-begin-keywords '("classdef" "do" "enumeration" "events" "for" "function" "if" "methods"