From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Font-lock of comments using comment tokens, does it work? Date: Fri, 5 Jun 2015 08:53:00 +0200 Message-ID: <20150605065300.GA26971@tuxteam.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1433487268 23685 80.91.229.3 (5 Jun 2015 06:54:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Jun 2015 06:54:28 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Stefan Monnier To: =?iso-8859-1?Q?Bj=F6rn?= Lindqvist Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 05 08:54:13 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z0lVN-0005LG-V9 for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 08:53:26 +0200 Original-Received: from localhost ([::1]:45547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0lVN-0002GU-9o for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 02:53:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0lVD-0002GO-IA for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 02:53:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0lV8-0001kY-Nb for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 02:53:15 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:49711 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0lV8-0001jZ-IG for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 02:53:10 -0400 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1Z0lUy-0007Gp-PE; Fri, 05 Jun 2015 08:53:00 +0200 In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104763 Archived-At: -----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 : [...] > 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-----