From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Font-lock of comments using comment tokens, does it work? Date: Thu, 04 Jun 2015 18:11:05 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1433456157 1577 80.91.229.3 (4 Jun 2015 22:15:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Jun 2015 22:15:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 05 00:15:57 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 1Z0dQH-0002kA-SO for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 00:15:38 +0200 Original-Received: from localhost ([::1]:44339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0dQH-0007SF-9l for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jun 2015 18:15:37 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Injection-Info: mx02.eternal-september.org; posting-host="7d373ed72892ee578c208d3ba2c61e92"; logging-data="1588"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+A7NCs1beabLVTAlzcE4je" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:mmH/+FEOipYOrePi7d/nnYdOnoQ= sha1:mqhPgsx955ZzFX+lDmswmN6ikjc= Original-Xref: usenet.stanford.edu gnu.emacs.help:212473 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:104758 Archived-At: >> 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. And you've marked "!" as a comment starter by default (i.e. in the mode's syntax-table), so you need to mark all "!" which are not surrounded by spaces as being not-comment-starters. 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? Of course, it'll still probably require more tweaking because I suspect that Ťall "!" which are not surrounded by spacesť is not actually a precise description of all cases that matter. E.g. I suspect that if the "!" is preceded by a newline (i.e. is at the beginning of a line) it should still be considered a comment starter. Same thing if it's preceded by a TAB. 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. One more thing: if "! as a normal char" is more common than "! as a comment starter", it might be worthwhile to take the opposite approach and define the syntax of "!" in the mode's syntax-table as being "_" and then in syntax-propertize-function mark those "!" which start a comment as having syntax "<". 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 "_"))) Stefan