[Top][All Lists]

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

Optionally (and correctly) match a group with font-lock

From: Sean Allred
Subject: Optionally (and correctly) match a group with font-lock
Date: Sun, 5 Apr 2015 12:53:32 -0500

Hello everyone,

Recently I’ve been seeing discussions on Emacs’ C sources and the fundamental 
aspects of elisp, but I hope asking for help is okay here, too :) I’m writing a 
mode for expl3, the programming layer that’s going to power LaTeX3. AUCTeX as 
very little support for it right now and I hope to have expl3-mode included at 
some point in the future, so this is at least a discussion of that development 

When I use the following, I cannot correctly match the test strings below. (For 
brevity, only the relevant portions have been included in this email.)

    (define-derived-mode expl3-mode prog-mode
      "Mode for editing expl3 source code."
      (setq font-lock-set-defaults nil)
       `((,(rx (* whitespace)
               (group (+ (any alnum "-")))
               (* whitespace)
               (optional "/" (* whitespace)
                         (group (+ any alnum "_")))
               (+ whitespace)
               (group "." (+ (any alpha)) (optional "_"))
               (group (optional (any alpha) (+ (any alpha "_"))))
               (group ":" (* (any "nNpTFwcVvxofD"))))
          (1 font-lock-variable-name-face t)
          (2 font-lock-variable-name-face t t)
          (3 font-lock-type-face t)
          (4 font-lock-function-name-face t)
          (5 font-lock-keyword-face t)))))

### Test strings

    test-key .tl_set:N ...
    with / grouping .code:n …

`test-key` matches correctly, but `with / grouping` does not. The `grouping` 
portion matches, but `with` is left out in the cold. Anybody know a good way to 
fix my regex for font-lock?

All the best,

(PS: this question has also been asked on Emacs.SE: 

reply via email to

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