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

Syntax highlighting, code folding, brace matching, code indenting, and function list

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

Postby JohnJSal » Fri Mar 31, 2006 11:12 pm

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
User avatar
JohnJSal
Advanced User
Advanced User
 
Posts: 60
Joined: Sat Mar 05, 2005 12:00 am

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

Postby vds2212 » Sat Jul 22, 2006 7:29 am

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
User avatar
vds2212
Newbie
 
Posts: 1
Joined: Fri Jul 21, 2006 11:00 pm

Auto indent behaves differently from what the help file says

Postby pietzcker » Fri Sep 15, 2006 7:10 am

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
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Auto indent behaves differently from what the help file

Postby Bego » Fri Sep 15, 2006 7:39 am

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 sth. wrong here, or we missed something ...

Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

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

Postby Mofi » Fri Sep 15, 2006 10:37 am

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!

At Syntax Highlighting (Configuration - Editor Display), chapter Indentation I can read in the english help of UltraEdit:

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 in the german help it is explained wrong.

For a possible solution for Python see above the post from Vivian De Smedt.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

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

Postby pietzcker » Mon Sep 25, 2006 11:42 am

So it works as explained in the english help. Can you email IDM where exactly in the german help it is explained wrong.

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
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

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

Postby s_m_b » Mon Nov 20, 2006 10:19 am

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

If this is intended behavour, 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. :(
User avatar
s_m_b
Basic User
Basic User
 
Posts: 13
Joined: Thu Sep 01, 2005 11:00 pm


Return to Syntax Highlighting