Ben Schmidt wrote:
> Charles Campbell wrote:
>> David Fishburn wrote:
>>> I am writing an indent script for Flex which has similar HTML and 
>>> Javascript.
>>>
>>> So the indent script is pretty simple.
>>>
>>> If inside a <mx:Script> tag"
>>>           return cindent(a:lnum)
>>> else
>>>           " indent like XML
>>> endif
>>>
>>> In my other indent scripts I have never used cindent() before.
>>>
>>> In my sample app, I have:
>>> cinoptions=
>>>
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
>>>      <mx:Script>
>>>      <![CDATA[
>>>      private function update():void
>>> {
>>>
>>> So, cindent() returns 4 for "private function update():void".
>>> cindent() returns 0 for "{".
>>>
>>> Not sure really where to go from here.
>>> I read through cinoptions, but nothing jumps out at me.
>>>
>>> Any ideas why it wouldn't return 4, as in the previous line?
>>>
>> I believe cindent() is treating that "{" as the opening curly for a
>> function declaration;
>> and "One requirement is that toplevel functions have a '{' in the first
>> column."
>>
>> (from  :help C-indenting)
>
> Your particular situation is also going to be difficult because
> cindent() will look at context beyond the C code you want it to look at.
> It will essentially try to return the indent the line would have if the
> whole file were cindented.

Hm.  Is this true?  I would have thought that it would only look up at
the preceding line, and see what new things happened on that line...
ie, if a function began on the previous line, add the right amount of
whitespace for a function body to its indent, if a label: was there, add
the negative of the label unindent plus the indent-after-a-label value,
etc...

> That means that because, e.g. <![CDATA[
> doesn't have a semicolon at the end of it, the first line of your C code
> will be thought to be a continuation of a line so will be indented
> accordingly.

Either way, this is true.

> Solving this will be tough, and I'm not sure what approach
> would be best. Two possible solutions I can see are both very nasty: (1)
> writing the C indenting functionality in Vimscript yourself; or (2)
> copying the chunks of C code into another buffer, outdenting according
> to the current XML indent, running cindent on it, then returning the
> appropriate indent plus the current XML indent.

A third option (which would only work if my belief about cindent only
looking back one line is true) would be to see if the previous line
matches /<![CDATA[/ and if so set the indent for the current line to 0,
otherwise if you're not in a mx:Script tag return the XML indent, else
return the cindent.

But, I'm not positive that I'm correct in my belief, and don't have time
to test.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to