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

J

John Salerno

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.
 
C

Carl Banks

John said:
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
 
P

Paul McNett

John said:
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! ;)
 
J

John Salerno

Carl said:
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.
 
C

Carl Banks

John said:
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
 
B

Bill Scherer

John said:
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
 
J

John Salerno

Carl said:
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.
 
J

John Salerno

Paul said:
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.
 
J

John Salerno

Bill said:
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.
 
M

Michael Ekstrand

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
 
T

Tim Chase

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
 
S

Sudden Disruption

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/
 
J

jussij

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
 
D

Duncan Booth

John said:
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.
 
E

Eric Deveaud

John said:
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" -+-
 
M

Mc Osten

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).
 
M

Mc Osten

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.
 
J

John Salerno

John said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top