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 231345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:55:30+00:00 2026-05-11T19:55:30+00:00

Possible Duplicate: Syntax coloring for Cocoa app I’m interested in syntax highlighting in a

  • 0

Possible Duplicate:
Syntax coloring for Cocoa app

I’m interested in syntax highlighting in a Cocoa TextView.

I found several resources:

  • approach with flex, via a flex pattern matched against textStorageDidProcessEditing
    in a TextView delegate. In this approach the whole string get parsed on each input event, hence performance degrades.

  • CocoaDev has an own page on the topic of syntax highlighting:

    1. Use NSTextStorageDidProcessEditingNotification, then get the edited range, and just apply the coloring there. The range might be wordboundaries or anything; this definitely improves performance.

    2. Mentioned there: Xcode, for example, only colorizes text that’s currently on-screen, and defers colorizing the rest of the document until you scroll through it. How would one implement this?

    3. Use NSLayoutManager – via Temporary attributes [which] are used only for on-screen drawing and are not persistent in any way… as the docs say, but that doesn’t color the last edited range, until a whitespace character is entered.

    4. Custom Helper like UKSyntaxColoredDocument – nice, but language definition is done via property list; how to use additional/existing language definitions?

None of the approaches seem really extensible or robust to me (except the 4. maybe ..).

I am aware of robust existing libraries for SH like pygments; and of PyObjC.

Question: How would it be possible to use some existing library e.g. like pygments to have an extensible and performant syntax highlighting in a Cocoa TextView?

Note: I know this question is very broad (and much too long). Experiences and suggestions as well as solutions are welcome. Thanks.


Found another similar thread on that matter: Syntax coloring for Cocoa app

  • 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-05-11T19:55:30+00:00Added an answer on May 11, 2026 at 7:55 pm

    I would suggest taking a look at the source code to Smultron. It has very nice syntax highlighting. It uses a subclass of NSTextView to do most of the heavy lifting. The code uses the layout manager to add attributes to the text and uses some other clever tricks to only highlight as much of the document as necessary.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A key is what you use to access an object… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer If you are using them all over, you can store… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer If its just for quick testing or whatever, you could… May 11, 2026 at 11:38 pm

Related Questions

Possible Duplicate: Syntax coloring for Cocoa app I'm interested in syntax highlighting in a
I have a domain-specific language with a certain syntax. Is it possible to make
Possible Duplicate: Are “(function ( ) { } ) ( )” and “(function (
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
I am trying to create an ANI lookup table from 2 separate tables, one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.