Commit e9155c4a authored by Dmitry Gutov's avatar Dmitry Gutov
Browse files

* lisp/newcomment.el (comment-beginning): When `comment-use-syntax' is

non-nil, use `syntax-ppss'.

Fixes: debbugs:15251
parent 481a8e0f
2013-10-01 Dmitry Gutov <dgutov@yandex.ru>
* newcomment.el (comment-beginning): When `comment-use-syntax' is
non-nil, use `syntax-ppss' (Bug#15251).
2013-09-30 Rüdiger Sonderfeld <ruediger@c-plusplus.de> 2013-09-30 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
* progmodes/octave.el (inferior-octave-startup-file): Prefer * progmodes/octave.el (inferior-octave-startup-file): Prefer
......
...@@ -515,30 +515,36 @@ Ensure that `comment-normalize-vars' has been called before you use this." ...@@ -515,30 +515,36 @@ Ensure that `comment-normalize-vars' has been called before you use this."
"Find the beginning of the enclosing comment. "Find the beginning of the enclosing comment.
Returns nil if not inside a comment, else moves point and returns Returns nil if not inside a comment, else moves point and returns
the same as `comment-search-backward'." the same as `comment-search-backward'."
;; HACK ATTACK! (if comment-use-syntax
;; We should really test `in-string-p' but that can be expensive. (let ((state (syntax-ppss)))
(unless (eq (get-text-property (point) 'face) 'font-lock-string-face) (when (nth 4 state)
(let ((pt (point)) (goto-char (nth 8 state))
(cs (comment-search-backward nil t))) (prog1 (point)
(when cs (when (looking-at comment-start-skip)
(if (save-excursion (goto-char (match-end 0))))))
(goto-char cs) ;; Can't rely on the syntax table, let's guess based on font-lock.
(and (unless (eq (get-text-property (point) 'face) 'font-lock-string-face)
;; For modes where comment-start and comment-end are the same, (let ((pt (point))
;; the search above may have found a `ce' rather than a `cs'. (cs (comment-search-backward nil t)))
(or (if comment-end-skip (not (looking-at comment-end-skip))) (when cs
;; Maybe font-lock knows that it's a `cs'? (if (save-excursion
(eq (get-text-property (match-end 0) 'face) (goto-char cs)
'font-lock-comment-face) (and
(unless (eq (get-text-property (point) 'face) ;; For modes where comment-start and comment-end are the same,
'font-lock-comment-face) ;; the search above may have found a `ce' rather than a `cs'.
;; Let's assume it's a `cs' if we're on the same line. (or (if comment-end-skip (not (looking-at comment-end-skip)))
(>= (line-end-position) pt))) ;; Maybe font-lock knows that it's a `cs'?
;; Make sure that PT is not past the end of the comment. (eq (get-text-property (match-end 0) 'face)
(if (comment-forward 1) (> (point) pt) (eobp)))) 'font-lock-comment-face)
cs (unless (eq (get-text-property (point) 'face)
(goto-char pt) 'font-lock-comment-face)
nil))))) ;; Let's assume it's a `cs' if we're on the same line.
(>= (line-end-position) pt)))
;; Make sure that PT is not past the end of the comment.
(if (comment-forward 1) (> (point) pt) (eobp))))
cs
(goto-char pt)
nil))))))
(defun comment-forward (&optional n) (defun comment-forward (&optional n)
"Skip forward over N comments. "Skip forward over N comments.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment