JJ Rohrer
JJ Rohrer

Reputation: 2741

Modifying Xcode syntax highlighting to gray-out NSAssert lines

I want to modify Xcode syntax highlighting. Namely, I do a lot of 'NSAsserts', which I find visually distracting, and so I would like lines starting with 'NSAssert' to be a light gray. This way, I can focus upon my code logic instead of having to cognitively filter-out the NSAssert lines.

Upvotes: 2

Views: 1060

Answers (2)

Phil Willoughby
Phil Willoughby

Reputation: 1734

I use a lot of these too, and I liked your idea enough to work out the answer. Well, sort of: I have not worked out how to treat NSAsserts as a new item but I have worked out how to make them appear as comments in the syntax highlighter.

  1. Create the directory ~/Library/Application Support/Developer/Shared/Xcode/Specifications
  2. Copy BaseSupport.xclangspec from /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources to that directory
  3. Apply this patch to the new copy:
--- /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/BaseSupport.xclangspec    2010-10-05 00:27:45.000000000 +0100
+++ /Users/philwill/Library/Application Support/Developer/Shared/Xcode/Specifications/BaseSupport.xclangspec    2010-12-14 11:36:51.000000000 +0000
@@ -100,9 +100,8 @@
         Identifier = "xcode.lang.comment.singleline";
         BasedOn = "xcode.lang.comment"; // for text macros
         Syntax = {
-            Start = "//";
-            EscapeChar = "\\";
-            Until = "\n";
+            StartChars = "/N";
+       Match=("//.*$","NSC?Assert[12345]?[[:space:]]*\\([^;]*\\)[[:space:]]*;");
             IncludeRules = ( "xcode.lang.url", "xcode.lang.url.mail", "xcode.lang.comment.mark" );
             Type = "xcode.syntax.comment";
         };

Caveats:

  1. This will mess up any //-comments which contain escaped newline characters. Don't do that.
  2. This will theoretically slow down syntax highlighting a little. I haven't noticed any difference.
  3. This will affect all languages you use in Xcode which normally allow //-comments.

Upvotes: 2

blueberryfields
blueberryfields

Reputation: 50468

This is the best that Xcode currently permits you to do.

Upvotes: 2

Related Questions