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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Jun 05, 2015 at 05:29:36AM +0200, Björn Lindqvist wrote:
> 2015-06-05 0:11 GMT+02:00 Stefan Monnier <monnier@iro.umontreal.ca>:

[...]

> No. I want two strings, FOO and BAR (or ! doesn't matter, same
> principle) to start comments iff they are separate tokens.

Sorry to jump in the middle. I've been lurking in case I could help
(and to learn about font-lock).

Björn: you are assuming that everyone knows what's a "token" to you.
And you are assuming that everyone has the time to read and grasp
all your examples, first time. I for one don't know what your tokens
are. To put one extreme example, to C, the string 'a+b' are three
tokens, '++a' are two; for Lisp, the first and the second example are
both just *one* token.

Given that, you can't expect Stefan to even come near a regular expression
useful to you, since what they are doing is exactly *separate tokens*.

> > 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.

You mean when FOO is at the end of the line? Then no character would be
there and the second '[^ ] wouldn't match?

That's what Stefan said, you'll have to tweak this. Use an alternative '\|',
something like "\(^\|[^ ]\)!\([^ ]\|$\)" (i.e. match at beginning-of-line-
or-space, then "!" then space-or-end-of-line. You can use "\(?: ... \)
if you want non-capturing groups. Watch out for those backslashes: you
want to double them when writing them as an Elisp string [1].

> > Also it's likely that " !! " would also start
> > a comment [...]

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

See? we are all guessing at what your tokens are. Designing the
nitty-gritties of your regexps and testing them can only be your
work, because we'd be all fighting phantoms.

> > 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.

I don't understand you. What is this "test", where does it come from
and what is it doing *in* the regular expression? (and in which one:
in syntax-propertize rules, as in Stefan's example above, or somewhere
else?

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlVxR0wACgkQBcgs9XrR2kZXwwCdGe35a21eiwMqPmJ/xYmnjd5H
RK8AniLaRZ3iKcGU1ah3uAPeJNpERABf
=vTni
-----END PGP SIGNATURE-----



  reply	other threads:[~2015-06-05  6:53 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
2015-06-05  6:53             ` tomas [this message]
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=20150605065300.GA26971@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=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.