From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Bj=C3=B6rn_Lindqvist?= Newsgroups: gmane.emacs.help Subject: Re: Font-lock of comments using comment tokens, does it work? Date: Fri, 5 Jun 2015 05:29:36 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1433475006 12717 80.91.229.3 (5 Jun 2015 03:30:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Jun 2015 03:30:06 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 05 05:30:06 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 1Z0iKM-0002NX-EL for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 05:29:50 +0200 Original-Received: from localhost ([::1]:45127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0iKL-0006gj-JH for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jun 2015 23:29:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0iKB-0006gd-5h for help-gnu-emacs@gnu.org; Thu, 04 Jun 2015 23:29:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0iKA-0005mo-3N for help-gnu-emacs@gnu.org; Thu, 04 Jun 2015 23:29:39 -0400 Original-Received: from mail-wg0-x22c.google.com ([2a00:1450:400c:c00::22c]:36478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0iK9-0005mc-Sc for help-gnu-emacs@gnu.org; Thu, 04 Jun 2015 23:29:38 -0400 Original-Received: by wgbgq6 with SMTP id gq6so47016702wgb.3 for ; Thu, 04 Jun 2015 20:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=kHJEjxqqzgZMjK0caG9JxlcGOQzTNyMzwJ4ew1GpQck=; b=hjVMVW0RcTIdtCREGvelcuMZUZbMfFZnGQlLLFqpXUD9W9Y0GEdhRvJniy7DmnU+pQ qWrzbCf32YLGa17UcEJqAkqihIEvZLBvnFNH7g4jHBsu62+JNgVtNCWW5/1mx+xmvQfM iJhGMmGnfM4DtuZsflYzhp8OKwcCmc6ziNwcIj3nmm/oW1Yt4tYadCTHyai8vdeiofR4 Ch7A62vTsY14qE7gLRzh9bNGzyJtVi2SO7m+GwF0r0t2ofUBX7lD7QTW6ctPxU2umefS YlkTGxR9peiSKMwWlNKrIPQ5Hx/Yj5lUQxs9JOIUESEW16DfdZRPGxrjKLnoUG3nuNqr Hu5A== X-Received: by 10.181.27.131 with SMTP id jg3mr56804496wid.89.1433474976335; Thu, 04 Jun 2015 20:29:36 -0700 (PDT) Original-Received: by 10.194.24.167 with HTTP; Thu, 4 Jun 2015 20:29:36 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::22c 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:104761 Archived-At: 2015-06-05 0:11 GMT+02:00 Stefan Monnier : >>> 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 afterwa= rds. > >> ("\\(!\\)[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 =C2=ABall "!" which are not surroun= ded > by spaces=C2=BB would look like "[^ ]![^ ]". Have you tried something li= ke > 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. --=20 mvh/best regards Bj=C3=B6rn Lindqvist