NOTE: Apple finally got off its ass and supports highlighting method names differently from the rest of the code. So, thankfully, this project is no longer needed and won't be updated finally. Only took them 10 years....
...............
These are xclangspec files and color schemes for Xcode3 and Xcode5 that allow you to target the method names in definitions and declarations for special highlighting. For Xcode5 also supports special colors for blocks (class methods, instance methods, and closure blocks can have different colors). Some work is needed as it is not compatible with context highlighting (i.e. project identifiers).
Some sample images are included in the package. The following is a simple illustration of what the highlighting additions can do. It gives the ability to pop out method names which makes legibility much greater similar to functionality available in Emacs.
Class methods can have distinctive highlighting as well to separate them from instance methods in the same file.
Xcode out of the box won't let you do this, unless you make some difficult modifications to the language parsing grammars. This is still a work in progress for Xcode5+, especially for the header files as the ObjC++ langspec is required for all headers and I haven't modified that yet (lots of work).
The following are additions for highlighting features over the standard set:
- class method names
- class method return type
- class method parameter types
- class method parameters
- instance method names
- instance method return type
- instance method parameter types
- instance method parameters
- separate colors for class and instance method definition blocks
- closure blocks ( i.e. ^{} type blocks) can be set to their own color as well
Limitations:
There is a problem with Xcode5/6 in that setting colors by grammar vs. setting colors by context (i.e. what clang/llvm hands back after parsing) seems to be incompatible so far. So using these will currently disable things like being able to special-highlight project class names. I have left notes in the grammars where the area is to focus on if someone can improve this.
-
*** Not tested vs. Xcode4 ***
-
You need to install these to:
sudo cp *.xclangspec *.xcsynspec \
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/
- You may have problems with other, older language specs installed throughout your system. I nuked everything else I found in my system. find / -name ObjectiveC.xclangspec -print is your friend. Xcode even has two copies under the .app. I nuked the other one, because at the end of the day YOU NEVER KNOW WHAT THE HELL XCODE IS GOING TO DO. Words to live by. I don't think Apple even knows. In particular you may need to delete these:
sudo rm /Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/ObjectiveC.xclangspec
sudo rm /Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/ObjectiveC++.xclangspec
sudo rm /Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/C.xclangspec
This seems to be the alternate copy, and they will be used if you edit the primary in DVTFoundation.
You need to remove the caches any time you edit the langspecs, Xcode stashes everywhere:
find /private/var/folders -name \*Xcode\* -print -exec rm -rf {} \;
rm -rf ~/Library/Developer/Xcode/DerivedData
-
These highlighting rules are not yet compatible with context highlighting (i.e. things that make your local class names pop out with a different color) This needs some improvement.
-
MAKE BACKUPS AND USE AT YOUR OWN RISK
-
Sample colorschemes are included. They are just slammed together. Copy colorschemes into:
cp *.dvtcolortheme \
~/Library/Developer/Xcode/UserData/FontAndColorThemes/
Again, this is tested with Xcode5/Xcode6 only. I have older highlighting code that works for Xcode3. Xcode4, who knows.
Things that were discovered in the process (if you want to improve this):
-
Xcode will crash if there is no ObjectiveC.xclangspec when you have ObjCC++ active.
-
ObjC++ is used for headers, and ObjC for m files. So the ObjC++ grammars also need editing.
-
to refresh Xcode's syntax highlighting you need to do the following:
a. stop Xcode b. save your edited files c. at the shell:
rm -rf /private/var/folders////com.apple.DeveloperTools//Xcode* rm -rf ~/Library/Developer/Xcode/DerivedData open /Applications/Xcode5-DP5.app
Unfortunately Xcode seems to cache the syntax highlighting from clang in the DerivedData somewhere. There also seems to be a cache in /private
so you need to nuke both. There may be a cleaner way to do it. -
if keywords are shown at all in the ObjC lang spec then all the C keywords are automatically included (from somewhere...) seems like the only way to block it is to rename the grammar so it is not picked up. So basically the keywords list in the grammar does nothing, it cannot be changed, only the rules renamed.
-
Blocking out the keyword parsing by making a mismatch with the builtins causes all of the rest of the context-based parsing to fail out.
-
Xcode is very aggressive in loading langspecs, seems to load in subdirs and regardless of extension, so if you put something in there as a backup you will get two copies. So do not store any alternate versions of the grammar in Xcodes directory or else you will get strange results.
-
do tail -f /var/log/system.log and watch Xcode errors... "line one" errors on the console mean that you have not closed a brace properly somewhere or broken the syntax in some other way. So make your changes in small iterations.
-
Visual Diff is very useful if you break the grammar, compare it against originals.
-
Keep backups of everything. Just not in the Xcode dirs.
-
It seems at the moment to be a choice between grammar highlighting and context recognition from clang/llvm. Anything in the grammar that clang/llvm cares about will be overridden. One of those things is identifiers, which are things we care about for highlighting method names. So if you use this highlighting, unless someone figures out how to do it, will override project/class identifying and highlighting as well as some other things based on context.
DBX Aug 2014