Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (119 sloc) 6.763 kb
cb0e2e8 readme tweaks
Marc Liyanage authored
1 About This Package
2 ==================
3
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
4 Here are some Xcode text macros I use for writing Objective-C code.
5 They speed up my coding a lot, especially the macros for methods.
6
7 Let me know if you wrote useful macros that you would like to add
8 to this collection. The best way is by forking this project on github,
9 adding your macros, and sending me a pull request.
10
11 There is also a cheat sheet generator that lists the macros on an HTML
12 page with their completion prefixes and your keybord shortcuts.
13 Here’s an [example](http://www.entropy.ch/software/macosx/xcode-macro-cheat-sheet.html).
14 You’re more than welcome to spice up that HTML in the XSLT:-)
15
16
17 About Xcode’s Text Macros in General
18 ====================================
19
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
20 My guess is that they are underutilized by Xcode users. They certainly
21 aren’t very discoverable where they are in the Edit menu, with no keyboard
22 shortcuts assigned by default. Personally, I would give them their own toplevel
23 menu bar item in Xcode, with a nice space-saving icon like the one
24 [BBEdit](http://www.barebones.com/products/bbedit/)
25 uses for its clippings.
26
27 I know I didn’t use them a lot, I used
28 [Objective Development](http://www.obdev.at)’s
29 [Completion Dictionary](http://www.obdev.at/products/completion-dictionary/index.html)
30 instead.
31
32 But Xcode’s macros are very powerful. The first step to harnessing that power
33 for your daily coding is to start using what’s already there:
34
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
35 * Assigning keyboard shortcuts to the most often used macros is *highly*
36 recommended, especially to get one of the coolest text macro features,
37 cycle lists. Cycle lists link together related macros and let you
38 quickly flip through them by repeatedly pressing the shortcut. This
cb0e2e8 readme tweaks
Marc Liyanage authored
39 is very useful for different variants of `if ()` statements, for example.
5f75474 More Readme edits.
Marc Liyanage authored
40 Until recently I didn’t even know about cycle lists. The cheat sheet
41 shows you which macros are part of a cycle list.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
42 * Another great feature that’s easier to use with keyboard shortcuts is
43 the ability of some macros to wrap selected text. Again this is useful
5f75474 More Readme edits.
Marc Liyanage authored
44 for block statements such as `if ()`, especially in combination with the previous
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
45 feature. Select a bunch of lines, hit the shortcut to wrap them in an
5f75474 More Readme edits.
Marc Liyanage authored
46 `if ()` block, hit the shortcut again to switch to an `if / else` block.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
47 Taken together, this results in a killer feature.
48 * I recommend picking a simple and consistent keyboard shortcut convention
49 across all macros. I use just the Ctrl key with letters. Obviously
50 this only works because I don’t use the emacs text editing bindings,
51 except maybe Ctrl-T once in a while. My recommendations are listed below
5f75474 More Readme edits.
Marc Liyanage authored
52 in the macro list and in the cheat sheet sample. You could also use the
53 number keys with Cmd-Ctrl. Whatever you pick, if you make it something
54 simple and unified, you’ll have an easier time remembering the shortcuts,
55 and only if you remember and use them a lot will you get the full time-saving
56 benefit.
57 * You might use some macros once in a while, but not often enough to justify
b2b7a0d add hint about completion prefix to readme.
Marc Liyanage authored
58 giving them their own shortcut. In those cases it’s a good idea to
5f75474 More Readme edits.
Marc Liyanage authored
59 still memorize their completion shortcut, which is the next best thing.
b2b7a0d add hint about completion prefix to readme.
Marc Liyanage authored
60 To insert the macro, type the completion shortcut and hit the tab key.
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
61
62 The second step is to start writing (and hopefully sharing) your own macros:
63
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
64 * Xcode’s macro language is fairly complicated, and as far as I know not
65 well-documented, but it is also very powerful because it uses an inheritance
66 system and flexible token replacement features. It’s worth to learn it,
cb0e2e8 readme tweaks
Marc Liyanage authored
67 and you can learn a lot by looking at the built-in `C.xctxtmacro` file.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
68 The built-in macro files are in the Xcode application bundle in
cb0e2e8 readme tweaks
Marc Liyanage authored
69 `Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/`.
70 * The Xcode user defaults also influence the macros, specifically the whitespace.
71 These defaults are documented [here](http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW40).
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
72
73
74 About the Macros
75 ================
76
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
77 With both the built-in macros and the ones in this collection here, play
78 around a bit, with something selected, nothing selected etc. to see what
79 gets wrapped, where the cursor ends up, what placeholders get inserted.
80 If you spend a lot of time in Xcode, you’ll really want to get familiar
81 with text macros.
cb0e2e8 readme tweaks
Marc Liyanage authored
82
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
83 Installation
84 ------------
85
86 Put the .xctxtmacro file into your
87
88 "$HOME/Library/Application Support/Developer/Shared/Xcode/Specifications/"
89
90 directory. Then restart Xcode so it picks them up. *Definitely* assign keyboard
cb0e2e8 readme tweaks
Marc Liyanage authored
91 shortcuts :-)
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
92
438b1fc Git clone tip added to readme
Marc Liyanage authored
93 Ideally, you would `git clone` this project directly from GitHub
94 to some location on your system and put a symbolic link to the macro file into
95 the directory given above. That way, you can always update to the newest version
96 of the macro collection with a simple `git pull`. If you start your own collection
44b513e last edit for today :)
Marc Liyanage authored
97 of macros, put them into a separate file in the same directory.
438b1fc Git clone tip added to readme
Marc Liyanage authored
98
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
99 Here’s a quick run-down of some of the macros:
100
101 Objective-C String Literal
102 --------------------------
103
cb0e2e8 readme tweaks
Marc Liyanage authored
104 Inserts `@""`. If something is selected, it puts that between the quotes.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
105 Without selection, moves the cursor between the quotes.
106
107 Recommended shortcut: ⌃\
108
109 NSLog() Calls
110 -------------
111
cb0e2e8 readme tweaks
Marc Liyanage authored
112 Inserts `NSLog()` calls with zero and one arguments. The two are linked
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
113 in a cycle list.
114
115 Recommended shortcut: ⌃L
116
117 Single-Statement if ()
118 ----------------------
119
cb0e2e8 readme tweaks
Marc Liyanage authored
120 Inserts an `if ()` statement without the braces. It’s linked to several
121 other `if ()` statement variants in a cycle list.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
122
318dfdd readme tweaks
Marc Liyanage authored
123 Recommended shortcut: ⌃I
124
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
125 Method Definitions
126 ------------------
127
128 Several variants of methods with different return value and parameter
129 combinations. They are linked together in a cycle list.
130
131 Recommended shortcut: ⌃M
132
133 Method Parameter
134 ----------------
135
cb0e2e8 readme tweaks
Marc Liyanage authored
136 Inserts an `xxxx:(yyy)zzz` sequence to add a parameter to a method
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
137 definition/declaration. Ideal for combination with the method
138 blocks in the previous item.
139
140 Recommended shortcut: ⌃P
141
142
143 About the Cheat Sheet Generator
144 ===============================
145
146 The cheat sheet generator reads the macros in Apple’s C and
147 Objective-C files built in to Xcode. By default it doesn’t
148 read the shortcuts for C++ or the other languages supported
149 by Xcode, because I don’t use those and don’t want them cluttering
150 up the list. If you want them you can enable them in the generator’s
cb0e2e8 readme tweaks
Marc Liyanage authored
151 `read_macro_definitions()` method.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
152
12e3b2e readme tweaks
Marc Liyanage authored
153 It reads *all* of the `.xctxtmacro` files in your personal
154 directory, as it is likely that you care a lot about those...
155
156
f5407cd added link to xobjc project, fixes #1.
Marc Liyanage authored
157 Related Projects
158 ================
159
160 Here are some related projects:
12e3b2e readme tweaks
Marc Liyanage authored
161
f5407cd added link to xobjc project, fixes #1.
Marc Liyanage authored
162 * [xobjc - Shortcuts for lazy Objective-C developers](http://github.com/holtwick/xobjc)
Something went wrong with that request. Please try again.