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

  • Home
  • SEARCH
  • 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 9229773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:39:19+00:00 2026-06-18T05:39:19+00:00

Basically, I’m trying to syntax highlight the following piece of coffeescript code the way

  • 0

Basically, I’m trying to syntax highlight the following piece of coffeescript code the way I want it. Explanation of the syntax of coffeescript functions can be found here.

nameHere = (tstamp, moo, boo) ->
    ...

The names tstamp, moo and boo should be colored pink (and nothing else, not the commas and not the brackets) because they are parameters to a lambda function.

highOrderFun ((x) -> x * x) someList

Here it is the first x that is the parameter. Parameters can have default arguments:

class Foo
    meth: (msg = "Hello", bar = "foo") ->
        ....

Default arguments can be variables themselves:

defColor = "red"
print = (msg, color = defColor) ->
    ...

So msg and color above should be highlighted, but not defColor. An even trickier case is functions with default arguments that themselves are functions. I think that is to hard for emacs’ font-lock to highlight correctly, but I’m including it anyway:

funTakingFuns = (f1 = ((a, b) -> a*b), f2 = ((c, d) -> c/d)) ->
    ...

This appears to be pretty complicated to achieve in emacs because you want the highlighting to be context sensitive. I’ve read up on the documentation on font-lock but haven’t been able to figure it out.

I’d be grateful if someone could show me what to set font-lock-defaults to make it syntax highlight the way I want it.

Update Showing more coffeescript syntax examples.

  • 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-18T05:39:20+00:00Added an answer on June 18, 2026 at 5:39 am

    font-lock-keywords allows function values in the MATCHER field:

    where 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;
    it should return non-nil, move point, and set match-data appropriately if
    it succeeds; like re-search-forward would).

    So we need to write a function that would search for the next function argument in the buffer.

    Something like this:

        (defun coffee-match-next-argument (limit)
          (let ((start (point)))
            ;; Look for the arrow.
            (when (re-search-forward ") *->" limit t)
              ;; Save the position of the closing paren.
              (let ((stop (point)))
                (goto-char (match-beginning 0))
                ;; Go to the opening paren.
                (goto-char (nth 1 (syntax-ppss)))
                ;; If we're before our initial position, go forward.
                ;; We don't want to find the same symbols again.
                (when (> start (point))
                  (goto-char start))
                ;; Look for the next symbol until the arrow.
                (or (re-search-forward "\\((\\|,\\) *\\(\\(\\sw\\|_\\)+\\)" stop 'mv)
                    (coffee-match-next-argument limit))))))
    

    And the setup, to use with existing coffee-mode:

    (font-lock-add-keywords
     'coffee-mode
     '((coffee-match-next-argument 2 font-lock-variable-name-face)))
    

    You can also use this in font-lock-defaults, of course.

    This will likely use some other color than pink, but that’s easy to change.

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

Sidebar

Related Questions

Basically I want to get a handle of the python interpreter so I can
Basically like the opposite of Math.pow() . I want a function which can be
Basically I want to create a user control in code behind, DataBind() it and
Basically I want a function to be called every say, 10 milliseconds. How can
Basically I'm wondering if I can compile code that a user inputs in a
Basically I want to check the extended permissions the user has granted my app.
Basically I want to convert a virtual path to an absolute path.
basically I want to validate whether or not a text box is a certain
Basically, what I'm trying to create is a page of div tags, each has
Basically when a user enters data into a textfield on Form2 , I want

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.