emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114486: * lisp/newcomment.el (comment-beginning): W


From: Dmitry Gutov
Subject: [Emacs-diffs] trunk r114486: * lisp/newcomment.el (comment-beginning): When `comment-use-syntax' is
Date: Tue, 01 Oct 2013 01:13:55 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114486
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15251
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Tue 2013-10-01 04:13:48 +0300
message:
  * lisp/newcomment.el (comment-beginning): When `comment-use-syntax' is
  non-nil, use `syntax-ppss'.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/newcomment.el             
newcomment.el-20091113204419-o5vbwnq5f7feedwu-1719
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-09-30 01:13:19 +0000
+++ b/lisp/ChangeLog    2013-10-01 01:13:48 +0000
@@ -1,3 +1,8 @@
+2013-10-01  Dmitry Gutov  <address@hidden>
+
+       * newcomment.el (comment-beginning): When `comment-use-syntax' is
+       non-nil, use `syntax-ppss' (Bug#15251).
+
 2013-09-30  RĂ¼diger Sonderfeld  <address@hidden>
 
        * progmodes/octave.el (inferior-octave-startup-file): Prefer

=== modified file 'lisp/newcomment.el'
--- a/lisp/newcomment.el        2013-06-18 17:57:56 +0000
+++ b/lisp/newcomment.el        2013-10-01 01:13:48 +0000
@@ -515,30 +515,36 @@
   "Find the beginning of the enclosing comment.
 Returns nil if not inside a comment, else moves point and returns
 the same as `comment-search-backward'."
-  ;; HACK ATTACK!
-  ;; We should really test `in-string-p' but that can be expensive.
-  (unless (eq (get-text-property (point) 'face) 'font-lock-string-face)
-    (let ((pt (point))
-         (cs (comment-search-backward nil t)))
-      (when cs
-       (if (save-excursion
-             (goto-char cs)
-             (and
-              ;; For modes where comment-start and comment-end are the same,
-              ;; the search above may have found a `ce' rather than a `cs'.
-              (or (if comment-end-skip (not (looking-at comment-end-skip)))
-                  ;; Maybe font-lock knows that it's a `cs'?
-                  (eq (get-text-property (match-end 0) 'face)
-                      'font-lock-comment-face)
-                  (unless (eq (get-text-property (point) 'face)
-                              'font-lock-comment-face)
-                    ;; 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)))))
+  (if comment-use-syntax
+      (let ((state (syntax-ppss)))
+        (when (nth 4 state)
+          (goto-char (nth 8 state))
+          (prog1 (point)
+            (when (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)
+      (let ((pt (point))
+            (cs (comment-search-backward nil t)))
+        (when cs
+          (if (save-excursion
+                (goto-char cs)
+                (and
+                 ;; For modes where comment-start and comment-end are the same,
+                 ;; the search above may have found a `ce' rather than a `cs'.
+                 (or (if comment-end-skip (not (looking-at comment-end-skip)))
+                     ;; Maybe font-lock knows that it's a `cs'?
+                     (eq (get-text-property (match-end 0) 'face)
+                         'font-lock-comment-face)
+                     (unless (eq (get-text-property (point) 'face)
+                                 'font-lock-comment-face)
+                       ;; 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)
   "Skip forward over N comments.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]