File: commandt.vim

package info (click to toggle)
vim-command-t 5.0.2-5-g7147ba9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 744 kB
  • sloc: ruby: 3,394; ansic: 1,177; makefile: 27; sh: 26; xml: 11
file content (222 lines) | stat: -rw-r--r-- 5,252 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
" Copyright 2010-present Greg Hurrell. All rights reserved.
" Licensed under the terms of the BSD 2-clause license.

if exists('g:command_t_autoloaded') || &cp
  finish
endif
let g:command_t_autoloaded = 1

"
" Functions
"

function! s:RubyWarning() abort
  echohl WarningMsg
  echo 'command-t.vim requires Vim to be compiled with Ruby support'
  echo 'For more information type:  :help command-t'
  echohl none
endfunction

function! commandt#BufferFinder() abort
  if has('ruby')
    ruby $command_t.show_buffer_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#CommandFinder() abort
  if has('ruby')
    ruby $command_t.show_command_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#FileFinder(arg) abort
  if has('ruby')
    ruby $command_t.show_file_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#JumpFinder() abort
  if has('ruby')
    ruby $command_t.show_jump_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#MRUFinder() abort
  if has('ruby')
    ruby $command_t.show_mru_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#HelpFinder() abort
  if has('ruby')
    ruby $command_t.show_help_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#HistoryFinder() abort
  if has('ruby')
    ruby $command_t.show_history_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#LineFinder() abort
  if has('ruby')
    let g:CommandTCurrentBuffer=bufnr('%')
    ruby $command_t.show_line_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#SearchFinder() abort
  if has('ruby')
    ruby $command_t.show_search_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#TagFinder() abort
  if has('ruby')
    ruby $command_t.show_tag_finder
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#Flush() abort
  if has('ruby')
    ruby $command_t.flush
  else
    call s:RubyWarning()
  endif
endfunction

function! commandt#Load() abort
  if !has('ruby')
    call s:RubyWarning()
  endif
endfunction

" For possible use in status lines.
function! commandt#ActiveFinder() abort
  if has('ruby')
    ruby ::VIM::command "return '#{$command_t.active_finder}'"
  else
    return ''
  endif
endfunction

" For possible use in status lines.
function! commandt#Path() abort
  if has('ruby')
    ruby ::VIM::command "return '#{($command_t.path || '').gsub(/'/, "''")}'"
  else
    return ''
  endif
endfunction

" For possible use in status lines.
function! commandt#CheckBuffer(buffer_number) abort
  if has('ruby')
    execute 'ruby $command_t.return_is_own_buffer' a:buffer_number
  else
    return 0
  endif
endfunction

" visible == exists, loaded, listed and not hidden
" (buffer is opened in a window - in current or another tab)
function! s:BufVisible(buffer)
  " buffer is opened in current tab (quick check for current tab)
  if bufwinnr('^' . a:buffer . '$') != -1 | return 1 | end
  " buffer exists if it has been opened at least once (unless wiped)
  if !bufexists(a:buffer) | return 0 | end
  " buffer is not loaded when its last window is closed (`set nohidden` only)
  if !bufloaded(a:buffer) | return 0 | end
  " buffer is not listed when it's deleted
  if !buflisted(a:buffer) | return 0 | end

  let bufno = bufnr(a:buffer)
  let ls_buffers = ''

  redir => ls_buffers
  silent ls
  redir END

  " buffer is hidden when its last window is closed (`set hidden` only)
  for line in split(ls_buffers, "\n")
    let components = split(line)
    if components[0] == bufno
      return match(components[1], 'h') == -1
    endif
  endfor

  return 1
endfunction

function! commandt#GotoOrOpen(command_and_args) abort
  let l:command_and_args = split(a:command_and_args, '\v^\w+ \zs')
  let l:command = l:command_and_args[0]
  let l:file = l:command_and_args[1]

  " `bufwinnr()` doesn't see windows in other tabs, meaning we open them again
  " instead of switching to the other tab; but `bufname()` sees hidden
  " buffers, and if we try to open one of those, we get an unwanted split.
  if s:BufVisible(l:file)
    execute 'sbuffer ' . l:file
  else
    execute l:command . l:file
  endif
endfunction

if !has('ruby')
  finish
endif

" note that we only start tracking buffers from first (autoloaded) use of Command-T
augroup CommandTMRUBuffer
  autocmd!
  autocmd BufEnter * ruby CommandT::MRU.touch
  autocmd BufDelete * ruby CommandT::MRU.delete
augroup END

ruby << EOF
  # require Ruby files
  begin
    require 'command-t'
    require 'command-t/ext' # eager load, to catch compilation problems early
    $command_t = CommandT::Controller.new
  rescue LoadError
    load_path_modified = false
    ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
      ext = "#{path}/ruby/command-t/ext"
      if !$LOAD_PATH.include?(ext) && File.exist?(ext)
        $LOAD_PATH << ext
        load_path_modified = true
      end
      lib = "#{path}/ruby/command-t/lib"
      if !$LOAD_PATH.include?(lib) && File.exist?(lib)
        $LOAD_PATH << lib
        load_path_modified = true
      end
    end
    retry if load_path_modified

    $command_t = CommandT::Stub.new
  end
EOF