GNU bug report logs - #15251
24.3.50; do-auto-fill "continues" comment from inside a string

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dgutov <at> yandex.ru>

Date: Tue, 3 Sep 2013 01:28:01 UTC

Severity: normal

Found in version 24.3.50

Fixed in version 24.4

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#15251: 24.3.50; do-auto-fill "continues" comment from inside
 a string
Date: Sun, 29 Sep 2013 15:12:57 +0200
Am 29.09.2013 05:59, schrieb Dmitry Gutov:
> Dmitry Gutov <dgutov <at> 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.








This bug report was last modified 11 years and 233 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.