Skip to content

Commit 659e26c

Browse files
committed
executioner 1.3.1
Check if g:executioner#full_name and g:executioner#base_name are not equal to 1 to set them to default values Defaults use defined g:executioner#full_name and g:executioner#base_name values
1 parent eb9f868 commit 659e26c

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

doc/executioner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*executioner.txt* For Vim version 8.1 Last change: 2019 January 01
1+
*executioner.txt* For Vim version 8.1 Last change: 2019 January 02
22

33
_____ _ _ ~
44
| ___| | | (_) ~

plugin/executioner.vim

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" ============================================================================
22
" File: executioner.vim
33
" Maintainer: https://github.com/EvanQuan/vim-executioner/
4-
" Version: 1.3.0
4+
" Version: 1.3.1
55
"
66
" A Vim plugin to easily execute files in the terminal or a separate buffer.
77
" You can learn more about it with:
@@ -15,11 +15,11 @@ if exists("g:executioner#loaded")
1515
endif
1616

1717
" Name and extension
18-
if !exists("g:executioner#full_name")
18+
if !exists("g:executioner#full_name") || len(g:executioner#full_name) != 1
1919
let g:executioner#full_name = '%'
2020
endif
2121
" Just name
22-
if !exists("g:executioner#base_name")
22+
if !exists("g:executioner#base_name") || len(g:executioner#base_name) != 1
2323
let g:executioner#base_name = '@'
2424
endif
2525

@@ -60,58 +60,58 @@ endif
6060

6161
if g:executioner#load_defaults
6262
if !has_key(g:executioner#extensions, 'c')
63-
let g:executioner#extensions['c'] = 'gcc % -o @.out;./@.out'
63+
let g:executioner#extensions['c'] = 'gcc ' . g:executioner#full_name . ' -o ' . g:executioner#base_name . '.out;./' . g:executioner#base_name . '.out'
6464
endif
6565
if !has_key(g:executioner#extensions, 'cpp')
66-
let g:executioner#extensions['cpp'] = 'g++ % -o @.out;./@.out'
66+
let g:executioner#extensions['cpp'] = 'g++ ' . g:executioner#full_name . ' -o ' . g:executioner#base_name . '.out;./' . g:executioner#base_name . '.out'
6767
endif
6868
if !has_key(g:executioner#extensions, 'hs')
69-
let g:executioner#extensions['hs'] = 'ghci %'
69+
let g:executioner#extensions['hs'] = 'ghci ' . g:executioner#full_name . ''
7070
endif
7171
if !has_key(g:executioner#extensions, 'java')
72-
let g:executioner#extensions['java'] = 'javac %;java @'
72+
let g:executioner#extensions['java'] = 'javac ' . g:executioner#full_name . ';java ' . g:executioner#base_name . ''
7373
endif
7474
if !has_key(g:executioner#extensions, 'js')
75-
let g:executioner#extensions['js'] = 'node %'
75+
let g:executioner#extensions['js'] = 'node ' . g:executioner#full_name . ''
7676
endif
7777
if !has_key(g:executioner#extensions, 'm')
7878
let g:executioner#extensions['m'] = 'matlab'
7979
endif
8080
if !has_key(g:executioner#extensions, 'ml')
81-
let g:executioner#extensions['ml'] = 'ocaml % -o @.out;./@.out'
81+
let g:executioner#extensions['ml'] = 'ocaml ' . g:executioner#full_name . ' -o ' . g:executioner#base_name . '.out;./' . g:executioner#base_name . '.out'
8282
endif
8383
if !has_key(g:executioner#extensions, 'php')
84-
let g:executioner#extensions['php'] = 'php %'
84+
let g:executioner#extensions['php'] = 'php ' . g:executioner#full_name . ''
8585
endif
8686
if !has_key(g:executioner#extensions, 'pl')
87-
let g:executioner#extensions['pl'] = 'perl %'
87+
let g:executioner#extensions['pl'] = 'perl ' . g:executioner#full_name . ''
8888
endif
8989
if !has_key(g:executioner#extensions, 'prolog')
90-
let g:executioner#extensions['prolog'] = 'swipl %'
90+
let g:executioner#extensions['prolog'] = 'swipl ' . g:executioner#full_name . ''
9191
endif
9292
if !has_key(g:executioner#extensions, 'py')
93-
let g:executioner#extensions['py'] = 'python3 %'
93+
let g:executioner#extensions['py'] = 'python3 ' . g:executioner#full_name . ''
9494
endif
9595
if !has_key(g:executioner#extensions, 'py2')
96-
let g:executioner#extensions['py2'] = 'python2 %'
96+
let g:executioner#extensions['py2'] = 'python2 ' . g:executioner#full_name . ''
9797
endif
9898
if !has_key(g:executioner#extensions, 'R')
99-
let g:executioner#extensions['R'] = 'Rscript %'
99+
let g:executioner#extensions['R'] = 'Rscript ' . g:executioner#full_name . ''
100100
endif
101101
if !has_key(g:executioner#extensions, 'r')
102-
let g:executioner#extensions['r'] = 'Rscript %'
102+
let g:executioner#extensions['r'] = 'Rscript ' . g:executioner#full_name . ''
103103
endif
104104
if !has_key(g:executioner#extensions, 'rb')
105-
let g:executioner#extensions['rb'] = 'ruby %'
105+
let g:executioner#extensions['rb'] = 'ruby ' . g:executioner#full_name . ''
106106
endif
107107
if !has_key(g:executioner#extensions, 'rc')
108-
let g:executioner#extensions['rc'] = 'rustc % -o @.out;./@.out'
108+
let g:executioner#extensions['rc'] = 'rustc ' . g:executioner#full_name . ' -o ' . g:executioner#base_name . '.out;./' . g:executioner#base_name . '.out'
109109
endif
110110
if !has_key(g:executioner#extensions, 'sh')
111-
let g:executioner#extensions['sh'] = 'bash %'
111+
let g:executioner#extensions['sh'] = 'bash ' . g:executioner#full_name . ''
112112
endif
113113
if !has_key(g:executioner#extensions, 'swift')
114-
let g:executioner#extensions['swift'] = 'swiftc % -o @.out;./@.out'
114+
let g:executioner#extensions['swift'] = 'swiftc ' . g:executioner#full_name . ' -o ' . g:executioner#base_name . '.out;./' . g:executioner#base_name . '.out'
115115
endif
116116

117117
if !has_key(g:executioner#names, 'makefile')
@@ -335,6 +335,22 @@ function! s:ParseArgs(has_teriminal, split_type, file_with_args)
335335
let s:file_with_args = a:file_with_args != "" ? a:file_with_args : expand("%")
336336
endfunction
337337

338+
function! s:CommandIsInvalid(execute_command, file_name)
339+
if a:execute_command == s:INVALID_COMMAND
340+
execute "echo \"'" . a:file_name . "' is not configured to be executable.\""
341+
return 1
342+
endif
343+
return 0
344+
endfunction
345+
346+
function! s:SaveFileIfExists()
347+
" Evaluate saving current buffer
348+
" Don't save and reload current file not in file
349+
if &filetype != ""
350+
silent execute "update | edit"
351+
endif
352+
endfunction
353+
338354
function! s:SaveAndExecuteFile(...) abort
339355
" Since the user is not directly calling this, all arguments are guarenteed
340356
" Parameters:
@@ -351,23 +367,14 @@ function! s:SaveAndExecuteFile(...) abort
351367

352368
call s:ParseArgs(a:1, a:2, a:3)
353369

354-
" If not split, then output is terminal
355-
" Otherwise, the output replaces the current buffer contents
356370
let parsed_input = s:ParseInput(s:file_with_args)
357371
let execute_command = s:GetExecuteCommand(parsed_input)
358372

359-
" If invalid execute_command then return early with error message
360-
if execute_command == s:INVALID_COMMAND
361-
execute "echo \"'" . parsed_input[s:NAME]
362-
\ . "' is not configured to be executable.\""
363-
return -1
373+
if s:CommandIsInvalid(execute_command, parsed_input[s:NAME])
374+
return s:INVALID_COMMAND
364375
endif
365376

366-
" Evaluate saving current buffer
367-
" Don't save and reload current file not in file
368-
if &filetype != ""
369-
silent execute "update | edit"
370-
endif
377+
call s:SaveFileIfExists()
371378

372379
" Finally execute command
373380
call s:ExecuteCommand(s:split_type, execute_command, parsed_input[s:FILE])

0 commit comments

Comments
 (0)