indenting only when a character is at end of prior line?

indenting only when a character is at end of prior line?

601
Advanced UserAdvanced User
601

    Apr 01, 2006#1

    Hi all. Is there a way to set the auto-indent feature so that it only works when a certain character ends the previous line? Right now for my Python syntax file, I have the colon (':') as an indent character, which is fine like this:

    if x > 0:
    ....do_something

    But it also indents when I use a colon like this:

    section = source[start:stop]
    ....next line starts here, but shouldn't

    So is there a way to specify that indenting should only occur when the colon ends a line?

    Thanks,
    John

    1
    NewbieNewbie
    1

      Jul 22, 2006#2

      It is far from perfect but (it doesn't warn you about missing trailing column) but it avoid your problem:

      Code: Select all

      /Indent Strings = "class" "def" "elif" "else" "for" "if" "try" "except" "while"
      Vivian De Smedt

      236
      MasterMaster
      236

        Auto indent behaves differently from what the help file says

        Sep 15, 2006#3

        Hi all,

        I'm using V12.10b, and one problem that has been bugging me for a while now: ":" is the Indent String in Python. All lines that end in ":" are indented, which is the right behavior, since Python expects a new (indented) code block to follow after an if/for/try/etc. statement, and those statements end in a ":". Example:

        Code: Select all

        for line in file:
            items = line.split(";")
            for item in items:
                do_something()
        
        
        The problem is that UE causes all lines that follow a line that contains a colon anywhere to be indented, as in

        Code: Select all

        partial_list = items[2:4]
            # now UE indents falsely!
        
        
        In the help file (at least in the German version) it says "in order for an Indent string to be matched, it has to be the last non-whitespace character in the line." Which is what I would have expected. I can see a potential problem there, as it might be that a line comment follows after the Indent string, and that comment should not cause the indentation to fail, obviously. So I'd say that the correct way to handle auto indent would be: Indent the following line if the Indent String is the last non-whitespace, non-comment string of the current line.

        Or do some other programming languages have problems with that definition?

        Code: Select all

        int foo(int bar) { bar*=2;
            return bar;
        }
        
        
        would not work, but does anyone use this kind of formatting?

        Any ideas as to what would be the best way to handle this?

        Thanks,
        Tim

        344
        MasterMaster
        344

          Re: Auto indent behaves differently from what the help file

          Sep 15, 2006#4

          Lo Tim,

          hmmm, never made anything with indent string, but tried it out in vb script, UE 12.10a:
          wordfile:

          Code: Select all

          /Indent Strings = "then"
          /Unindent Strings = "End" "Next" "End If" "End Select"
          
          Result:

          Code: Select all

          lala Then lala
              here we go :-/
          
          Seems something wrong here, or we missed something ...

          Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          6,688586
          Grand MasterGrand Master
          6,688586

            Re: Auto indent behaves differently from what the help file says

            Sep 15, 2006#5

            pietzcker wrote:In the help file (at least in the German version) it says "in order for an Indent string to be matched, it has to be the last non-whitespace character in the line." Which is what I would have expected.
            Hi Tim!

            On help page Syntax Highlighting (Configuration - Editor Display), chapter Indentation I can read in the English help of UltraEdit:
            UE help wrote:If an indent string occurs anywhere on a line it will be used for indenting (except when it occurs in quoted/commented text).
            So it works as explained in the English help. Can you email IDM where exactly it is explained wrong in the German help.

            For a possible solution for Python see above the post from Vivian De Smedt.
            Best regards from an UC/UE/UES for Windows user from Austria

            236
            MasterMaster
            236

              Sep 25, 2006#6

              Mofi wrote:So it works as explained in the English help. Can you email IDM where exactly it is explained wrong in the German help.

              For a possible solution for Python see above the post from Vivian De Smedt.
              Ah, OK, so the help file is outdated. Vivian's example causes other problems, though. If one chooses to use a short notation

              Code: Select all

              if test==True: print "True"
              else: print "False"
              
              then it won't work...apart from not alerting the programmer to missing ":"s.

              Too bad...

              Tim

              13
              Basic UserBasic User
              13

                Nov 20, 2006#7

                Hi there - I posted this one the other day... wordlist issue? about the other side of this problem.

                If this is intended behaviour, its bad. There's nothing so irritating as self-correcting code that does it wrong.

                Given the other holes I've found with syntax highlights and wordwrap, though, its not too surprising. :(