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 21:37:16 +0200 Message-ID: References: <20150605065300.GA26971@tuxteam.de> 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 1433533061 3758 80.91.229.3 (5 Jun 2015 19:37:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Jun 2015 19:37:41 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Stefan Monnier To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 05 21:37:40 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 1Z0xQo-0001Xo-1e for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 21:37:30 +0200 Original-Received: from localhost ([::1]:49298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0xQn-0005Eo-8E for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 15:37:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0xQd-0005Ei-0z for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 15:37:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0xQb-0007rt-Vr for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 15:37:18 -0400 Original-Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:35514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0xQb-0007rj-Oz for help-gnu-emacs@gnu.org; Fri, 05 Jun 2015 15:37:17 -0400 Original-Received: by wiga1 with SMTP id a1so30803657wig.0 for ; Fri, 05 Jun 2015 12:37:17 -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=tn6JYewEgPlj608kPfdqB5XW2L9RaWvEpL3wq0jWFHg=; b=KcG7/52dYvPsaRFB2KNYZDOjJOAzM8xFyqAIsx/QlgmbtZE7DMirMKHbxW5AwOzcLN FjWCDXBlZZcZ7JZsCoiilrJt2UzWbH4aee3CKMzlWuWml2JewCMTRwEFFY/7oUN5gByu ZsE6tK/S5PXuZve6nPtaCbpzrZT7Yq/DWG4a8iB6Z+Ml7rPZq0wlECYvsZyXwtm4h/RU UVIXuE5gKYbjGzoGk3vp/MJNe9zOBMhZtltppFq3n5d3POr3al0K5rXBYdZZRYnz5ATd b2aHRZWI95XChByLwJ9X0GFihw8Aog0OMSizuPilY47FyLHnmU+ejRvSx2CMFhiznC/t U8GA== X-Received: by 10.194.200.228 with SMTP id jv4mr8880039wjc.157.1433533036982; Fri, 05 Jun 2015 12:37:16 -0700 (PDT) Original-Received: by 10.194.24.167 with HTTP; Fri, 5 Jun 2015 12:37:16 -0700 (PDT) In-Reply-To: <20150605065300.GA26971@tuxteam.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::230 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:104774 Archived-At: >> 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=C3=B6rn: 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. It's not necessary to know what the tokenization rules for my language are to help me. Though the rules are very simple, each whitespace-separated sequence of characters is one token. But if you can just come up with the required syntax-propertize-rules and syntax table setup to make the first for lines of my example highlight as comments and the last for *not* highlight as comments, I would be happy with that: random code ,FOO random comment stuff ,BAR comment "with stuff" ,BAR FOO BAR ,FOO FOObar random come BARFOO random code random code xyFOOzw random code "with string FOO " etc ... Here I've added a comma to show where the start of the comment-face should be. The comma is not present in the output. You can even take this skeleton mode I wrote and just figure out what to write inside the regexp: (defun mm-syntax-propertize (start end) (funcall (syntax-propertize-rules ("WHAT HERE?" (1 "_"))) start end)) (defvar mm-mode-syntax-table (let ((table (make-syntax-table prog-mode-syntax-table))) (modify-syntax-entry ?\n "> " table) (modify-syntax-entry ?! "< " table) table)) (define-derived-mode mm-mode prog-mode "Foo" (setq-local font-lock-defaults '(())) (setq-local syntax-propertize-function 'mm-syntax-propertize)) Here "!" is the comment token, but I'm also trying to get it work for N arbitrary comment tokens. Also I've worked on this problem for a long time (check the date on my stackoverflow posting) and tried dozens of different approaches. So spitballing guesses (I've tried all guesses so far and many permutations of them and none have worked) or telling me to rtfm again is pointless. --=20 mvh/best regards Bj=C3=B6rn Lindqvist