Re: XC3: text macros, autocompletion
Re: XC3: text macros, autocompletion
- Subject: Re: XC3: text macros, autocompletion
- From: David Ewing <email@hidden>
- Date: Mon, 5 Nov 2007 11:44:00 -0700
So, text macros didn't really change too much from Xcode 2.x. They
were available via code completion in 2.x.
You've noticed the big difference with the IncludeContexts and
ExcludeContexts entries. The IncludeContexts entry is similar to the
ComputerLanguages entry from 2.x. It's a list of contexts where the
macro will show up. In 2.x, this was just the identifier for the given
language. (Languages were given in .pbxlangspec files.) In 3.0, it's
also the identifier of a language spec (now given in .xclangspec
files). But in 3.0, a language spec is much more flexible, and roughly
corresponds to a production in a BNF grammar. So you can specify that
a macro will only show up in a particular part of a file.
ExcludeContexts gives a list of places where the macro shouldn't be
included in the completion list.
To find a list of all valid values for the IncludeContexts and
ExcludeContexts entries you have to look in all the .xclangspec files.
There are literally hundreds. But, most of the ones you'd ever care
about are already used by existing text macros. For instance, your
ifelse macro can be used anywhere in a C file, but it's not very
useful inside comments, strings and the like. So the settings are:
IncludeContexts = ( "xcode.lang.c.block",
"xcode.lang.java.block" ); // these all work in Java too
ExcludeContexts = ( "xcode.lang.string",
"xcode.lang.character", "xcode.lang.comment",
"xcode.lang.c.preprocessor", "xcode.lang.c.parenexpr",
"xcode.lang.c.bracketexpr" );
(For completeness, these are inherited from the c.block macro. The
values make it so that they only show up inside blocks - you can't use
an if statement outside a function. And you don't want them inside
parenthesized or bracketed expressions. What makes them also work in
Objective-C and C++ files is given by the inheritance of language
specs. The spec "xcode.lang.cpp.block" is based on
"xcode.lang.c.block".)
You still need to specify the CompletionPrefix to get the macro to
show up in code completion. IncludeContexts and ExcludeContexts are
inherited through the macro specification hierarchy (as given by
BasedOn).
If you couldn't get your text macros to show up in the completion list
in 2.x, it's likely that something else is wrong. It's probably
easiest to base them on existing ones, and make sure they show up in
the menu. If they work there, then all that's necessary to get them in
code completion is to add a CompletionPrefix, and make sure
ComputerLanguages is set (which can be inherited).
And, since I'm here, the second big change in text macros is that
default settings (e.g. "PreExpressionsSpacing", "BlockSeparator") can
be shared by all languages (which makes them much easier to
customize). I won't go into how you used to have to set these values.
It was too hard to be useful. So, if you like your 'case' keywords in
a switch statement aligned even with the block, rather than indented,
you use the following defaults command in Terminal:
defaults write com.apple.Xcode XCCodeSenseFormattingOptions
'{ CaseStatementSpacing = ""; }'
The default value of CaseStatementSpacing is a tab character, which
corresponds to one indentation level (which is then converted to
spaces or tabs according to your settings).
One of the better parts of this consolidation is that the relevant
settings are also used by the indentation commands. And, there are
keys for handling the spacing for regular code completion (e.g.
"PreFunctionArgsSpacing", "PreCommaSpacing"). Unfortunately, we
managed to leave the documentation for this default out of the Xcode
User Default Reference. I'l try to get it added soon.
I hope that helps more than it confuses.
Dave
On Nov 2, 2007, at 7:08 AM, Fritz Anderson wrote:
In Xcode 3, text macros now have the feature that, if you type a
token word, and then escape, the resulting completion list includes
the macro expansion assigned to that word in the macro specification
file (*.xctxtmacro).
For example: In a C-family file, type ifelse. When you press escape,
it offers you "ifelse - If / Else Block." Accepting it inserts a
skeleton
if (<#condition#>) {
<#statements#>
}
else {
<#statements#>
}
## 1: How can I get my own macro set to take advantage of this
feature?
I've figured out how to do text macros for Xcode 2, which didn't
have macro completion. Simply providing CompletionPrefix for the
particular macro has no effect.
## 2: Has it something to do with the IncludeContexts/
ExcludeContexts keys I see in (inherited) macro definitions? The
basic values for those context lists don't seem to be documented
anywhere.
— F
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden