summaryrefslogtreecommitdiff
path: root/lisp/newcomment.el
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2014-03-18 08:06:33 +0200
committerDmitry Gutov <dgutov@yandex.ru>2014-03-18 08:06:33 +0200
commit2b7858ecbd57f16d0a20906dd792fd96049c5952 (patch)
tree8514ab26cdcaa7b1c20bef830438969bc94538ac /lisp/newcomment.el
parent1917cf46bba74cdd0bcd1d0545cbd688db4e76f9 (diff)
downloademacs-2b7858ecbd57f16d0a20906dd792fd96049c5952.tar.gz
Further tweaks for comment-start-skip behavior
* lisp/newcomment.el (comment-normalize-vars): Only add escaping check to `comment-start-skip' if not `comment-use-syntax'. (comment-beginning): Use `narrow-to-region' instead of moving back one character. (http://lists.gnu.org/archive/html/emacs-devel/2014-03/msg00488.html) (comment-start-skip): Update the docstring. Fixes: debbugs:16971
Diffstat (limited to 'lisp/newcomment.el')
-rw-r--r--lisp/newcomment.el21
1 files changed, 12 insertions, 9 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 44e270a66ea..2d798494b8b 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -120,8 +120,9 @@ Comments might be indented to a different value in order not to go beyond
;;;###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.")
+If there are any \\(...\\) pairs and `comment-use-syntax' is nil,
+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 'stringp)
@@ -378,7 +379,10 @@ function should first call this function explicitly."
;; In case comment-start has changed since last time.
(string-match comment-start-skip comment-start))
(set (make-local-variable 'comment-start-skip)
- (concat "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|"
+ (concat (unless (eq comment-use-syntax t)
+ ;; `syntax-ppss' will detect escaping.
+ "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)")
+ "\\(\\s<+\\|"
(regexp-quote (comment-string-strip comment-start t t))
;; Let's not allow any \s- but only [ \t] since \n
;; might be both a comment-end marker and \s-.
@@ -523,12 +527,11 @@ the same as `comment-search-backward'."
(when (nth 4 state)
(goto-char (nth 8 state))
(prog1 (point)
- (when (or (looking-at comment-start-skip)
- ;; Some older modes use regexps that check the
- ;; char before the comment for quoting. (Bug#16971)
- (save-excursion
- (forward-char -1)
- (looking-at comment-start-skip)))
+ (when (save-restriction
+ ;; `comment-start-skip' sometimes checks that the
+ ;; comment char is not escaped. (Bug#16971)
+ (narrow-to-region (point) (point-max))
+ (looking-at comment-start-skip))
(goto-char (match-end 0))))))
;; Can't rely on the syntax table, let's guess based on font-lock.
(unless (eq (get-text-property (point) 'face) 'font-lock-string-face)