[TriLUG] formatting (tabbing) perl scripts

Jon Carnes jonc at nc.rr.com
Sat Apr 24 16:14:06 EDT 2004


On Sat, 2004-04-24 at 15:35, Ed Hill wrote:
> On Sat, 2004-04-24 at 12:57, Douglas Kojetin wrote:
> > hi all-
> > 
> > i've got a perl script with quite a bit of code.  i had to add a few 
> > more 'if/else' statements, and instead of manually tabbing everything 
> > over (puts ease on my eyes), i was wondering if there was a program 
> > and/or script that anyone knows of that might automagically do this for 
> > me (scan through the code and tab it according to its structure)?  i've 
> > seen programs that format HTML quite efficiently (html tidy, i think it 
> > was called), but i haven't really looked for anything else.
> 
> 
> Hi Douglas,
> 
> In Emacs, selecting a region followed by the command:
> 
>   ESC-x indent-region
> 
> will do what you want.  And recent versions of Emacs have a nifty
> point-and-click menu (Options --> Customize Emacs) that you can use to
> customize the indentation system to suit your style.
> 
> Ed

Vi:

There are in fact four methods available for indentation:
'autoindent'    uses the indent from the previous line.
'smartindent'   is like 'autoindent' but also recognizes some C syntax
                to increase/reduce the indent where appropriate.
'cindent'       Works more cleverly than the other two and is
                configurable to different indenting styles.
'indentexpr'    The most flexible of all: Evaluates an expression to
                compute the indent of a line.  When non-empty this
                method overrides the other ones.

The rest of this section describes the 'cindent' option.

Note that 'cindent' indenting does not work for every code scenario. 
Vim is not a C compiler: it does not recognize all syntax.
                                                                                These four options control C program indenting:
'cindent'       Enables Vim to perform C program indenting
                automatically.
'cinkeys'       Specifies which keys trigger reindenting in insert mode.
'cinoptions'    Sets your preferred indent style.
'cinwords'      Defines keywords that start an extra indent in the next
                line.

...yada, yada, yada

Anyway, Vim recognizes the formating for Python, and does a darn a good
job!

Jon




More information about the TriLUG mailing list