all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Björn Lindqvist" <bjourne@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Font-lock of comments using comment tokens, does it work?
Date: Fri, 5 Jun 2015 05:29:36 +0200	[thread overview]
Message-ID: <CALG+76cE-yyM7_87Kf-BMN-sE0G-cSZNOdUYuC3Wwbe9B=8ZsA@mail.gmail.com> (raw)
In-Reply-To: <jwvwpzjw33q.fsf-monnier+gnu.emacs.help@gnu.org>

2015-06-05 0:11 GMT+02:00 Stefan Monnier <monnier@iro.umontreal.ca>:
>>> Also, as Emacs maintainer I have enough experience/knowledge to fix
>>> most users's problems, but if I do that I'll just end up with more
>>> users with new problems to fix.  So instead I'm better off trying to
>>> train them so they can fix their problems themselves and even help me
>>> improve Emacs.
>>>> I've tried a dozen different permutations of the regexp and none of
>>>> them produces the desired result.
>>> What have you tried?  What/where were the undesired results?
>
>> ("[a-zA-Z0-9_]\\(! \\) " (1 "_")))
>
> IIUC you want all "!" that are surrounded by spaces to be treated as
> comment starters.

No. I want two strings, FOO and BAR (or ! doesn't matter, same
principle) to start comments iff they are separate tokens. Look at my
examples if the definition isn't so precise. FOO written at the top of
the buffer and followed by a newline would therefore start a comment.

> The above regexp does part of the work, but only does it for those "!"
> which are preceded by a latin letter or a number and are followed by
> a space.  E.g. it will fail on those "!" which don't have a space afterwards.
>
>> ("\\(!\\)[a-zA-Z0-9_]" (1 "_")))
>
> This one will fail on those "!" which are followed with a letter that's
> neither a space nor a latin letter nor a number.  And it will fail on
> those "!" which are followed by a space but are not preceded by a space.
>
> To me, the translation into regexp of «all "!" which are not surrounded
> by spaces» would look like "[^ ]![^ ]".  Have you tried something like
> that?

That turns the comment face of if the ! is in the middle, but not if
it prefixes or suffixes the token. abcFOO is wrongly interpreted as a
comment starter.

> Also it's likely that " !! " would also start
> a comment, so "followed by a space" is too strict as well.  But then,
> I don't know if " !!a" would be treated as starting a comment.
> IOW, maybe you'll want something like "[^ \n\t]\\(!+\\)[^
> \t\n]" instead.

No. In "!!" and "!!a" the comment token is not separate, so no comment.

> Yet another thing: if you have trouble catching all cases with a single
> regexp, you can use more rules, as in
>
>    (syntax-propertize-rules
>     ("[a-zA-Z0-9_]\\(! \\) " (1 "_"))
>     ("\\(!\\)[a-zA-Z0-9_]" (1 "_")))

It still messes up the comment font-locking. BTW I've noticed that if
the regexp is "test\\(!\\)" emacs correctly does not use comment face
on "test!". But if it is "\\(!\\)test" then "!test" is still seen as a
comment. That is inconsistent with what you have explained and the
elisp manual. So I think it is a bug.


-- 
mvh/best regards Björn Lindqvist



  reply	other threads:[~2015-06-05  3:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4238.1433357678.904.help-gnu-emacs@gnu.org>
2015-06-03 19:11 ` Font-lock of comments using comment tokens, does it work? Stefan Monnier
2015-06-03 23:37   ` Björn Lindqvist
     [not found]   ` <mailman.4244.1433374628.904.help-gnu-emacs@gnu.org>
2015-06-04  3:42     ` Stefan Monnier
2015-06-04 11:10       ` Björn Lindqvist
     [not found]       ` <mailman.4276.1433416248.904.help-gnu-emacs@gnu.org>
2015-06-04 22:11         ` Stefan Monnier
2015-06-05  3:29           ` Björn Lindqvist [this message]
2015-06-05  6:53             ` tomas
2015-06-05 19:37               ` Björn Lindqvist
2015-06-07  3:58                 ` Björn Lindqvist
2015-06-07 11:34                   ` tomas
2015-06-03 16:46 Björn Lindqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALG+76cE-yyM7_87Kf-BMN-sE0G-cSZNOdUYuC3Wwbe9B=8ZsA@mail.gmail.com' \
    --to=bjourne@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.