Automatic indentation on Eclipse PDT when copy-pasting
Asked Answered
M

6

10

This is a simple question :

Is there any automatic indentation alignment on Eclipse PDT when you do a copy-paste ?

Because it doesn't work on my installation (raw copy-paste), but maybe this is because I use tabs instead of spaces, so I want to know if it will work if I switch to spaces.

Thanks

Meri answered 18/3, 2010 at 13:6 Comment(0)
M
0

Ok then I guess the answer is : no, this functionnality doesn't exists yet. I've moved to PhpStorm and I'm more than happy.

Meri answered 22/3, 2010 at 9:27 Comment(2)
Just to let everyone know, PhpStorm has this functionnality.Meri
This is a super old post but since this is still the accepted answer I figure I'd note that Eclipse does have this feature now. For PHP development it is found under Window -> Preferences -> PHP -> Editor -> Typing -> "When Pasting" Adjust Indentation.Suribachi
A
28

Actually, such a function exists now for eclipse CDT. In preferences : C++ -> Editor -> Typing, "when pasting", "adjust indentation".

Perhaps it is the same for PDT ?

Agnesse answered 12/10, 2011 at 12:29 Comment(6)
(I know this question is 1 year old, question found via google, I answer for other googlers)Agnesse
Thanks for the answer, even though the question is a year old, it still hold given no solution was found. I'll check that out if I open PDT again.Meri
@Matthieu Found this searching on Google and solved my problem. You should accept his answer.Asuncion
@Asuncion The question was for Eclipse PDT (and last time I checked there was no such functionnality)Meri
@MatthieuNapoli Last time I checked (just now g), the same feature is available for the PHP Editor (although it's using global indentation and not the project specific one on my system).Astronomy
The same functionality exists for Java. In preferences : Java -> Editor -> Typing, "when pasting", "adjust indentation".Assume
S
6

I don't know specifically about PDT, but normally you can indent code with Ctrl + i, and format code with Ctrl + Shift + f (under Preferences -> Java -> Code Style -> Formatter you can specify how the formatter should work).

You can even select multiple files in the navigator and select Source -> Format to format several files then.

Scroop answered 18/3, 2010 at 13:23 Comment(3)
Yep, but I would like that to be performed on a "paste" automatically.Meri
+1 Thank you very much, it has been a trouble to redefine the indentation by hand after copy paste! This solution Works great for me!Yclept
Well, together it's actually just a slight roll of the wrist from ctrl + v to ctrl + shift + f @MatthieuNapoli. :)Excellence
O
6

Tony Vermeiren had a suggestion that worked for me (from https://bugs.eclipse.org/bugs/show_bug.cgi?id=351771#c17)

open workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.php.ui.prefs

add "smartPaste=false" at the end

save & restart eclipse

Overset answered 3/12, 2013 at 22:57 Comment(3)
"smartPaste" lol Yes it screw up my format in a very smart way with any interface to disabled that so so smart piece of shcode, is there a conspiracy or something for pushing bugs and ppor formating tools in eclipse? Why eclipse developers hate the other developers so much.Oodles
Thank you so much for this. I was loosing my mind. Would give you some of my reputation points, but I can see you have much more of them than me :-)Headrick
For CDT, replace "php" with "cdt". And as the author has said, do not forget to save the file and restart eclipse. This is a big time saver.You
A
0

A similar idea to Davids is the use of Save actions: in the Preferences selecting Java/Editor/Save actions you can define an action to format the java code files during saves. It would solve the paste format problems during the save.

If you manage codes with different coding standards, where this formatting might have problems, define multiple formats, on a per-project basis (using the Project properties window).

Alf answered 18/3, 2010 at 14:13 Comment(2)
There is no such option in Eclipse PHP ("PHP/Editor/Save actions"). Lucky Java. But still it would be on save, this is too bad it doesn't exists on a paste...Meri
Sorry - I missed PDT for PDE. I hate these acronyms :).Add
M
0

Ok then I guess the answer is : no, this functionnality doesn't exists yet. I've moved to PhpStorm and I'm more than happy.

Meri answered 22/3, 2010 at 9:27 Comment(2)
Just to let everyone know, PhpStorm has this functionnality.Meri
This is a super old post but since this is still the accepted answer I figure I'd note that Eclipse does have this feature now. For PHP development it is found under Window -> Preferences -> PHP -> Editor -> Typing -> "When Pasting" Adjust Indentation.Suribachi
A
0

TLDR: uncheck "C/C++->Editor->Typing->Adjust indentation"

Explanation:

When i copy paste the following:

copyPasteMakredText

And "C/C++->Editor->Typing->Adjust indentation" checked

enter image description here

The result is that the second line has unwanted indentation:

enter image description here

To fix this just uncheck "C/C++->Editor->Typing->Adjust indentation"

Annettannetta answered 16/5, 2019 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.