1
1
" ============================================================================
2
2
" File: executioner.vim
3
3
" Maintainer: https://github.com/EvanQuan/vim-executioner/
4
- " Version: 1.2.1
4
+ " Version: 1.2.2
5
5
"
6
6
" A Vim plugin to easily execute files in the terminal or a separate buffer.
7
7
" ============================================================================
8
8
9
9
if exists (" g:executioner#loaded" )
10
10
finish
11
11
endif
12
- let g: executioner #loaded = 1
13
12
14
13
" Name and extension
15
14
if ! exists (" g:executioner#full_name" )
@@ -31,6 +30,7 @@ let s:FILE = 0
31
30
let s: NAME = 1
32
31
let s: EXTENSION = 2
33
32
let s: ARGS = 3
33
+ let s: PATHLESS_NAME = 4
34
34
35
35
" Split types
36
36
let s: NONE = 0
@@ -41,6 +41,8 @@ let s:HORIZONTAL = 3
41
41
let s: EXTENSION_COMMAND = 0
42
42
let s: NAME_COMMAND = 1
43
43
44
+ let s: DIRECTORY_SEPARATOR = ' [/\\]'
45
+
44
46
" extension : command
45
47
" Command is executed if file has specified extension
46
48
if ! exists (" g:executioner#extensions" )
@@ -143,12 +145,15 @@ endfunction
143
145
144
146
function ! s: GetExecuteCommand (parsed_input) abort
145
147
" Parameters:
146
- " list parsed_input [string file, string name, string extension, string args]
148
+ " list parsed_input [string file, string name, string extension,
149
+ " string args]
147
150
" Returns:
148
151
" string the execute command of the parsed_input if executable
149
152
" "" if not executable
150
- if has_key (g: executioner #names, a: parsed_input [s: FILE ])
151
- let s: command = g: executioner #names[a: parsed_input [s: FILE ]]
153
+ if ! filereadable (expand (s: parsed_input [s: FILE ]))
154
+ let s: command = " "
155
+ elseif has_key (g: executioner #names, a: parsed_input [s: PATHLESS_NAME ])
156
+ let s: command = g: executioner #names[a: parsed_input [s: PATHLESS_NAME ]]
152
157
\ . a: parsed_input [s: ARGS ]
153
158
elseif has_key (g: executioner #extensions, a: parsed_input [s: EXTENSION ])
154
159
let s: command = g: executioner #extensions[a: parsed_input [s: EXTENSION ]]
@@ -190,7 +195,8 @@ function! s:ParseInput(file_with_args) abort
190
195
" Parameters:
191
196
" string file_with_args - file name, optionally followed by arguments
192
197
" Returns:
193
- " list [string file, string name, string extension, string arguments]
198
+ " list [string file, string name, string extension, string arguments,
199
+ " string pathless_name]
194
200
195
201
" If no arguments supplied, then there is nothing to parse
196
202
if len (a: file_with_args ) == 0
@@ -209,12 +215,17 @@ function! s:ParseInput(file_with_args) abort
209
215
" Split the file into its name and extension.
210
216
let s: file = s: SplitNameAndExtenstion (s: file_with_extension )
211
217
218
+ " Remove path from name
219
+ let s: directories = split (s: file [0 ], s: DIRECTORY_SEPARATOR )
220
+ let s: pathless_name = s: directories [len (s: directories ) - 1 ]
221
+
212
222
" Remaining terms are arguments
213
223
" Join all arguments back together with spaces
214
224
let s: arguments = len (s: input_terms ) > 1 ?
215
225
\ " " . join (s: input_terms [1 :], " " ) : " "
216
226
217
- return [s: file_with_extension , s: file [0 ], s: file [1 ], s: arguments ]
227
+ return [s: file_with_extension , s: file [0 ], s: file [1 ], s: arguments ,
228
+ \ s: pathless_name ]
218
229
endfunction
219
230
220
231
function ! s: GetSplitPrefix (split_type) abort
@@ -395,8 +406,27 @@ endfunction
395
406
" endfunction
396
407
397
408
" nnoremap <leader>d :call g:Debug(2, "test.cpp")<CR>
409
+ "
410
+ function ! g: Test ()
411
+ let s: string1 = ' foo/bar/file1.extension'
412
+ let s: string2 = ' foo\bar\file2.extension'
413
+
414
+ let s: split1 = split (s: string1 , s: DIRECTORY_SEPARATOR )
415
+ let s: split2 = split (s: string2 , s: DIRECTORY_SEPARATOR )
416
+
417
+ let s: name1 = s: split1 [len (s: split1 ) - 1 ]
418
+ let s: name2 = s: split2 [len (s: split2 ) - 1 ]
419
+
420
+ echom s: name1
421
+ echom s: name2
422
+ endfunction
423
+
424
+ nnoremap <leader> d :call g:Test()<CR>
425
+
398
426
399
427
" Create commands
400
428
command ! -nargs =* Executioner :call s: SaveAndExecuteFile (s: NONE , <q-args> )
401
429
command ! -nargs =* ExecutionerVertical :call s: SaveAndExecuteFile (s: VERTICAL , <q-args> )
402
430
command ! -nargs =* ExecutionerHorizontal :call s: SaveAndExecuteFile (s: HORIZONTAL , <q-args> )
431
+
432
+ let g: executioner #loaded = 1
0 commit comments