help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Font-lock of comments using comment tokens, does it work?


From: Björn Lindqvist
Subject: Re: Font-lock of comments using comment tokens, does it work?
Date: Fri, 5 Jun 2015 21:37:16 +0200

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

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.


-- 
mvh/best regards Björn Lindqvist



reply via email to

[Prev in Thread] Current Thread [Next in Thread]