2

I'm new to eclipse. One thing I notice about eclipse+PyDev is that it give me warning if the indentation is not in multiple of 4 space. That is fine because I could use "reindent.py" to just reindent it. And I manage to setup it as the external tools. But the problem is, when I use it, (using Run->Externaltools->reindent) it would modify the code in the background, so after that, it would pop up saying that the source code has been modified (duh!) would you like to to reload the file? (duh again!) So, my question is, is there a way to pipe the current selection of the source code through reindent (it uses standard input/output when given no argument) and then replace the selection with reindent standard output automatically. Thanks!

asdacap
  • 738
  • 2
  • 9
  • 15

2 Answers2

1

Check in the preferences > general > workspace if you have 'refresh on access' and 'refresh with native hooks' both checked (that may solve your problem).

Another thing to check is in your external tool configuration: it has a 'refresh' tab, where you can choose to refresh the selected resource upon completion.

Another thing... if you have things just in a different indent (say 2 spaces), you can simply replace all 2 spaces by 4 spaces in the find instead of going through reindent...

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • Found your answer when looking for a way to have an external script automatically update in the workspace. Thanks! Was integrating autopep8.py as an external tool. Works great now. – tom stratton Sep 09 '12 at 18:16
0

When you run reindent.py as an external tool, you modify the whole file that contains the source code, not the current selection in your editor. But according to PEP 8 you should not mix tabs and spaces, so this might actually be what you want. In that case just click ok to reload the file and find that it worked.

In the settings you find some options under Window->Preferences->PyDev->Editor

There you can activate automatic replacement of a tabs with spaces when typing. Also you can choose that PyDev assumes tab-spacing for files that contain tabs.

You might want to read this: How to integrate pep8.py in Eclipse?

When you activate Window->Preferences->PyDeV->Editor->Code Analysis->pep8.py you can generate a warning for every line, that conflicts with the convention.

Community
  • 1
  • 1
Schuh
  • 1,045
  • 5
  • 9
  • Of course it worked, after I reload it. I'm just wondering If there is a better way to do it, ie: edit the current selection or something, seems to be more integrated. And about the mized space and tabs, I used to do this project on kate...I'm new to eclipse. So, there are already some of python+html+"other guy's python" in the project, that's why I can't just reindent -r it. But thanks for the pep8 link. – asdacap May 15 '12 at 04:58