Home Download Buy Blog Forum Support

Sublime for PHP

Sublime for PHP

Postby devians on Wed Mar 24, 2010 1:11 am

Hey guys, I had a quick look through but I couldnt spot anyone talking about sublime text specifically with use for PHP. I'm a huge fan of the editor, and I use it all day at work in, you guessed it, PHP. I think it would be a good idea to talk in this thread about plugins, snippets etc and their use with PHP. Off the top of my head, here are some starter issues to tackle:

  • Continuing Comments automatically for Sublime.
  • How about a plugin/macro for helping you produce PHPDoc comment blocks?
  • Exuberant CTags for PHP, and how to keep the ctags file updated as you develop.
  • Better syntax highlighting, the current highlight file works well but there are quite a few odd gaps in its behaviour. For instance, when you're using things like
    Code: Select all
    $this->property
    // or...
    $this->method($arg);
    there is an awful lot of white, when having spaces around your -> produces a property as purple. Or how __construct definition is blue when every other function definition is green.

Please add to this list, or weigh in with how you use Sublime and PHP. Hopefully we can collaborate and improve PHP behaviour.
devians
 
Posts: 4
Joined: Fri Oct 30, 2009 1:52 am

Re: Sublime for PHP

Postby Anomareh on Wed Mar 24, 2010 5:20 am

I created a snippet and a series of key bindings that work great for me for doc blocks.

Code: Select all
<snippet>
   <content><![CDATA[/**
* $0
*/]]></content>
   <tabTrigger>//</tabTrigger>
   <scope>source.php</scope>
   <description>doc block</description>
</snippet>

Code: Select all
<binding key="enter" command="insertInlineSnippet '\n*$0'">
   <context name="selector" value="comment.block.documentation.phpdoc.php"/>
   <context name="allPrecedingText" value="\*"/>
</binding>

<binding key="enter" command="insertInlineSnippet '\n *$0'">
   <context name="selector" value="comment.block.documentation.phpdoc.php"/>
   <context name="allPrecedingText" value="/\*\*"/>
</binding>

<binding key="enter" command="insertInlineSnippet '*$0\n'">
   <context name="selector" value="comment.block.documentation.phpdoc.php"/>
   <context name="allFollowingCharacter" value="*"/>
</binding>

There may be a better way to combine the keybindings but this has worked for me so I've just left it alone. Basically //<tab> will start a doc block and hitting enter anywhere sane in the doc block will continue it.


Your syntax highlighting issues are most likely due to what ever theme you're currently using and not the PHP tmlanguage file. For instance __construct and other functions are colored differently because in your theme language functions and user defined functions are set to be different colors. The only major things I've actually found lacking in the PHP tmlanguage is support for 5.3 and some annoyances when formatting SQL.

The only thing I find Sublime lacking is the lack of indentation guides. Really wish it had something similar to Notepad++. It gets really easy to get lost when you're working in big files with varying depths of nested code.
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Sublime for PHP

Postby devians on Thu Mar 25, 2010 11:51 pm

Thanks for the comment snippet and bindings, thats really handy. I modified them slightly by putting a space after the * on subsequent lines. Is there any way to get snippets to trigger on <enter> rather than on <tab>?

As for proper PHPdoc support with auto population for things like @param and @return etc, I assume we're going to need a macro/plugin, since that needs to do a bit of code lexing.

I'm currently using the monokai theme, btw. (best theme ever)

Can anyone weigh in on the use of Ctags with PHP in Sublime?

+1 for indentation markers. Komodo IDE, despite being perpetually in beta, has these and its fantastic.
devians
 
Posts: 4
Joined: Fri Oct 30, 2009 1:52 am

Re: Sublime for PHP

Postby Anomareh on Fri Mar 26, 2010 2:28 am

For snippets on enter you can simply bind it. Also note bindings with a comma will bind a sequence. So 'shift+a' will execute when you push 'shift' and 'a' combined, where as 'a,b,c' will execute when you type 'a', then 'b', and then 'c'.

Code: Select all
<binding key="slash,slash,enter" command="insertSnippet 'Packages/User/my-snippet.sublime-snippet'" />

So the above binding will execute when you type 'slash', 'slash', and then 'enter'.


If you want automatic PHPDoc generation your best bet is probably a plugin. From what I've seen I don't think it'd be very tough at all to implement it either.
Anomareh
 
Posts: 222
Joined: Thu Oct 01, 2009 7:32 pm

Re: Sublime for PHP

Postby myel on Fri Mar 26, 2010 9:28 am

mario ricalde on the textmate mailing list is rebuilding "intellisense" for php as a textmate bundle -> http://lists.macromates.com/textmate/20 ... 30531.html

while its not released yet, i hope it can be ported to sublime :)
myel
 
Posts: 88
Joined: Sat Mar 22, 2008 11:26 pm

Re: Sublime for PHP

Postby dickiedyce on Thu Apr 28, 2011 9:54 pm

Took me a while to find this - a build system for PHP... not quite the TextMate "PHPMate" but useable to get started

Code: Select all
{
   "cmd": ["php", "-f", "$file"],
   "selector": "source.php",
   "file_regex": "^Parse error: .* in (.*?) on line ([0-9]*)"
}


change
Code: Select all
["php", "-f", "$file"],
to
Code: Select all
["php", "-l", "$file"],
for lint checking only.

If anyone has a more PHPMate like system... ;-)
dickiedyce
 
Posts: 1
Joined: Thu Apr 28, 2011 9:49 pm

Re: Sublime for PHP

Postby vostok4 on Sat Apr 30, 2011 10:21 pm

For real time lint-checking in PHP source you don't need a build system, just look at sublimelint:

https://github.com/lunixbochs/sublimelint
vostok4
 
Posts: 25
Joined: Fri Oct 22, 2010 6:09 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 26 guests