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

Discussion in 'Python' started by John Salerno, Mar 2, 2006.

  1. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Mar 2, 2006
    #1
    1. Advertising

  2. John Salerno

    Carl Banks Guest

    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
     
    Carl Banks, Mar 2, 2006
    #2
    1. Advertising

  3. John Salerno

    Paul McNett Guest

    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
     
    Paul McNett, Mar 2, 2006
    #3
  4. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Mar 2, 2006
    #4
  5. John Salerno

    Carl Banks Guest

    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
     
    Carl Banks, Mar 2, 2006
    #5
  6. John Salerno

    Bill Scherer Guest

    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
     
    Bill Scherer, Mar 2, 2006
    #6
  7. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Mar 2, 2006
    #7
  8. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Mar 2, 2006
    #8
  9. John Salerno

    John Salerno Guest

    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.
     
    John Salerno, Mar 2, 2006
    #9
  10. On Thu, 02 Mar 2006 18:39:55 GMT
    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.
    >
    > 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
     
    Michael Ekstrand, Mar 2, 2006
    #10
  11. John Salerno

    Tim Chase Guest

    > 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
     
    Tim Chase, Mar 2, 2006
    #11
  12. 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/
     
    Sudden Disruption, Mar 3, 2006
    #12
  13. John Salerno

    Guest

    > 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, 2006
    #13
  14. John Salerno

    Duncan Booth Guest

    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.
     
    Duncan Booth, Mar 3, 2006
    #14
  15. John Salerno

    Eric Deveaud Guest

    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" -+-
     
    Eric Deveaud, Mar 3, 2006
    #15
  16. John Salerno

    Mc Osten Guest

    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$
     
    Mc Osten, Mar 3, 2006
    #16
  17. John Salerno

    Mystilleef Guest

    Mystilleef, Mar 3, 2006
    #17
  18. John Salerno

    John Salerno Guest

    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?
     
    John Salerno, Mar 3, 2006
    #18
  19. John Salerno

    Mc Osten Guest

    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$
     
    Mc Osten, Mar 3, 2006
    #19
  20. John Salerno

    John Salerno Guest

    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?
     
    John Salerno, Mar 3, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    736
    Stylus Studio
    Aug 3, 2004
  2. kaushikshome
    Replies:
    4
    Views:
    806
    kaushikshome
    Sep 10, 2006
  3. Your Encryption Site
    Replies:
    11
    Views:
    728
    Kim André Akerø
    Apr 24, 2008
  4. Eduardo78
    Replies:
    0
    Views:
    272
    Eduardo78
    Nov 3, 2005
  5. Andrew Tomazos
    Replies:
    2
    Views:
    669
    Nobody
    Dec 12, 2011
Loading...

Share This Page