Format only selected code in eclipse - eclipse

As the title says, I want to format only selected lines of code. I know by pressing Ctrl + Shift +F formats whole file.
Formatting whole file is not good options as it will create lots of conflicts when I will commit the file. I changed a portion of the file (copied some code from internet etc.).
Is there any easy way to format selected lines in eclipse. I have searched a lot but found no solution.
I am working with PHP.

Highlight (left click, drag, left release) the lines you want to format, and press Ctrl + Shift + F, or right click and select Source -> Format.
For Java code, you have to highlight a complete piece of code (statement(s), method).
For PHP, I imagine you would still have to highlight a complete piece of code.
Tested on Windows version of Eclipse 4.2.

Related

Copy text of error msg from circled-X in Eclipse source editor

I'm trying to fix literally hundreds of XML validation errors in a Java webapp using Eclipse. Researching them with Google has been excruciatingly painful, because up to now, this has been my workflow:
Open Google in a browser.
Click in the Eclipse editor tab where the error (shown as an icon at the start of the line that's a red circle with a white "X") is located, mouseover, and try to memorize a chunk of it.
Click on the search form in the browser, and attempt to replicate the chunk from memory.
Repeat steps 2-3 until the text in the search form matches the text Eclipse ephemerally displays on the screen. Usually, something like:
"cvc-complex-type.2.4.d: Invalid content was found starting with element 'description' No Child element is expected at this point."
(that's just one error out of thousands, shown for illustration. I copied it from memory in 5 or 6 chunks)
At the moment, it's blowing my mind that there doesn't appear to be any easy way in Eclipse to do something like right-click the error icon & choose "copy error description"... or at least display it in some way that will survive giving another window the input focus so I can read it while typing it into the search form.
I know there has to be a better way to do this.
I suspect the error descriptions are present somewhere on the "Problems" tab, but I literally have almost 10,000 Errors & Warnings there, and no obvious way I'm aware of to sort or filter them. Is there maybe some keyboard modifier + mouse action that will allow me to click the red/white X icon and have Eclipse take me directly to the error on the Problems tab?
Good question, and I feel for you, there is a slightly easier way. I'm running Eclipse Kepler but I suspect this will work for you too.
Roll your mouse cursor over the problem x icon in the editor gutter (if you're showing line numbers it will be in that area), wait till the tool tip displays the error message, then quickly move your cursor over the tool tip and click within the text, then you can select all (Ctrl + a) and copy (Ctrl + c), then paste wherever the error description.

Compare editors in eclipse

I sometimes work with 2 editors in eclipse (splitting screen vertically)
I know for starters that you can compare two files by selecting them from the navigator (Ctrl + Click for example) and then hitting compare or even with a keyboard shortcut
But i am wondering if there is a way in the current release to kinda bypass the compare window which always shows up and automatically select the active file from the editor on the left and the active file from the editor on the right just like in notepad++ (where i could just have two views and hit Alt + D there and automatically the files are compared)
Any help is appreciated, thanks
There is no such feature in Eclipse. Of course, you're always free to write a plugin that can do what you want. The learning curve is a little steep but overall what you're describing probably wouldn't be too much work once you got the hang of plugin writing.
Here are some links to get you started:
http://www.vogella.com/articles/EclipsePlugIn/article.html
http://www.vogella.com/eclipse.html
http://www.eclipse.org/resources/?sort=date&category=Plug-ins

Eclipse Code Formatting

I have switched my development environment from Adobe DreamWeaver to Eclipse, and I had one question regarding the Eclipse environment. Whenever I copy and paste sections of code from one area of a script to another, often times the indenting isn't consistent with the surrounding code.
Is there a way I can indent/outdent large sections of code instead of having to manually correct them on a line-by-line basis?
Thank you for your time.
To indent or outdent a section of code, you can select the entire section and then press tab or shift-tab.
I do Java development in Eclipse and to format code I select it and press Ctrl + Shift + F. It is also available from Menu -> Source -> Format.
Note that I am working with Eclipse 3.5.1, but I dont think this key combination will change for other versions.

Is there a way to copy code from the Eclipse IDE without the rich-text formatting?

Recently every time I copy a block of code from Eclipse and paste the code into TextEdit or a online forum using the code tags, I get the code with the rich-text or html formatting, so I have to copy into a text editor remove the formatting copying and pasting again, In the past this was not a problem I used to copy from eclipse and paste the code without any formatting at all just as plain-text, I dont know if I turn on a property or what I did for this to happen, any ideas how to fix this?
There is an Eclipse bug filed for this that can be voted for:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=45969
It has been open for 10 years though!
There are applications out there that think they can handle rich text but can't. So for those it looks like we'll have to carry on with "Copy-Switch to Notepad-Paste-Select All-Copy-Switch to final app-Paste" for some time yet.
Note: the rich formatting from a SWT editor seems to have always been available (bug 64498).
You could use "Edit, Paste and Match Style" in TextEdit.
From the Edit menu, choose Paste and Match Style,
or use the keyboard shortcut, Shift Option Command V.
The pasted text will pick up all the formatting from the character to the left of the flashing insertion point. This technique works in Mail as well.

What are the must know shortcuts in Xcode for faster application development?

What are the must know shortcuts in Xcode for faster application development?
As a special interest, the Mac shortcut I want to know is the one to open application menus (File, Edit, View, Project, Build etc.,). In Windows, if we type Alt + F, the File menu will drop down, and we can navigate through the sub-menus using the arrow keys or typing the letters that are underlined in the menus. How can we do something like that in Mac?
Thanks..
For debugging:
CMD+SHIFT+I (step into)
CMD+SHIFT+O (step)
Building & Running:
CMD+B (build project)
OPT+CMD+ENTER (debug project)
This is the PDF for all the shortcuts of Xcode
All Xcode Shorcuts
I hope it helps.
Alt + Cmd + Up to toggle between .h and .m files of a class
Cmd + ' to move to next error or warning
Cmd + Shift + ' to move to previous error or warning
Column Selection: Holding down the option key while dragging allows you to perform a column based selection of text. Might be useful in limited circumstances.
Control-. to select the next autocompletion, control-/ to select the next placeholder (add shift for previous), control-escape to show autocompletion list.
As a response to your request, if you have full keyboard access turned on, control-fn-F2 will select the menu bar. Then use the arrows to select an item, and space to choose it.
These shortcuts are for Xcode 3.2.x (they may vary from Xcode 3.1.x and other versions):
Command-double click on symbol/method name in source code editor > Open the .h file for symbol
Option-double click on symbol/method name in source code editor > Open the documentation for symbol
Command-Option-Shift-F > Find Selected Text in Project (custom shortcut)
I have the following one setup in User Scripts under Code to insert a standard logging call:
The inserted text is:
NSLog(#"[%# %#]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
Shift-Command-D (Xcode 3.2) / Shift-Command-O (Xcode 4): Open quickly. Great way to get to the file you want.
"Alt + Cmd + Up to toggle between .h and .m files of a class"
This seems to have been disabled in Xcode 4. I've not been able to find a way to set it in Bindings, either. Any hints?
Update: Just found it. It has been changed to "Ctrl + Cmd + Up". It can also be executed with a three finger swipe up or down.
The command, by the way, is called "Jump to Next Counterpart". I knew that.... :-/
Sometimes it takes a Ph.D. in linguistics to figure computer terminology out. And I've been doing this since the early 80s.
Click on any method name in the Xcode.
Then use ALT + CMD + / to insert comments describing the input and return parameters.
This will encourage you to write descriptive comments explaining what is the method supposed to do, thus leading to a more maintainable code.
Use CMD + SHIFT + O to open the Open Quickly Dialog. While you type classes, methods and files will appear matching your entered description. Pressing enter will go to said method, class or file. This greatly improved productivity for me.