TextMate is a great all-round editor for simple (and some not-so-simple) tasks. For RoR, it's the dog's bullocks. I was, however, initially somewhat disappointed by its support for PHP.
Out of the box, TextMate doesn't support PHP code completion or provide you with an easy method of accessing the PHP documentation. I found, however, that you can easily configure it to do both of these things by downloading, installing and configuring the PHP Code Completion bundle.
Code completion
To set up code completion in TextMate, you must first download the PHP Code Completion bundle. As you can see, that link leads to an SVN repository.
To download and install the PHP code completion bundle, follow these instructions:
- Open Terminal
- Create a folder under /Library/Application Support/ called TextMate and a folder under that called /Bundles:
mkdir -p /Library/Application\ Support/TextMate/Bundles
- Switch to that folder:
cd /Library/Application\ Support/TextMate/Bundles
- Check out the bundle you want from the TextMate bundles repository:
svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHPCodeCompletion.tmbundle
- If you had TextMate open during this, select Bundles → Bundle Editor → Reload Bundles.
Create a new PHP file and test out the code completion by typing the first few letters of a function name and pressing ⎋ (esc). If you press ⌥ F1 before code completion, you will see a list of similar functions and if you press it after completion, you will see some brief documentation on the function signature.
Documentation
The PHP docs are probably the best I've seen for any programming language. The online version with comments is especially useful. Although TextMate doesn't have a built-in feature in the default bundles to access this documentation, the PHP code completion bundle you just installed does. It does require some configuration though.
With the PHP code completion bundle installed, you can access the PHP documentation by pressing Shift F1. The first time you do this, you will see a message telling you that you need to configure your settings.
To configure the PHP documentation:
- If you don't already have it, download the PHP documentation (.tar.gz version) to your computer. I placed the .tar.gz file in
/Users/aral/library/PHP_Manual/and unzipped it there. The unzipped files appear in an html folder so the path I entered in my preferences (see Step 4, below) was/Users/aral/library/PHP_Manual/html/(do not leave out the trailing forward slash or else it won't work). Also, wherever you decide to place the documentaiton, make sure that none of the folder names on its path have a space in them. - Click the Edit Preferences link in the PHPCodeCompletion Documentation window to open the PHPCodeCompletion preferences file in TextMate.
- Comment out the line that reads
$phpcc_configured = FALSE;and uncomment the one that sets the same flag to true. - Set the path that you placed the documentation in to the value of the
$phpcc_manual_path_to_localvariable. - Save and close the preferences file.
Press Shift F1 on a function name to test out the documentation. If you see the familiar PHP web site appear, it means that you put the wrong path in the preferences file and that you are viewing the online docs as a backup. Of course, you may want to default to the online docs as they contain those invaluable user-submitted comments but it does make things slightly slower too.
That's it! You should now have code completion and documentation working for PHP in TextMate. Enjoy! :)
The PHP code completion in TextMate article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
I have tried to svn this, but have been unable to get it to work, is it possible to please send the actual tmbundle to me? I keep getting an error that says svn: command unknown… Thanks for the writeup on the process, it sold me in wanting the code completion as I used to have that (almost standard with every editor on the windows side) though I am extremely new to Mac and am completely lost.
You can download them from here
http://www.imediatec.co.uk/tm/phpcc/
you are very kind, thanks very much.
Hi, I downloaded and installed this bundle yesterday. The fuction lookup works. In fact everything seems to be working except for code completion.
Pressing the ESC key just gives me the system alert sound. “bonk”
Did I miss something? Do I need to have the local documentation installed to use code completion?
btw, getting SVN installed properly was a pain. packages out there install it to the system but don’t make it available to users. Had to find it, add it to the PATH then restart terminal to use it.
Thanks for this post. I followed your instructions and it worked perfectly.
I’m relatively new to TextMate and am really loving it. It is this kind of feature that really sets it apart.
Thanks again!
[...] http://aralbalkan.com/822 [...]
Link is not working!!
Brian
Appears that this has been moved to the disabled bundles:
http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/
[...] さて本題にはいると、元ネタは以下です。 http://aralbalkan.com/822 基本はこの通りでいいのですが、記事が古いため、リポジトリのパスが間違っています。(コメントに新たなパスが書かれていますが、それも古い) 正しいパスは以下です。 http://macromates.com/svn/Bundles/trunk/Disabled%20Bundles/PHPCodeCompletion.tmbundle/ これをTextMateの環境ディレクトリ?にチェックアウトすればOKです。 > cd /Library/Application¥ Support/TextMate/Bundles svn co http://macromates.com/svn/Bundles/trunk/Disabled%20Bundles/PHPCodeCompletion.tmbundle/ (svn co ~は2行で表示されていますが、実際は1行です) この辺は元記事通りです。 PHPマニュアルが手元にない方は以下のURLよりDLしてください。 http://jp.php.net/get/php_manual_ja.tar.gz/from/a/mirror それでDLしたマニュアルは自分のアカウントで参照可能なディレクトリに保存します。 TextMateを開いてLanguageをPHPにし、なんでもいいのでPHPの組み込み関数を入力します。その関数にフォーカスがあたっている状態でShift+F1を押します。 するとエラーとともに初期設定をしてくださいみたいなウィンドウが開きます。その中のEdit Preferencesを押すとphpcc.preferences.phpというファイルが開きますので、後は元記事の指定に従って、フラグの変更と先ほど準備したマニュアルへのパスを指定してあげます。 そしてもう一度PHP関数にフォーカスをあてた状態でShift+F1を押すと…。 見事マニュアルが表示されました! TextMateのリポジトリには他にも使えそうなBundleがあるようなので、試してみようと思います。 これで€39というのは安いですね。 しか〜し、自分のMacBookではShift+F1というショートカットは押しにくいなぁ。 [...]
Thanks for the info, extremely helpful. :)
Here’s some updates for new readers:
1. Open Terminal, type ’svn’, if you see ‘-bash: svn: command not found’ you don’t have svn installed.
2. You can install Martin Ott’s svn package from http://www.codingmonkeys.de/mbo/
3. Follow steps 1 through 3 in this article
4. Type this in place of step 4 above (so it pulls from the new location):
svn co http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/
You need to put a “percent 20″ (a percent symbol % followed immediately by the number 20) in place of the space between the words ‘Disabled’ and ‘Bundles’ in previous svn checkout path (doesn’t appear to show up in the comments).
Installed last night with no problem…. Thank you this helps a lot.
Installed and had no problem at all, thanks
[...] Either I’m missing something, or the “escape” key doesn’t actually do any code completion whatsoever. Looks like there are a couple bundles out there that enable this functionality (such as this one for PHP)… TextMate is indeed light. [...]
The plain PHP bundle supports completion, documentation lookup, and quick function synopsis (see Bundles → PHP → Help) — I have now removed the PHPCodeCompletion bundle from the repository to avoid confusion.
Thanks for the update, Allan :)
Hy, I tried to install it but as long as i see none of the links are working!
Thanks!
@Alexandra Same problem here 404 on the URIs.
where did that bundle go? :(
svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHP.tmbundle/
the post 17 works, btw u need install that like root so u need the sudo command, the exact line looks like this:
sudo svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHP.tmbundle/
[...] Il primo, aiuta molto nel completamente del codice PHP, magari non proprio come mi sarei aspettato (la classica finestrella che compare man mano che si scrive), ma è davvero utile! -> PHP code completion in TextMate [...]
TextMate for Mac only :\
Wow it’s really a shame that those links don’t work anymore. I was looking forward to using code completion in TextMate. This thing is such a step up from Adobe Dreamwaster.
By the way I have the most recent version of TextMate (1.5.8). I can confirm that code completion is not currently part of PHP.tmbundle, and it’s not anywhere in http://macromates.com/svn/Bundles.
What we need is a new link. If someone has it, I would be grateful to them if they would send it to daniel at summitcove dot com.
http://www.cigaria.co.il/סיגריה-אלקטרונית.asp
גמילה מעישון וסיגריות אלקטרוניות
סיגריה אלקטרונית
quit smoking with the elctronic cigaratte – the best option to quit smoking without hard work. get the elctronic cigaratte today.
סיגריה אלקטרונית הדרך הקלה והבטוחה להפסיק לעשן
היתה טעות בכתובת הקודמת
@Daniel The PHP Bundle supports all that now. No need for a manual install of a PHPCodeCompletion bundle. This is obsolete. Cheers Stefan
Hat tip, Aral!! Great :-)
I had to look for the link but I just installed it with this:
svn co http://svn.textmate.org/trunk/Bundles/PHP.tmbundle/
Thanks!
Am I confused? It looks like the key commands for ‘if’ and for ‘if’ wrapped in php tags are the same. That is, they are both triggered by ‘if’ followed by a tab. I can never get the php wrapped ones to work. I always just get the plain ‘if’ without the php tags. What am I doing wrong?
Thanks
I have an error trying to install PHP.tmbundle :
$ svn co http://svn.textmate.org/trunk/Bundles/PHP.tmbundle/
svn: Can’t convert string from ‘UTF-8′ to native encoding:
svn: PHP.tmbundle/Snippets/?\226?\128?\166 ?>.tmSnippet
How can I solve this ?
Thanks
Thanks Aral, this is an amazing help. However I cannot get SVN installed on my mac running 10.4.11. http://www.codingmonkeys.de/mbo/ is not there anymore :(
סיגריה אלקטרונית מוצר חדש אשר יעזור לך להפסיק לעשן – קנו סיגריה אלקטרונית עכשיו
The bundle no longer exists in the svn.
Just looking to implement this and it turns out it’s in the PHP bundle included in Textmate. Just type the command and hit option+Esc
Cheers