bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#15251: 24.3.50; do-auto-fill "continues" comment from inside a strin


From: Andreas Röhler
Subject: bug#15251: 24.3.50; do-auto-fill "continues" comment from inside a string
Date: Sun, 29 Sep 2013 15:12:57 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0

Am 29.09.2013 05:59, schrieb Dmitry Gutov:
Dmitry Gutov <dgutov@yandex.ru> writes:

In certain conditions, if I press SPC, and a string on the current line
contains text matching `comment-start-skip', the filling is performed,
and the newly created line starts with a comment.

Examples (point is at |, fill-column is 70):

ruby-mode:

aa = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#{}a" a|

press SPC =>

aa = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#{}a"
                                 #a

js-mode:

aa = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa//a" aa|

press SPC =>

aa = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa//a"
//aa

I've tracked this to misbehaving `comment-beginning'. Since we start
outside of string, and the comment char(s) are inside the string on the
same line, the check comparing the face at point to
`font-lock-string-face' doesn't work.

And in ruby-mode's case, since interpolations use a different face, even
putting a similar guard to check at `cs' won't help.

As I see it, we either have to use `syntax-ppss' here, or trust
font-lock. The latter means not skipping other checks even if
`comment-end-skip' is defined and doesn't match at point, and also
only trusting "let's assume ... if we're on the same line" when
font-lock-mode is disabled.

How does this change look? Seems to work fine.

(As an aside, I'm having hard time understanding which search is
supposed to have set the match data used by `(match-end 0)' there. Is it
`comment-search-backward'? Or `(looking-at comment-end-skip)'?)

=== modified file 'lisp/newcomment.el'
--- lisp/newcomment.el  2013-06-18 17:57:56 +0000
+++ lisp/newcomment.el  2013-09-29 03:41:18 +0000
@@ -526,12 +526,13 @@
              (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'?
+               (if comment-end-skip (not (looking-at comment-end-skip)))
+              (or ;; 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)
+                  (unless (or (eq (get-text-property (point) 'face)
+                                   'font-lock-comment-face)
+                               font-lock-mode)
                     ;; 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.






Reading the face for detecting basic things like comment is terrible.
What did the author smoke when writing this ;)

BTW from my experience jumping to (nth 8 (syntax-ppss)) works well.









reply via email to

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