XCode技巧之自定义TextMacros

On 03/16/2011, in iOS Dev, Mac Dev, by ultragtx

这篇文章一样,以下基本都是从becoming productive in xcode中取得的

===Text  Macros===

添加自己的TextMacros(XCode 3.2.5测试通过,XCode 4 未测试)

在~/Library/Application Support/Developer/Shared/Xcode/下面新建Specifications文件夹,建立与/Developer/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources文件夹下类似的*.xctxtmacro文件即可

例子

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(
  {
    Identifier = objc.hello;
    BasedOn = objc;
    IsMenuItem = YES;
    OnlyAtBOL= YES;
    Name = "Hello";
    TextString = "Hello, XCode!";
    CompletionPrefix = "hello";
    IncludeContexts = ("xcode.lang.objc");
  },
  {
    Identifier = objc.property;
    BasedOn = objc;
    IsMenuItem = YES;
    OnlyAtBOL= YES;
    Name = "@property Definition";
    TextString = "@property (nonatomic, retain) IBOutlet <#type#> *<#variable#>;";
    CompletionPrefix = "prop";
    IncludeContexts = ("xcode.lang.objc.interface");
  },
  {
    Identifier = objc.rectmake;
    BasedOn = objc;
    IsMenuItem = YES;
    OnlyAtBOL= YES;
    Name = "RectMake";
    TextString = "CGRect aRect = \n\tCGRectMake(<#x#>, <#y#>, <#width#>, <#height#>);";
    CompletionPrefix = "cgrm";
    IncludeContexts = ("xcode.lang.objc.block");
  }
)

上面的代码添加了三个textmacro:

第一个仅仅是测试用,代码中输入hello即有自动补全提示,补全成Hello,Xcode!。

第二个效果是输入prop,然后 ⌃. 自动补全成@property (nonatomic, retain) IBOutlet <#type#> *<#variable#>;的形式,具体实验一下就知道了。

第三个类似,不多说了。

首先注意一下OnlyAtBOL这一行,在新版本的XCode中如果不加上这一行则textmacro无法生效。具体请看这一段的解释:

There is a bug on TextMacros in the latest versions of Xcode (I encourage you to send a bugreport to Apple as I did)

In fact, only TextMacros that have the value “YES” for the key “OnlyAtBOL” will work. If this key is not present (or set to NO), the macro will not respond to autocompletion.
Actually, the new “OnlyAtBOL” key means “Only at Beginning Of Line”, so the autocompletion for this macro will only work if it is triggered in the beggining of a line. But in fact, quite every macro I need everyday comply to this constraint (ifelse, nslog, nss, …) so this is acceptable.
If you want those macros (that does not work because of the lack of OnlyAtBOL set to YES) to work again, you need to add/override their specifications in your “Application Support” directory (in a custom TextMacro file that override them), until the Xcode team fixes that bug.
 
 
Tagged with:  

修改Mac下粘贴并匹配样式的快捷键

On 12/22/2010, in 折腾, by ultragtx

    Mac下的粘贴功能很“智能”,可以把原来的格式文字原封不动的搬过来,但这样也照成一些麻烦,如乱码,格式混乱等,Mac下还有另一种粘贴方式即“粘贴并匹配样式”(Paste And Match Sytle),这种粘贴方式所”匹配“的样式不是原文的样式,而是要粘贴到的位置的样式,但这种粘贴方法要同时按下“⇧⌘⌥V”这四个按键,实在是有点困难,而对我来讲还是这种粘贴方式更加符合我的工作习惯。解决方法很明确,就是将两种粘贴方式的快捷键互换一下,这样能很好的保证不会与其他快捷键有冲突,方法如下:

  1. 打开 偏好设置>>键盘>>键盘快捷键
  2. 在左边的列表里选择“应用程序快捷键”,然后点下面那个“+”号添加一项
  3. 在弹出的对话框中,“应用程序”选则你要修改的程序,尽量不要选择全部程序,因为某些程序没有匹配样式并粘贴这个操作(比如终端,Mac QQ等),这样就会导致粘贴时必须按⇧⌘⌥+V才行(如果一定要选择所有程序,要么就单独为那些出问题的程序把粘贴这一操作的快捷键设置成⌘+v,要么就使用别的快捷键),“菜单标题”输入“粘贴”,“键盘快捷键”⇧⌘⌥+v,点添加。
  4. 再用相同的方法添加“粘贴并匹配样式”,快捷键“⌘+v”,如果某些英文软件不支持中文,还要添加“Paste”和“Paste And Match Style",方法类似。

    OK,修改完成,现在可以开个程序试试修改的效果了。(END)

Tagged with: