Sublime Forum

Sublime for PHP

#1

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 $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.

0 Likes

#2

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

[code]
<![CDATA[/**

  • $0
    */]]>
    //
    source.php
    doc block
    [/code]

[code]


[/code] There may be a better way to combine the keybindings but this has worked for me so I've just left it alone. Basically // 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.

0 Likes

#3

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 rather than on ?

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.

0 Likes

#4

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’.

<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.

0 Likes

#5

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

while its not released yet, i hope it can be ported to sublime :smile:

0 Likes

#6

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

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

change "php", "-f", "$file"], to "php", "-l", "$file"], for lint checking only.

If anyone has a more PHPMate like system… :wink:

0 Likes

#7

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

github.com/lunixbochs/sublimelint

0 Likes