ActiveState Powered by ActiveState

ActiveState Community


Feature request - intelligent indenting

Posted by cheesegrits on 2008-04-21 15:20
OS: All / Any

How about adding a little more smarts to the code indenting, so it doesn't touch 'to here' blocks in perl or PHP? So for ...

print <<EOL;
   whatever
EOL

... or the PHP equivalent, it'll indent the print, but not the 'whatever', and most importantly, not the EOL ... 'cos of course then it's not EOL any more ...

"Separation of code and content". :)

-- hugh

ericp | Mon, 2008-04-21 18:02

Hi, Hugh

I would actually prefer this sort of indenting (leading "." indicate spaces):

sub f {
....if ($foo) {
........print <<<_EOL_
zero indent
...manually type three spaces
...komodo should continue with same indentation (3 spaces)
_EOL_   # You need to manually delete the white space
........# Komodo automatically bounces back to the indentation at start of here-doc
sub f {
....if ($foo) {
........print <<<_EOL_
zero indent
...manually type three spaces
...komodo should continue with same indentation (3 spaces)
_EOL_   # You need to manually delete the white space
........# Komodo automatically bounces back to the indentation at start of here-doc

To sum up, the only white space management you'd need to do
is the first line that starts with three spaces, and the closing
line where there's no white-space.

There's a longish discussion in the Perl cookbook about how to write code
to get around the limitations of auto-indenting that vi and emacs did at
the time, so your heredoc strings would be dedented in code. I prefer to
dedent the heredoc strings in the editor, so you see exactly the whitespace
you'll get. I guess this should be a pref.

This is probably easier to do in Perl and Ruby, where the editor knows about
here-document strings. The PHP colorizer currently only knows they're strings.

Can anyone point me to a reference of "flavored heredocs" in PHP -- this is where
the text in the heredoc tag is supposed to conventionally describe the language
of the heredoc's contents? Something like

echo <<

-->