php: auto indent the whole code? - php

isnt there any software/plugin to netbeans/eclipse that auto indent the whole code after i've inserted it?
not just indent when i press ENTER for new function.
i want to paste in a code for example without indents and it will auto indent everything automatically since it can recognize what language is used.
should save a lot of time.

In Zend Studio (and I guess in Eclipse with PDT as well), you can right click your pasted document in the editor view and select Source Format. Rules for source formatting are edited in Windows Preferences PHP Code Style Formatter. You can select Code Conventions like PEAR or ZF there by default or invent your own.
If you just want to indent some selected lines of code back and forth you select it and hit tab (or shift tab to unindent). This will not resolve any nested code though. Use Ctrl Shift F for that (thanks to Paul Lammertsma for pointing that out).

In Eclipse you can press Ctrl+Shift+f to autoindent your open file.

In Netbeans go to the Source menu, choose the Format option. It does what you need. It will follow the formatting options you set from Tools menu, Options dialog.

Polystyle is a standalone tool that can be integrated into most IDEs, and does highly configurable source code formatting for many languages. It costs $15.

I believe the Eclipse shortcut to auto-indent the selected code is Ctrl+i, at least it is in Eclipse for Java, so I assume it would be the same for Eclipse PHP.

Related

Turn off autocomplete in PhpStorm

Right now if I type in $ into Jetbrains PhpStorm IDE, it will display a whole bunch of suggestions (e.g. variables that have already been declared) which slows down my typing.
Is there a way to configure PhpStorm to NOT do this? In other words, turn off auto-complete or only do auto-complete if I press Ctrl+Space and not when I just type in $?
Disable code completion?
See Settings/Preferences(depends on OS) - IDE Settings - Editor - Code Completion
There you should find an option Autopopup code completion in (ms)
If the check box is not selected, PhpStorm will not suggest code completion automatically.
See also the online help.
This is more an answer to the linked "duplicate" question, but I can't answer that one. Hope this helps someone.
To disable HTML auto-completion, see Settings -> Editor -> General -> Smart Keys.
There is a section called XML/HTML where you can toggle auto-completion of HTML tags and attributes.
In my case I was looking to disable Auto close tags when typing '</' option.
My auto-completion was not working, I had to execute in menu File->Invalidate cache... (and disable Nette tester plugin in my case)

Formatting PHP code in Microsoft Expressions Web 4

Does Microsoft Expressions Web 4 has a option (or keyboard shortcut) to format PHP Code?
Have you tried Ctrl+K+F this is the usual formatting for Visual Studio Codes for ASP.NET and C# codes. I assume Microsoft would make the feature's keyboard shortcut the same. If it does not work then probably there is no built in.
You can select all the code you want to indent and hit the tab key. It will indent all selected lines. If you want to reduce the indent press shift+tab.
It won't magically fix poorly formatted code, but it will help you quickly indent large blocks.
I don't know how it's related to MS Expressions but you can do the same from this tool: http://www.waterproof.fr/products/phpCodeBeautifier/
Try using PHPStorm IDE to edit/format php code. The IDE has everything you may need to edit/format/deploy/refactor code.
With PHPStorm you can reformat the code by using CTRL+ALT+L.
try this to format the code of an existing page:
Open the web page you want to reformat.
In the Code pane, right-click and select Reformat HTML.

What are the best tips & tricks you use with Eclipse PDT

There are a couple of similar threads here, but most of the other tips don't work on PDT so let's make this one specific to Eclipse PDT for PHP.
I'll start (w/ credit to those that work from other the other threads):
CTRL-SPACE = code completion
CMD-/ = auto comment
CMD-SHIFT-L = key assist
If autocomplete isn't working right and filenames aren't expanding, right
click on project folder and go to php build path and add folder
CMD-SHIFT-t = shows list of classnames
CMD-SHIFT-r = shows list of files
I would say add the Generate Getters and Setters plugin except I just did and it doesn't work for me.
Don't like the #author variable used by the doc block? Change it. Note the comments include the tricky way of fixing this on the Mac.
Something that works for me very well is to customize the coloring of the syntax in the eclipse preferences. It helps me to differentiate the syntax-elements. The standard coloring often allocates the same color to several elements. I ve added a picture of my coloring to this post:
Eclipse PHP Syntax Coloring

Question about software that tracks divs better than notepad++

I recently got hired as a web developer, and the project that I am overseeing has a formatting issue on one of the pages because one of the divs is out of whack. It is a fairly complex page with quite a bit of php, and from what I can gather, I am missing a </div> tag somewhere, and accordingly everything is messed up.
I am currently using notepad++, which is decent at lining up divs, meaning that if you click on the opening div tag, it will highlight purple and also highlight the closing one. But it seems as though if you have div tags that span several lines (hundreds) it won't work.
Has anyone else run into a similar situation? Is there a better editor I could be using that would do a better job of helping me with my div issue? Or do I have to go through and line up the divs 1 by 1? (there are like over 100). Please let me know!! Thanks
An alternate route I would like to suggest is running your page through a validator, such as the W3C service at http://validator.w3.org
HTML Validator is an addon for Firefox that can automatically run your pages through a local validator and notify you of any issues with an icon in the satus bar.
You want an editor that detects and highlights syntax errors in markup (as well as validity). There are many. I use Komodo Edit from ActiveState (www.activestate.com)
A cross platform solution is Eclipse (PDT). It comes with a nice and handy html editor. For quick file changes and hotfixes I use TextMate – but this is OS X only :(
Sometimes, when I have crazy X/HTML that I am trying to clean up/debug I put it into an XML editor and let it do some of the matching/formatting for me. My personal choice is Altova's XMLSpy. It is not free (hell, it's not even cheap), but I really like the power it has. You can download a free demo from their website and see if it helps you out.
Like what others have said, use a free editor like Eclipse. Open your HTML in Eclipse, then press CTRL+SHIFT+F and it will format and indent the code, just like what Notepad++ does.
Is this page already online in public area?
If yes, did you try to validate the HTML/XHTML with W3C validator http://validator.w3.org/, it might tell you the exact line where the closed DIV tag is missing.
UPDATE: you can also copy and paste code of the page deirectly into the validator and validate it: you go with your browser at the page, then you select "View Source" from the browser manu, than you copy & paste code into W3C validator.
You could try using a more "Powerful" editor such as Eclipse or Netbeans. I use Netbeans for most of my HTML / PHP development, and it does a good job of highlighting matching tags.
Vim + matchit plugin
I use http://users.rcn.com/creitzel/tidy.html#tidyui for fixing html.

Any netbeans features that will make my day?

I've recently gotten quite fond of netbeans for my php work because of the XDebug integration. It has made me all but forget about textmate (which imho still beats netbeans for the little things)
What do you think is the one awesome netbeans feature I should know about, and more importantly why and how do I use it?
I'm asking this to optimize my skills in the use of the IDE and based on the idea that what works well for others might just work for me (and hopefully others).
I've found another great snip of genius i wanted to share:
you can do custom code folding (not really related to php, just netbeans)
just put this into a code file:
// <editor-fold defaultstate="collapsed" desc="getters and setters">
some boring code you don't need to see every time here
// </editor-fold>
That'll behave similar to #regions in visual studio or pragma marks in xcode. but unlike regions, it doesn't screw up the working of your code, it's really just a comment!
The Subversion Integration directly on the IDE and the Local History are of my must-use, favorite features.
I find the single most useful feature in Netbeans for PHP work is that it understands PHPDoc (in the same way that it understands Javadoc), and uses it for type hinting.
Type /** before a function definition, hit return and it'll create a PHPDoc template.
/** <-- I typed this one line
* #param <type> $otherObj <-- Netbeans added these 3 lines
* #return <type> <--
*/ <--
public function exampleFunction($otherObj)
{
$myObj = new MyClass($otherObj);
return $myObj;
}
Replace the <type> placemarkers with the appropriate types:
/**
* #param OtherClass $otherObj
* #return MyClass
*/
public function exampleFunction($otherObj)
{
$myObj = new MyClass($otherObj);
return $myObj;
}
And voila, you'll get type completion (and pop-up documentation) with Ctrl-space.
Awesome Vi bindings via the jVi plugin.
if ($x instanceof SomeClass) {
$x->.... // now it has code completion with SomeClass' methods.
}
Macros, and Code Templates with advanced input !
Parametrized code templates (try typing fnc in netbeans and then imediately press Tab, and then keep pressing Tab to see what happens, how it cycles through the function name and the function parameters - look inside the code template to see how this is done).
(Options > Editor > Code Templates )
Some easy examples (some I made, some come with netbeans):
[forek] expands to: [foreach ($array as $key => $value) { }] (This one comes with netbeans, the rest I made)
[arr] + Tab expands to: [array();]
[kv] +Tab expands to: ['key' => "val", ] (key and val are parameters that I canc cycle through and edit with tab. The code template looks like this: ['${key}' => "${val}", ] where [${something}] is a template parameter, it prints [something]. if you want it tio print [$something] I think you have to use three ]$] characters: [$$${key}])
EDIT: You can make a code template for the arrow with a single letter (like 'm' for ex) , but when you type in code you have to put a space before the letter, else it wont recognize it. Ex: $obj m[press Tab], expands to [$obj ->]. The space inbetween works ok and is not a sintax error.
/EDIT
Every time I wish there was a template for something, I actually insert the template and then use it imediately and continue with the rest of the php programming.
Macros with shortcuts as mini code templates ! (Netbeans >Menu > Edit >Start / Stop Macro Recording)
Best Macros I made for php are actually Code Templates (because ' + Tab doesnt work as code template for some reason, only if the template begins with a letter it works) ([shortcut] inserts [text]):
shortcut [Ctrl + ;] inserts [->] (no more
keybooard gymnastics, no more dot
sintax envy on other languages :))
shortcut [Ctrl + Shift + ;] inserts [ => ]
This link has a lot of keyboard shortcuts that comes in handy. I have a copy of it printed out and pinned to the wall next to my computer. Sadly, I don't see any special PHP shortcuts though.
UPDATE: http://netbeans.org/project_downloads/usersguide/shortcuts60.pdf
UPDATE2: http://netbeans.org/project_downloads/www/shortcuts.pdf (for 7.0)
I would add Tasks integration. Don't have time to finalize something? Add a simple task which NetBeans will track for you. You can customize what gets tracked in Tasks in Options -> Miscellaneous -> Tasks, but I found the format below to be most useful, as it aligns well with PHPDoc comments (see therefromhere's comment):
/**
* #todo Create public setters and __toString() for this class.
*/
Ctrl + Space is my favorite and most used feature when programming in java, I think it is enabled for PHP as well. But if you like net beans you most likely know about it already, if not try it out discover what it does.
Also navigating to the relevant source code by Ctrl + Clicking on anything from variables, to method calls, to class references is a nice feature.
Additionally, the popup menus that are displayed when right clicking in source code contain many useful tools for everything from refactoring to code generation.
This is going to sound ridiculously trivial, but one thing I do in Netbeans is code formatting. Its code formatting (source->format) rocks.
Its SVN integration is great too, but that's already been said.
The ability to create quick on the fly macros.
For example , here is one that will put a semi-colon at the end of the current line and places your cursor back where it was before the macro started.
";" delete-previous caret-end-line ";" jump-list-last-edit jump-list-last-edit
(I know this is present in other language implementations by default. But it does not work by default in PHP Netbeans.)
As someone who tends to stick with IDE for a long time, I love being able to customize little things to make me more efficient.
If you consider Netbeans 6.7 it has a sync feature a bit like Dreamweaver
In the way that you can add a custom ftp, import it to the project and when you save the files locally they are also uploaded to the server so you have a semi backup system in place.
(trust me it's better than working directly onto a ftp tree and realizing that the transfer failed somehow between the current tmp file and the server file and you lost your work because you closed the file window :) )
NetBeans also allows you to completely undock individual windows.
How to:
Right-click on toolbar of the window which you want to move and select Undock window. The selected window becomes a floating one, which allows you to move it outside of the main NetBeans window.
Highlights:
you can pin floating windows to screen borders or to different floating windows (just the ones from NetBeans though)
floating windows can make themselves semitransparent if you move away from them (configurable via main settings in Miscellaneous/Appearance)
if you move a different application over any floating windows, they come back on top after you start using NetBeans again
your workspace layout is remembered, so all floating windows keep their respective positions between individual coding sessions (NetBeans restarts)
This is useful especially if you have a second monitor, as it allows you to maximize the space available for source code by moving any supplementary windows (the file browser, unit test results, etc) away from the main screen. The nice thing is that NetBeans works around most annoyances which are usually present in multi-window applications (e.g. different applications covering individual toolbars in GIMP).
Note: perhaps this is commonly known feature, but I managed to discover it just today. It wasn't on the list yet, so I added it even though I already answered with a different feature some time ago.
Squiglies under unused private class members.
maybe the search box, to find anything in the source code`?
Some features definitely worth looking out for, including the ones mentioned above:
Version control Integration, including Local History
IDE wide search box
Integration with Tomcat/Apache, GlassFish can be helpful when you are looking to work with PHP and other server side technologies, like JSP
Very good integration with MySQL- essential to wAMP/LAMP development
TextMate is a great slick little editor I use all the time on my Mac, but not an IDE. I haven't enjoyed Netbeans on Mac very much being so non-native, but on Windows or Linux I prefer it over Eclipse.
The Swing GUI designer with Java has been huge in getting projects done rapidly.
Other people have said it, but integrated Subversion is awesome. If I've been working with a project from the terminal in Linux it figures out I've got SVN checked out on that directory and handles it fine.
I love the code formatting (right click in the editor), especially when team members write poorly spaced/indented code with nano, xemacs, or something like that.
its amazing that no one has talked about this cool plugin.
http://code.google.com/p/zen-coding/
I have found it very useful for html. PHP developers do need it. It adds a lot of templates like this.
download zen-coding for netbeans and import zip file in tools>options>code templates>import.
I like this the most: phpunit + code coverage
I've personally used Eclipse a couple of years ago for Java development, and ever since i knew Netbeans at version 3.5, it has gotten really good with the integration of server technologies as TomCat for J2EE application deployment, subversion, uml and plenty of plug-ins for different tecnologies, not just java now.
Database integration (MySQL, Jdb, SQL editor).
Continuous progress in PHP integration and features.
Subversion integration...it does help A LOT!
Code indent, custom color highlighting.
If you are a PHP developer, Ruby on Rails integration can be of help too, if you want to expand your expertise on web apps.
Netbeans has always been known for delivering support for experimental (not-yet-released) technologies, such as Java 6 EE preview, JDK7 support, ...
And, subversion support out-of-the box. It's a great difference to Eclipse, where you have to use plug-ins. With Eclipse I had only problems under Linux (JavaHL problems, blabla...). I don't remember who said it, or where it is written, but "out-of-the-box support is much more relevant to a user than the ability to use some plug-ins".

Categories