Note that there are some explanatory texts on larger screens.

plurals
  1. POSyntax Highlighting in Cocoa TextView? Experiences? Suggestions? Ideas?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1517239/syntax-coloring-for-cocoa-app">Syntax coloring for Cocoa app</a> </p> </blockquote> <p>I'm interested in <strong>syntax highlighting</strong> in a <strong>Cocoa</strong> TextView.</p> <p>I found several resources:</p> <ul> <li><p><a href="https://stackoverflow.com/questions/1517239/syntax-coloring-for-cocoa-app">approach with flex</a>, via a <a href="http://westes.github.io/flex/manual/Patterns.html" rel="nofollow noreferrer">flex</a> pattern matched against <code>textStorageDidProcessEditing</code> in a <code>TextView</code> delegate. In this approach the whole string get parsed on each input event, hence performance degrades.</p></li> <li><p>CocoaDev has an <a href="http://www.cocoadev.com/index.pl?ImplementSyntaxHighlighting" rel="nofollow noreferrer">own page on the topic of syntax highlighting</a>:</p> <ol> <li><p>Use <code>NSTextStorageDidProcessEditingNotification</code>, then get the edited range, and just apply the coloring there. The range might be wordboundaries or anything; this definitely improves performance.</p></li> <li><p>Mentioned there: <em>Xcode, for example, only colorizes text that's currently on-screen, and defers colorizing the rest of the document until you scroll through it.</em> How would one implement this?</p></li> <li><p>Use <code>NSLayoutManager</code> – via <em>Temporary attributes [which] are used only for on-screen drawing and are not persistent in any way...</em> as the docs say, but that <em>doesn't color the last edited range, until a whitespace character is entered.</em></p></li> <li><p>Custom Helper like <a href="http://www.zathras.de/angelweb/sourcecode.htm#UKSyntaxColoredTextDocument" rel="nofollow noreferrer">UKSyntaxColoredDocument</a> – nice, but language definition is done via property list; how to use additional/existing language definitions? </p></li> </ol></li> </ul> <p>None of the approaches seem really extensible or robust to me (except the 4. maybe ..).</p> <p>I am aware of robust existing libraries for SH like <a href="http://pygments.org/" rel="nofollow noreferrer">pygments</a>; and of <a href="http://pyobjc.sourceforge.net/" rel="nofollow noreferrer">PyObjC</a>.</p> <p><strong>Question</strong>: How would it be possible to use some existing library e.g. like <a href="http://pygments.org/" rel="nofollow noreferrer">pygments</a> to have an extensible and performant syntax highlighting in a Cocoa <code>TextView</code>?</p> <p><em>Note</em>: I know this question is very broad (and much too long). Experiences and suggestions as well as solutions are welcome. Thanks. </p> <hr> <p>Found another similar thread on that matter: <a href="https://stackoverflow.com/questions/1517239/syntax-coloring-for-cocoa-app">Syntax coloring for Cocoa app</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload