discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

For VIM users [Fwd: Re: [New Script] indent/objc.vim]


From: Kazunobu Kuriyama
Subject: For VIM users [Fwd: Re: [New Script] indent/objc.vim]
Date: Wed, 24 Dec 2003 13:17:19 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

Hi,

Though I'm not sure how many people there use VIM editor for creating
their ObjC programs, I'd like to offer this tiny script for the
community, because I found it useful for me.

The script does automatic indentation for message sending statements
and function headers/declarations, aligning colons, just like Michael
Weber's objc-c-mode.el does.

If you have an interest in it, put the scpipt in
$(VIMRUNTIME)/indent/ or ~/.vim/indent/.  Make sure filetype is set
to objc to source the script.

I think the script will be included in the VIM source shortly
(see below).

Because this is not a gnustep genuine topic, please send comment
or suggestion to me *privately*, if any.  I appreciate it.



-------- Original Message --------
Subject:        Re: [New Script] indent/objc.vim
Date:   Sun, 21 Dec 2003 17:15:26 +0100
From:   Bram Moolenaar <Bram@moolenaar.net>
To:     Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>



Kazunobu -

So, I'm sending a new script which modifies the previous one slightly.
I hope the behavior of the new one is more user-friendly.  Accordingly,
please do away with yesterday's script and adopt the new one.

I'll include the new version, thanks!

- Bram

--
From "know your smileys":
;-0     Can't find shift key
,-9     Kann Umschalttaste nicht finden

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
\\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///


"   Vim indent file
"   Language:       Objective-C
"   Maintainer:     Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>
"   Last Change:    2003 Dec 21
"   
 

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
    finish
endif
let b:did_indent = 1
setlocal cindent

" Set the function to do the work.
setlocal indentexpr=GetObjCIndent()

" To make a colon (:) suggest an indentation other than a goto/swich label,
setlocal indentkeys-=:
setlocal indentkeys+=<:>

" Only define the function once.
if exists("*GetObjCIndent")
    finish
endif

function s:GetWidth(line, regexp)
    let end = matchend(a:line, a:regexp)
    let width = 0
    let i = 0
    while i < end
        if a:line[i] != "\t"
            let width = width + 1
        else
            let width = width + &ts - (width % &ts)
        endif
        let i = i + 1
    endwhile
    return width
endfunction

function s:LeadingWhiteSpace(line)
    let end = strlen(a:line)
    let width = 0
    let i = 0
    while i < end
        let char = a:line[i]
        if char != " " && char != "\t"
            break
        endif
        if char != "\t"
            let width = width + 1
        else
            let width = width + &ts - (width % &ts)
        endif
        let i = i + 1
    endwhile
    return width
endfunction


function GetObjCIndent()
    let theIndent = cindent(v:lnum)

    let prev_line = getline(v:lnum - 1)
    let cur_line = getline(v:lnum)

    if prev_line !~# ":" || cur_line !~# ":"
        return theIndent
    endif

    if prev_line !~# ";"
        let prev_colon_pos = s:GetWidth(prev_line, ":")
        let delta = s:GetWidth(cur_line, ":") - s:LeadingWhiteSpace(cur_line)
        let theIndent = prev_colon_pos - delta
    endif

    return theIndent
endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]