diff options
| author | Dmitry Gutov | 2013-10-01 04:13:48 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2013-10-01 04:13:48 +0300 |
| commit | e9155c4ae4fff20989e8ec0cfbe3c24036a897a3 (patch) | |
| tree | 0bd5db71575600e30178857a8c2f0a39bba2af1b | |
| parent | 481a8e0f453026bdb4ab3c81e783f17060d892b0 (diff) | |
| download | emacs-e9155c4ae4fff20989e8ec0cfbe3c24036a897a3.tar.gz emacs-e9155c4ae4fff20989e8ec0cfbe3c24036a897a3.zip | |
* lisp/newcomment.el (comment-beginning): When `comment-use-syntax' is
non-nil, use `syntax-ppss'.
Fixes: debbugs:15251
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/newcomment.el | 54 |
2 files changed, 35 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4eb0e7ec584..ab8c87fca97 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-10-01 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * newcomment.el (comment-beginning): When `comment-use-syntax' is | ||
| 4 | non-nil, use `syntax-ppss' (Bug#15251). | ||
| 5 | |||
| 1 | 2013-09-30 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> | 6 | 2013-09-30 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> |
| 2 | 7 | ||
| 3 | * progmodes/octave.el (inferior-octave-startup-file): Prefer | 8 | * progmodes/octave.el (inferior-octave-startup-file): Prefer |
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 19a06bfe8e5..3702b55f0aa 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -515,30 +515,36 @@ Ensure that `comment-normalize-vars' has been called before you use this." | |||
| 515 | "Find the beginning of the enclosing comment. | 515 | "Find the beginning of the enclosing comment. |
| 516 | Returns nil if not inside a comment, else moves point and returns | 516 | Returns nil if not inside a comment, else moves point and returns |
| 517 | the same as `comment-search-backward'." | 517 | the same as `comment-search-backward'." |
| 518 | ;; HACK ATTACK! | 518 | (if comment-use-syntax |
| 519 | ;; We should really test `in-string-p' but that can be expensive. | 519 | (let ((state (syntax-ppss))) |
| 520 | (unless (eq (get-text-property (point) 'face) 'font-lock-string-face) | 520 | (when (nth 4 state) |
| 521 | (let ((pt (point)) | 521 | (goto-char (nth 8 state)) |
| 522 | (cs (comment-search-backward nil t))) | 522 | (prog1 (point) |
| 523 | (when cs | 523 | (when (looking-at comment-start-skip) |
| 524 | (if (save-excursion | 524 | (goto-char (match-end 0)))))) |
| 525 | (goto-char cs) | 525 | ;; Can't rely on the syntax table, let's guess based on font-lock. |
| 526 | (and | 526 | (unless (eq (get-text-property (point) 'face) 'font-lock-string-face) |
| 527 | ;; For modes where comment-start and comment-end are the same, | 527 | (let ((pt (point)) |
| 528 | ;; the search above may have found a `ce' rather than a `cs'. | 528 | (cs (comment-search-backward nil t))) |
| 529 | (or (if comment-end-skip (not (looking-at comment-end-skip))) | 529 | (when cs |
| 530 | ;; Maybe font-lock knows that it's a `cs'? | 530 | (if (save-excursion |
| 531 | (eq (get-text-property (match-end 0) 'face) | 531 | (goto-char cs) |
| 532 | 'font-lock-comment-face) | 532 | (and |
| 533 | (unless (eq (get-text-property (point) 'face) | 533 | ;; For modes where comment-start and comment-end are the same, |
| 534 | 'font-lock-comment-face) | 534 | ;; the search above may have found a `ce' rather than a `cs'. |
| 535 | ;; Let's assume it's a `cs' if we're on the same line. | 535 | (or (if comment-end-skip (not (looking-at comment-end-skip))) |
| 536 | (>= (line-end-position) pt))) | 536 | ;; Maybe font-lock knows that it's a `cs'? |
| 537 | ;; Make sure that PT is not past the end of the comment. | 537 | (eq (get-text-property (match-end 0) 'face) |
| 538 | (if (comment-forward 1) (> (point) pt) (eobp)))) | 538 | 'font-lock-comment-face) |
| 539 | cs | 539 | (unless (eq (get-text-property (point) 'face) |
| 540 | (goto-char pt) | 540 | 'font-lock-comment-face) |
| 541 | nil))))) | 541 | ;; Let's assume it's a `cs' if we're on the same line. |
| 542 | (>= (line-end-position) pt))) | ||
| 543 | ;; Make sure that PT is not past the end of the comment. | ||
| 544 | (if (comment-forward 1) (> (point) pt) (eobp)))) | ||
| 545 | cs | ||
| 546 | (goto-char pt) | ||
| 547 | nil)))))) | ||
| 542 | 548 | ||
| 543 | (defun comment-forward (&optional n) | 549 | (defun comment-forward (&optional n) |
| 544 | "Skip forward over N comments. | 550 | "Skip forward over N comments. |