On Thu, Sep 15, 2011 at 4:18 PM, Gary Johnson <[email protected]> wrote:
> On 2011-09-15, Donald Allen wrote:
>> If you have following in a vim buffer, file named, say, foo.awk
>>
>> /some test/ {
>> if (foo != "bar") {
>> if (baz != ""){
>> array1[xyz] = N
>> if (N > max_N) max_N = N
>> }
>> xyz = temp[1]
>> # Create
>> print "," > "something.sql"
>> split(description,temp,parse_descriptions[file])
>> print "\t-- "temp[1] > "something.sql"
>> printf "\t%s %s", xyz, pg_type > "something.sql"
>> # Load
>> insert = insert",\n\t"xyz
>> fields[M]=xyz
>> M++
>> N = 1
>> }
>> field_to_XX_field[xyz,N] = field
>> N++
>> }
>>
>> position the cursor on the '{' that ends the first line. Then do =%. You get
>>
>> /some test/ {
>>       if (foo != "bar") {
>>               if (baz != ""){
>>                       array1[xyz] = N
>>                       if (N > max_N) max_N = N
>>               }
>>               xyz = temp[1]
>>               # Create
>>               print "," > "something.sql"
>>               split(description,temp,parse_descriptions[file])
>>               print "\t-- "temp[1] > "something.sql"
>>               printf "\t%s %s", xyz, pg_type > "something.sql"
>>               # Load
>>               insert = insert",\n\t"xyz
>>               fields[M]=xyz
>>               M++
>>                N = 1
>>       }
>>       field_to_XX_field[xyz,N] = field
>>       N++
>>        }
>>
>>
>> The line 'N = 1' is indented by an extra space, incorrectly, and the
>> closing '}' is also incorrectly indented. Don't focus on the code
>> itself or its correctness. I modified it to make it simpler for the
>> purpose of this example and also for privacy. The point is that it is
>> syntactically correct awk and the behavior I'm showing you here is
>> identical to the indentation I get with the unmodified, semantically
>> correct code.
>>
>> This is one of a number of problems I've had with indentation. Looking
>> on the web for the usual discussions of emacs vs. vim, it's not hard
>> to find the observation that one of emacs' advantages is more accurate
>> indentation (emacs indents this code snippet correctly).
>> Unfortunately, my own experience is confirming this. I prefer vim in a
>> lot of ways, but when programming, indentation is a critical tool and,
>> for me, if I can't trust the editor to do it correctly, it's not of
>> much use to me. In the work I'm currently doing, I've been forced to
>> use emacs in viper mode because of this issue.
>>
>> I'm not trying to start an editor religious war here. I'm simply
>> making an observation about something that I think is an important
>> area where vim seems somewhat weak. vim and awk have been around for a
>> long time. it ought to be able to indent awk code correctly and I
>> would suggest that fixing indentation problems should take priority
>> over adding new features.
>>
>> (By the way, you get the above behavior with no ~/.vimrc and all
>> options set to their defaults. The behavior remains the same when you
>> turn on autoindent or cindent. This is with a vim built from source
>> up-to-date via git as of last night. Version is 7.3.315 running on a
>> Slackware 13.37 64-bit system.)
>
> Vim's indentation of most languages (except C) is done by plugins.
> These reside in $VIMRUNTIME/indent and are contributed and
> maintained by a number of different authors.  In the case of awk,
> the indentation plugin is $VIMRUNTIME/indent/awk.vim.  At the top of
> that file is the author's name, e-mail address, and an invitation to
> contact him with bug reports.  He would be the person to contact
> first with a bug report.
>
> I have cc'd him on this reply.
>
> I took a look at the plugin and think I found the problem and a
> solution.  The plugin tries to identify continuing lines and indents
> the subsequent line an additional amount.  It tries to identify
> continuing lines by looking for certain patterns such unfinished
> arithmetic statements including lines ending with '+'.
> Unfortunately, its pattern for '+' at the end of the line also
> matches '++', so it thinks that "N = 1" and the last '}' are
> continuation lines.
>
> This patch seems to fix that problem for the particular cases of the
> ++ and -- operators.
>
> --------------------------------------------------------------------
> *** awk.vim.orig     2011-05-16 14:55:32.553959000 -0700
> --- awk.vim      2011-09-15 12:48:40.004332000 -0700
> ***************
> *** 188,193 ****
> --- 188,195 ----
>
>  function! s:Seems_continuing( line )
>    " Unfinished lines
> +   if a:line =~ '\(--\|++\)\s*$'
> +     return 0
>    if a:line =~ '[\\,\|\&\+\-\*\%\^]\s*$'
>      return 1
>    endif
> --------------------------------------------------------------------
>
> If you apply that patch, make sure to do so to a copy of awk.vim in
> your ~/.vim/indent directory rather than to the original in
> $VIMRUNTIME/indent.

Yes, your patch fixes the issue I reported. Thanks very much.

/Don

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui