By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

how do you move to a new line in your text editor?

P: n/a
This is a real small point, but I'd like to hear what others do in this
case. It's more an 'administrative' type question than Python code
question, but it still involves a bit of syntax.

One thing I like to do is use tabs for my indentation, because this
makes it easy to outdent when I need to start a new line in column 1. I
can press backspace once and move 4 spaces to the left.

But I read in the PEP that spaces are recommended over tabs. If this is
the case, it would involve pressing backspace 4 times (or 8, etc.) to
get back to column 1.

So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.
Mar 2 '06 #1
Share this Question
Share on Google+
24 Replies


P: n/a
John Salerno wrote:
So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.


Emacs, at least, outdents reliably with spaces. Probably some other
editors do as well, though I was kind of surprised to find out that
some editors have (compared to Emacs) weak indent inference.

If editing with spaces annoys you, it might be possible with your
editor (which seems to have a variable tab stop) to edit the file with
tabs, but save it with spaces.
Carl Banks

Mar 2 '06 #2

P: n/a
Carl Banks wrote:
John Salerno wrote:
So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.


Emacs, at least, outdents reliably with spaces. Probably some other
editors do as well, though I was kind of surprised to find out that
some editors have (compared to Emacs) weak indent inference.

If editing with spaces annoys you, it might be possible with your
editor (which seems to have a variable tab stop) to edit the file with
tabs, but save it with spaces.
Carl Banks


I use UltraEdit right now, and it is possible to convert spaces and tabs
back and forth, but it's just an extra step. I was thinking about trying
vim, as I've heard it's easier to learn than emacs.
Mar 2 '06 #3

P: n/a

John Salerno wrote:
Carl Banks wrote:
John Salerno wrote:
So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.


Emacs, at least, outdents reliably with spaces. Probably some other
editors do as well, though I was kind of surprised to find out that
some editors have (compared to Emacs) weak indent inference.

If editing with spaces annoys you, it might be possible with your
editor (which seems to have a variable tab stop) to edit the file with
tabs, but save it with spaces.


I use UltraEdit right now, and it is possible to convert spaces and tabs
back and forth, but it's just an extra step. I was thinking about trying
vim, as I've heard it's easier to learn than emacs.


Well, they don't call vi the "Very Intuitive" editor for nothing. I
suspect if you're not used to the modes and movement keys and stuff
it'll be a little steep learning at first. More power to you if you
can get used to that.

You wouldn't know if Ultraedit has some kind of hook mechanism (whereby
it can execute a macro or script or something upon loading/saving).
That could solve your problem. Obviously, having to manually convert
isn't too helpful.

Carl Banks

Mar 2 '06 #4

P: n/a
John Salerno wrote:
But I read in the PEP that spaces are recommended over tabs. If this is


If you like tabs, stick with tabs. There isn't any reason to use spaces
unless your boss is demanding it. Tabs are the slightly better choice,
in my humble opinion.

That said, you should be able to tell your editor how to behave in the
indent/unindent case, no matter whether you use tabs or spaces. If not,
time to switch editors! ;)

--
Paul
Mar 2 '06 #5

P: n/a
Carl Banks wrote:
You wouldn't know if Ultraedit has some kind of hook mechanism (whereby
it can execute a macro or script or something upon loading/saving).
That could solve your problem. Obviously, having to manually convert
isn't too helpful.


I'll have to check on that. I know I can do macros and such, but I'll
have to see about having it done automatically.
Mar 2 '06 #6

P: n/a
Paul McNett wrote:
That said, you should be able to tell your editor how to behave in the
indent/unindent case, no matter whether you use tabs or spaces. If not,
time to switch editors! ;)


I definitely can, I'm just a little unsure about what the special
outdenting cases might be. The way to do it in UltraEdit is to specify
which characters (on a preceding line) an outdented line should follow,
so obviously for a C language you could specify Unindent = '}' and that
would help a lot. But with Python it seems more difficult to figure out
the cases where you would outdent.

Mar 2 '06 #7

P: n/a
John Salerno wrote:
I use UltraEdit right now, and it is possible to convert spaces and tabs
back and forth, but it's just an extra step. I was thinking about trying
vim, as I've heard it's easier to learn than emacs.

Absolutely. It's also easier to learn to ride a Huffy than a Schwinn,
Hondas are easier to drive than Toyotas, and Evian is easier to drink
than Poland Spring.

Do yourself a favor and learn them both. Then decide which is best for you.

Bill
Mar 2 '06 #8

P: n/a
Bill Scherer wrote:
John Salerno wrote:
I use UltraEdit right now, and it is possible to convert spaces and
tabs back and forth, but it's just an extra step. I was thinking about
trying vim, as I've heard it's easier to learn than emacs.

Absolutely. It's also easier to learn to ride a Huffy than a Schwinn,
Hondas are easier to drive than Toyotas, and Evian is easier to drink
than Poland Spring.

Do yourself a favor and learn them both. Then decide which is best for you.

Bill


Point taken. I like to just pick something and go with it, but sometimes
I just need to experiment first.
Mar 2 '06 #9

P: n/a
On Thu, 02 Mar 2006 18:39:55 GMT
John Salerno <jo******@NOSPAMgmail.com> wrote:
But I read in the PEP that spaces are recommended over tabs. If this is
the case, it would involve pressing backspace 4 times (or 8, etc.) to
get back to column 1.

So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.


I use Vim, use spaces, and have no problems. It has a shorttabstop
option, which causes backspace to backspace to the preceding multiple
of <tabwith> spaces when the curser is after a set of spaces at the
beginning of the line. It feels like I'm using tabs, but I'm not.

Also, there's some Python indenting/folding macros I picked up from Vim
Online (don't remember where exactly), that provide an indent/outdent
pair of key mappings, which also work perfectly with my usage of 4
spaces.

- Michael

--
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
Mar 2 '06 #10

P: n/a
> I use Vim, use spaces, and have no problems. It has a
shorttabstop option, which causes backspace to backspace
to the preceding multiple of <tabwith> spaces when the
curser is after a set of spaces at the beginning of the
line. It feels like I'm using tabs, but I'm not.
In addition, within insert-mode in vim, you can use
control+D and control+T to exdent/indent the current one
'shiftwidth' worth. If your 'shiftwidth' setting is the
same as your 'tabstop' setting, you'll get the expected
behavior. There are also settings to control whether tabs
get interpreted as spaces or vice-versa (see ":help
expandtab"). I presume Emacs has similar settings.
However, Vim can be tweaked to handle whatever style you're
comfortable with (or whatever style management shoves down
on you). The "shiftwidth = tabstop" also holds for the ">"
and "<" operators, so in Normal mode, you can use ">>" to
indent the current line, or "<3j" to exdent the current line
and the three below it. All sorts of magic can be worked
with this :)
Also, there's some Python indenting/folding macros I
picked up from Vim Online (don't remember where exactly),
that provide an indent/outdent pair of key mappings,
which also work perfectly with my usage of 4 spaces.


If you pop over to www.vim.org you'll find a search
functionality to search both the "tips" and "scripts"
section. Just searching for "python" yields a bounty of
fun. For folding, because python uses indenting, you can
just set your 'foldmethod' setting to "manual".

Okay...this has drifted just a wee spot off-topic. However,
the vim mailing list is a friendly place--so if you have any
questions, feel free to drop in.

-tkc



Mar 2 '06 #11

P: n/a
John,
This is a real small point


No point is small when you apply it hundreds of times a day. I spent
quite a bit of time on this element and ended up allowing conversion
from tabs to spaces and the reverse. Who knows what you'll find in the
world of ASCII.

Historically, Tabs were stops on the typewriter carriage, a control
function. This Tabs = Spaces thing came about largely because of
cursor bondage.

So how do YOU think of a Tab key? Is it a data key or a control key?

Internally, I treat Tab (and Shift Tab) as a navigation (control) key
instead of pumping in lots of spaces. It seems more useful that way.
But then Sudden View doesn't have "cursor bondage" to worry about.

Sudden Disruption

Try Sudden View - for the art of editing text
Beta test now in progress at...
http://www.sudden.net/

Mar 3 '06 #12

P: n/a
> One thing I like to do is use tabs for my indentation, because
this makes it easy to outdent when I need to start a new line
in column 1. I can press backspace once and move 4 spaces to
the left.
Zeus has a Smart Backspace feature (configurable on or off) where
by it will try to line up the current line with the lines of code
above on any backspace key press.

This means that in the case you describe a backspace will always
move back 4 spaces whether the white space is made up of tabs
or spaces.
But I read in the PEP that spaces are recommended over tabs. If
this is the case, it would involve pressing backspace 4 times (or
8, etc.) to get back to column 1.


It only takes one key press if you are using Zeus ;)

Jussi Jumppanen
Author: Zeus for Windows
Zeus for Windows IDE
http://www.zeusedit.com

Mar 3 '06 #13

P: n/a
John Salerno wrote:
But I read in the PEP that spaces are recommended over tabs. If this is
the case, it would involve pressing backspace 4 times (or 8, etc.) to
get back to column 1.


In the editor which I use, pressing the tab key indents the current line
under the previous one the first time you press it near the start of a
line, then indents a further 4 spaces every other time you press it. The
backspace key deletes the previous character, unless there is only
whitespace before it in the line in which case it deletes back to the
previous tabstop.

This sort of configuration is common to most programming editors: keys
should work in an intuitive manner and don't have to be dumb.

Mar 3 '06 #14

P: n/a
John Salerno wrote:
This is a real small point, but I'd like to hear what others do in this
case. It's more an 'administrative' type question than Python code
question, but it still involves a bit of syntax.

One thing I like to do is use tabs for my indentation, because this
makes it easy to outdent when I need to start a new line in column 1. I
can press backspace once and move 4 spaces to the left.

But I read in the PEP that spaces are recommended over tabs. If this is
the case, it would involve pressing backspace 4 times (or 8, etc.) to
get back to column 1.
you can still use tabs for editing, and if you want to provide space indented
code you can write a small tab2space converter in python

more seriously, most of the editors (at least Emacs and vim) may use tab for
automatic indentation but convert the tabs to a specified space number

Eric
-- Le lecteur c'est Outlook express (ceci explique sans doute celà)

Outlook Express, c'est fait pour demander comment configurer Emacs
pour lire le courrier et les news.
-+- GK in Guide du linuxien pervers - "De l'utilité de Outlook" -+-
Mar 3 '06 #15

P: n/a
On Thu, 02 Mar 2006 18:58:50 GMT, John Salerno wrote:
I use UltraEdit right now, and it is possible to convert spaces and tabs
back and forth, but it's just an extra step.


I wouldn't definitely suggest UltraEdit to code Python.
Probably you should try scite.

I'm using TextMate (but it's MacOS only). When on Linux I use Emacs or vim
(depends on what I find on the machine). On Windows I prefer gvim to Emacs,
since I've not yet found a well integrated Emacs distribution (I said I
did't find it, not that it doesn't exist).
--
USB Priests for only 10$
Mar 3 '06 #16

P: n/a
On Linux you can try out Scribes. It has a function to convert tabs to
spaces. Personally, I use tabs in all my projects.

http://scribes.sf.net/snippets.htm

http://scribes.sf.net/

Mar 3 '06 #17

P: n/a
Mc Osten wrote:
On Thu, 02 Mar 2006 18:58:50 GMT, John Salerno wrote:
I use UltraEdit right now, and it is possible to convert spaces and tabs
back and forth, but it's just an extra step.


I wouldn't definitely suggest UltraEdit to code Python.


Why do you say that?
Mar 3 '06 #18

P: n/a
On Fri, 03 Mar 2006 16:48:11 GMT, John Salerno wrote:
Why do you say that?


Because I tried it and it just lacks a lot of functionality you get with
TextMate or Emacs. It is quite stupid when indenting, just to name one.

--
USB Priests for only 10$
Mar 3 '06 #19

P: n/a
John Salerno wrote:
This is a real small point, but I'd like to hear what others do in this
case. It's more an 'administrative' type question than Python code
question, but it still involves a bit of syntax.

One thing I like to do is use tabs for my indentation, because this
makes it easy to outdent when I need to start a new line in column 1. I
can press backspace once and move 4 spaces to the left.

But I read in the PEP that spaces are recommended over tabs. If this is
the case, it would involve pressing backspace 4 times (or 8, etc.) to
get back to column 1.

So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.


I apologize for the OT nature of this question, but it's at least
on-topic as far as this thread goes! :)

Anyway, one problem I have in UltraEdit when I'm writing HTML is that
linewrapping is never handled quite right when using soft returns. Hard
returns screw things up when you need to edit the text, so it's not a
good option. But with soft returns, the lines wrap to column 1 of the
next line, and they don't line up properly (indentation-wise) with the
line being continued.

Do emacs or vim allow you to line up wrapped lines like this without
actually inserting return or space or tab characters in the text?
Mar 3 '06 #20

P: n/a
Mc Osten <ri**@despammed.com> writes:
Because I tried it and it just lacks a lot of functionality you get with
TextMate or Emacs. It is quite stupid when indenting, just to name one.


This is the main motive I don't use PyDev with Eclipse... It is a lot more
stupid than python-mode on Emacs with regards to indenting... :-(

--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Mar 4 '06 #21

P: n/a
Which indenting features do you find missing? Note: 1.0.3 -- still
unreleased -- has implemented if / elif /else auto unindent...

Jorge Godoy wrote:
Mc Osten <ri**@despammed.com> writes:
Because I tried it and it just lacks a lot of functionality you get with
TextMate or Emacs. It is quite stupid when indenting, just to name one.


This is the main motive I don't use PyDev with Eclipse... It is a lot more
stupid than python-mode on Emacs with regards to indenting... :-(

--
Fabio Zadrozny
------------------------------------------------------
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

Pydev Extensions
www.fabioz.com/pydev

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com
Mar 6 '06 #22

P: n/a
Fabio Zadrozny <fa****@esss.com.br> writes:
Which indenting features do you find missing? Note: 1.0.3 -- still unreleased
-- has implemented if / elif /else auto unindent...


The most basic one is not having my code moving forward with sucessive TABs
pressed. When I press TAB on Emacs it use a soft tab (i.e. what Eclips calls
'space-tab') and indent my code to the next indentation level and stop
indenting. Even when in the middle of the line and if I'm in the beginning of
the line it moves the cursor to the beginning of the code.

Another that is related is pressing that to remove indentation from the code:
TAB means go to the next indentation level, no matter where the line starts.

The third is using BACKSPACE to remove indentation from my code: if I'm in a
nesting level and I want to move my code one level down, I have to press
backspace 'n' times (n == the number of spaces used by soft tabs in my Eclipse
configuration) on lines where I have code. (The menu option 'Python
backspace' doesn't work.)

These are the most annoying things since in Python indentation matters and we
use it a lot.

--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Mar 6 '06 #23

P: n/a
Ok, I'm putting those in my 'todo-list' ;-)

-- keep an eye open for future releases...

Cheers,

Fabio

Jorge Godoy wrote:
Fabio Zadrozny <fa****@esss.com.br> writes:
Which indenting features do you find missing? Note: 1.0.3 -- still unreleased
-- has implemented if / elif /else auto unindent...


The most basic one is not having my code moving forward with sucessive TABs
pressed. When I press TAB on Emacs it use a soft tab (i.e. what Eclips calls
'space-tab') and indent my code to the next indentation level and stop
indenting. Even when in the middle of the line and if I'm in the beginning of
the line it moves the cursor to the beginning of the code.

Another that is related is pressing that to remove indentation from the code:
TAB means go to the next indentation level, no matter where the line starts.

The third is using BACKSPACE to remove indentation from my code: if I'm in a
nesting level and I want to move my code one level down, I have to press
backspace 'n' times (n == the number of spaces used by soft tabs in my Eclipse
configuration) on lines where I have code. (The menu option 'Python
backspace' doesn't work.)

These are the most annoying things since in Python indentation matters and we
use it a lot.

--
Fabio Zadrozny
------------------------------------------------------
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

Pydev Extensions
www.fabioz.com/pydev

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com
Mar 6 '06 #24

P: n/a
John Salerno wrote:
So I'm wondering, how do you all handle moving around in your code in
cases like this? Is there some sort of consistency to these things that
you can write rules for your text editor to know when to outdent? It
doesn't seem like you can do this reliably, though.

Under windows, I'm using SciTE which is an extremely lightweight editor,
but it handlers "smart unindent": pressing backspace at the beginning of
a line unindents one level, whether you're indenting with tabs (and need
to remove a tab) or space (and need to remove 2, 4, 8 spaces) doesn't
matter. And since SciTE also has Visual Studio's smart home key (home
brings you first at the beginning of the text == current indent, then at
the beginning of the line itself == indent level 0)

SciTE also features "somewhat smart" indent from time to time: it
indents one level after a ":". This is good for if/else/while/..., but
it also indents one level after ":" in dicts, which is way bad.
Oh, and it automatically unindents one level after a "return" statement.

Other than that, SciTE doesn't really "understand" python, if you want a
really pythonic editor you need to check Stani's Python Editor, WingsIDE
or Komodo.
Mar 6 '06 #25

This discussion thread is closed

Replies have been disabled for this discussion.