Indentation preferences

  • rphodges

    rphodges - 2007-07-30

    The layout of the Perl Editor Preferences pane confuses me.

    My current settings are:

    Displayed Tab Width: 8
    Insert tabs/spaces on indent: 4
    Use spaces instead of tabs: unchecked

    From a user interface perspective it is not really clear to me what "Insert tabs/spaces ..." really means and how
    it might be impacted by the "Use spaces instead of tabs" checkbox.  The wording of the above settings implies that 4 tabs would be inserted for every indent.   It also implies that if "Uses spaces instead of tabs" is checked, then 4 spaces would be inserted for every indent.

    However, it appears that when "Use spaces instead of tabs" is unchecked, the value of the "Insert tabs/spaces ..." box is ignored; instead one tab is always used for the indent.

    I would rename the "Insert tabs/spaces" box to "Indent width: " and change the behavior such that
    1. If tabs are enabled each indent is composed of the necessary tabs and spaces to occupy indent width.
    2. If spaces are used instead of tabs, then the indent width is occupied by solely spaces.

    This is equivalent to the tabstop, shiftwidth, and [no]expandtab, settings in Vim.

    Most would argue that it is bad style for the a mixture of spaces and tabs be used to occupy the indent width but
    a lot of legacy code is written in this style and it would be easier for an editor to conform.

    Also when the Displayed Tab Width value is changed, the change does not  immediately take effect in open files.  The files have to be close and reopened for the setting to take affect.


    • Jan Ploski

      Jan Ploski - 2007-08-05

      I agree with you that the tab-related settings are confusing. However, I doubt if Vim is a good model to follow. The settings in Vim are confusing as well (I'm a long-time Vim user myself).

      I think that the following would be sufficient:
      1. An integer preference concerning tab stops. Tab stops are imaginary vertical lines that divide the editor into equal-width strips, for example, every 8 characters (we assume a fixed-width font). The value preference might be called the "tab width".
      2. One radio-box preference for the TAB key behavior (insert spaces or insert '\t's). This governs what happens when you press TAB - either a '\t' or an appropriate number of spaces (based on the current caret position and the tab stop preference) is inserted.

      Regardless of the second preference, pressing the TAB key always moves the caret to the next tab stop.
      '\t' characters, if present, are always interpreted as "move to the next tab stop".

      There is another function which is affected by these preferences - the indent/outdent function. Adding an extra level of indentation is simple: either a single '\t' as or tab width spaces are inserted in front of the line. Removing indentation from a line would remove the leading '\t', or the leading spaces, or a mix consisting of some spaces followed by a '\t'. If there is not enough whitespace to remove (i.e. the line's text starts somewhere before the first tab stop), then all leading whitespace would be removed by the "outdent" operation (just like in Vim).

      I suspect that the above would be too simple for some users, but I don't have a good idea why. Can you provide some real-life examples?

      • Johan Vromans

        Johan Vromans - 2007-08-10

        Many (VERY MANY) sourcefiles currently are like

          sub foo {
          <4 spaces>if ( blah ) {
          <1 tab>while ( 1 ) {
          <1 tab><4 spaces>print ...;
          <1 tab>}
          <4 spaces>}

        To handle these, the following preferences would be necessary:

          Tab width:      [  8 ]
          Indent width:   [  4 ]
          Tab key does:   [ Indent / Tab / Indent in left margin, Tab elsewhere ]
          Indent with:    [ Spaces / Tabs+Spaces ]

        Shift left/ shift right should adjust the selection by the "Indent width" and rework the indentation according to the "Indent with" preference.

    • rphodges

      rphodges - 2007-08-08

      What you are proposing assumes that "tab width" and "indent width" are always equivalent.   However, I work on
      code where the coding convention is:

      1.  All tabs should be treated as 8 characters.
      2.  All indents should be indented by 4 characters.
      3.  The indent of a line should be composed as many tabs as possible.
            This means that a line that is indented by 4 should be indented by 4 spaces.
            However, a line that is indented by 8 characters should be indented by one tab
            character. A line indented by 12 characters should be indented by one tab
            character and 4 spaces and so on.

      When I work on these files I have to set the "tab width" to 8 characters.  If I don't
      existing text will not line up correctly.  This means that when I want an indent width
      of 4 characters, I can't do that by setting "tab width" to 4, because all of the existing
      tabs will cause a mis-alignment of text.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks