Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:37:27+00:00 2026-06-16T00:37:27+00:00

I’m writing an emacs major mode for a programming environment which supports two slightly

  • 0

I’m writing an emacs major mode for a programming environment which supports two slightly different programming languages. Both are lisps (one is Scheme), so both use s-expressions. The two languages are differentiated by their function definition keyword: scheme uses define, while the other language (which is called xtlang) uses bind-func

So, in the same buffer, I have

(define foo        ; this is scheme
   (lambda (a)
      (+ scheme-fn a))

(bind-func bar     ; this is xtlang
   (lambda (b)
      (* xtlang-fn b))

I’ve got the font-locking working, using something like

(font-lock-add-keywords nil
                        '(("(\\(define\\)\\>"
                           (1 font-lock-keyword-face))
                          ("(\\(bind-func\\)\\>"
                           (1 font-lock-keyword-face))
                          ("\\<scheme-fn\\>"
                           (0 font-lock-function-name-face))
                          ("\\<xtlang-fn\\>"
                           (0 font-lock-function-name-face))
                          ))

What I’d like to be able to do is to be able to colour the parens differently based on the language (scheme/xtlang).

So, colour all the parens in the form red if the top-level defun is a define, and blue if it’s a bind-func, while still highlighting all the keywords/functions within the forms as normal.

This may require multi-line font locking, since the define/bind-func will probably be on a previous line to the keywords to be highlighted. This thread suggests that font-lock-multiline in conjunction with match-anchored in font-lock-keywords may be the answer, but then goes on to suggest that font-lock-multiline should only be used in situations where the multi-line aspect is the exception rather than the rule.

My other option seems to be to use syntax-propertize, but I’m a bit confused about how that works – the documentation is a bit sparse.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:37:27+00:00Added an answer on June 16, 2026 at 12:37 am

    The easiest way to handle this is utilizing the following fact:

    MATCHER can be either the regexp to search for, or the function name
    to call to make the search (called with one argument, the limit of the
    search;

    In other words, you could replace regexps like "\\<scheme-fn\\>" with a function that repeatedly search for the regexp using re-search-forward, and return if a match is found in the correct context.

    For a concrete example of a package that use this technique, look at cwarn-mode, which is part of the standard Emacs distribution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tracked down a weird MySQL problem to the two different ways I was
I am writing an app with both english and french support. The app requests
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.