~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to misc/vim/ftplugin/go/import.vim

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
"       in the current Go buffer, using proper style and ordering.
13
13
"       If {path} is already being imported, an error will be
14
14
"       displayed and the buffer will be untouched.
15
 
 
15
"
16
16
"   :ImportAs {localname} {path}
17
17
"
18
18
"       Same as Import, but uses a custom local name for the package.
32
32
" The backslash is the default maplocalleader, so it is possible that
33
33
" your vim is set to use a different character (:help maplocalleader).
34
34
"
35
 
if exists("b:did_ftplugin")
 
35
if exists("b:did_ftplugin_go_import")
36
36
    finish
37
37
endif
38
38
 
58
58
        return
59
59
    endif
60
60
 
 
61
    " Extract any site prefix (e.g. github.com/).
 
62
    " If other imports with the same prefix are grouped separately,
 
63
    " we will add this new import with them.
 
64
    " Only up to and including the first slash is used.
 
65
    let siteprefix = matchstr(path, "^[^/]*/")
 
66
 
61
67
    let qpath = '"' . path . '"'
62
68
    if a:localname != ''
63
69
        let qlocalpath = a:localname . ' ' . qpath
83
89
            let appendstr = qlocalpath
84
90
            let indentstr = 1
85
91
            let appendline = line
 
92
            let firstblank = -1
 
93
            let lastprefix = ""
86
94
            while line <= line("$")
87
95
                let line = line + 1
88
96
                let linestr = getline(line)
89
97
                let m = matchlist(getline(line), '^\()\|\(\s\+\)\(\S*\s*\)"\(.\+\)"\)')
90
98
                if empty(m)
 
99
                    if siteprefix == "" && a:enabled
 
100
                        " must be in the first group
 
101
                        break
 
102
                    endif
 
103
                    " record this position, but keep looking
 
104
                    if firstblank < 0
 
105
                        let firstblank = line
 
106
                    endif
91
107
                    continue
92
108
                endif
93
109
                if m[1] == ')'
 
110
                    " if there's no match, add it to the first group
 
111
                    if appendline < 0 && firstblank >= 0
 
112
                        let appendline = firstblank
 
113
                    endif
94
114
                    break
95
115
                endif
 
116
                let lastprefix = matchstr(m[4], "^[^/]*/")
96
117
                if a:localname != '' && m[3] != ''
97
118
                    let qlocalpath = printf('%-' . (len(m[3])-1) . 's %s', a:localname, qpath)
98
119
                endif
103
124
                    let deleteline = line
104
125
                    break
105
126
                elseif m[4] < path
106
 
                    let appendline = line
 
127
                    " don't set candidate position if we have a site prefix,
 
128
                    " we've passed a blank line, and this doesn't share the same
 
129
                    " site prefix.
 
130
                    if siteprefix == "" || firstblank < 0 || match(m[4], "^" . siteprefix) >= 0
 
131
                        let appendline = line
 
132
                    endif
 
133
                elseif siteprefix != "" && match(m[4], "^" . siteprefix) >= 0
 
134
                    " first entry of site group
 
135
                    let appendline = line - 1
 
136
                    break
107
137
                endif
108
138
            endwhile
109
139
            break
198
228
    echohl Error | echo a:s | echohl None
199
229
endfunction
200
230
 
 
231
let b:did_ftplugin_go_import = 1
 
232
 
201
233
" vim:ts=4:sw=4:et