Skip to content

Commit 74beb35

Browse files
committed
executioner.vim 1.2.0
Defaults can be individually overridden instead of forcing the user to define the whole dictionary. Defaults can be disabled from loading with g:executioner#load_defaults
1 parent 0fa97d4 commit 74beb35

File tree

2 files changed

+115
-57
lines changed

2 files changed

+115
-57
lines changed

README.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ git clone https://github.com/EvanQuan/vim-executioner.git ~/.vim/pack/plugin/sta
2929

3030
#### [Vim-Plug](https://github.com/junegunn/vim-plug)
3131

32-
1. Add `Plug 'EvanQuan/vim-executioner'` to your vimrc file.
33-
2. Reload your vimrc or restart.
32+
1. Add `Plug 'EvanQuan/vim-executioner'` to your `vimrc` file.
33+
2. Reload your `vimrc` or restart.
3434
3. Run `:PlugInstall`
3535

3636
#### [Vundle](https://github.com/VundleVim/Vundle.vim)
3737

38-
1. Add `Plugin 'EvanQuan/vim-executioner'` to your vimrc file.
39-
2. Reload your vimrc or restart.
38+
1. Add `Plugin 'EvanQuan/vim-executioner'` to your `vimrc` file.
39+
2. Reload your `vimrc` or restart.
4040
3. Run `:BundleInstall`
4141

4242
#### [NeoBundle](https://github.com/Shougo/neobundle.vim)
4343

44-
1. Add `NeoBundle 'EvanQuan/vim-executioner'` to your vimrc file.
45-
2. Reload your vimrc or restart.
44+
1. Add `NeoBundle 'EvanQuan/vim-executioner'` to your `vimrc` file.
45+
2. Reload your `vimrc` or restart.
4646
3. Run `:NeoUpdate`
4747

4848
#### [Pathogen](https://github.com/tpope/vim-pathogen)
@@ -92,7 +92,7 @@ reason, it will not work for programs that require user input.
9292
#### Key mappings
9393

9494
By default, Executioner does not provide any key mappings as to not override
95-
mappings defined in your `.vimrc`. You can map these commands to however you
95+
mappings defined in your `vimrc`. You can map these commands to however you
9696
like to make them easier to use.
9797

9898
For example, I personally use:
@@ -128,7 +128,7 @@ what file I'm currently editing.
128128
You may want to refer to the full file name or base name in in your commands.
129129
The full file name, which is the base name with file extension, can be referred
130130
to by `g:executioner#full_name`, while the base name can be referred to by
131-
`g:executioner#base_name`, both which you can set in your `.vimrc`. By default
131+
`g:executioner#base_name`, both which you can set in your `vimrc`. By default
132132
they are defined as:
133133

134134
```vim
@@ -145,10 +145,36 @@ and then execute it.
145145

146146
There are 2 dictionaries that define what types of files can be executed:
147147

148-
With `g:executioner#extensions`, Executioner can execute a command based on the
149-
extension of a file name. With `g:executioner#names`, Executioner can execute
150-
a command based on a file name. If not defined in your `.vimrc`, they are by
151-
default defined as:
148+
`g:executioner#extensions` determines commands by file extension. For example,
149+
if you want to execute files with the `.foo` extension, such as
150+
`hello_world.foo`, with the `bar` command, (i.e. executing `bar
151+
hello_world.foo` in the terminal), then include:
152+
```vim
153+
let g:executioner#extensions['foo'] = 'bar %'
154+
```
155+
in your `vimrc`.
156+
157+
`g:executioner#names` determines commands by file name. For example, if you want
158+
to execute files with the name `echo_me.txt` with the command `echo
159+
echo_me.txt`, then include:
160+
```vim
161+
let g:executioner#names['echo_me.txt'] = 'echo echo_me.txt'
162+
```
163+
in your `vimrc`.
164+
165+
Executioner will prioritize names over extensions when determining what command
166+
to use. For example, if
167+
```vim
168+
let g:executioner#extension['py'] = 'python3 %'
169+
```
170+
dictates that `.py` files are to be executed with `python3` and
171+
```vim
172+
let g:executioner#names['foo.py'] = 'python2 foo.py'
173+
```
174+
dictates that `foo.py` is to be executed with `python2`, then `foo.py` will be
175+
executed with `python2`.
176+
177+
These are the default commands:
152178

153179
```vim
154180
" extension : command
@@ -180,19 +206,11 @@ let g:executioner#names = {
180206
\}
181207
```
182208

183-
`g:executioner#extensions` determines commands by file extension. For example,
184-
if you want to execute files with the `.foo` extension, such as
185-
`hello_world.foo`, with the `bar` command, (i.e. executing `bar
186-
hello_world.foo` in the terminal), then the value `'foo' : 'bar %'` must be
187-
included in this dictionary.
188-
189-
`g:executioner#names` determines commands by file name. For example, if you want
190-
to execute files with the name `delete_me.txt` with the command `rm
191-
delete_me.txt`, then the value `'delete_me.txt' : 'rm delete_me.txt'` must be
192-
included in this dictionary.
209+
As expected, if any of these extensions or file names are defined in your
210+
`vimrc`, they will take precedence over the defaults.
193211

194-
Executioner will prioritize names over extensions when determining what command
195-
to use. For example: if `g:executioner#extensions` dictates that `py` files are
196-
to be executed with `python3` and `g:executioner#names` dictates that `foo.py`
197-
is to be executed with `python2`, then `foo.py` will be executed with
198-
`python2`.
212+
If you wish to disable these defaults entirely, include:
213+
```vim
214+
let g:executioner#load_defaults = 0
215+
```
216+
in your `vimrc` and they will not be defined.

plugin/executioner.vim

Lines changed: 70 additions & 30 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.1.2
4+
" Version: 1.2.0
55
"
66
" A Vim plugin to easily execute files in the terminal or a separate buffer.
77
" ============================================================================
@@ -20,6 +20,10 @@ if !exists("g:executioner#base_name")
2020
let g:executioner#base_name = '@'
2121
endif
2222

23+
if !exists("g:executioner#load_defaults")
24+
let g:executioner#load_defaults = 1
25+
endif
26+
2327
" Fake enums
2428

2529
" Parsed input
@@ -37,36 +41,72 @@ let s:HORIZONTAL = 3
3741
let s:EXTENSION_COMMAND = 0
3842
let s:NAME_COMMAND = 1
3943

40-
" extension : command
41-
" Command is executed if file has specified extension
42-
if !exists("g:executioner#extensions")
43-
let g:executioner#extensions = {
44-
\ 'c' : 'gcc % -o @.out;./@.out',
45-
\ 'cpp' : 'g++ % -o @.out;./@.out',
46-
\ 'hs' : 'ghci %',
47-
\ 'js' : 'node %',
48-
\ 'm' : 'matlab',
49-
\ 'ml' : 'ocaml % -o @.out;./@.out',
50-
\ 'php' : 'php %',
51-
\ 'pl' : 'perl %',
52-
\ 'prolog' : 'swipl %',
53-
\ 'py' : 'python %',
54-
\ 'py2' : 'python2 %',
55-
\ 'R' : 'Rscript %',
56-
\ 'r' : 'Rscript %',
57-
\ 'rb' : 'ruby %',
58-
\ 'rc' : 'rustc % -o @.out;./@.out',
59-
\ 'sh' : 'bash %',
60-
\ 'swift' : 'swiftc % -o @.out;./@.out',
61-
\}
62-
endif
44+
if g:executioner#load_defaults
45+
" extension : command
46+
" Command is executed if file has specified extension
47+
if !exists("g:executioner#extensions")
48+
let g:executioner#extensions = {}
49+
endif
50+
if !has_key(g:executioner#extensions, 'c')
51+
let g:executioner#extensions['c'] = 'gcc % -o @.out;./@.out'
52+
endif
53+
if !has_key(g:executioner#extensions, 'cpp')
54+
let g:executioner#extensions['cpp'] = 'g++ % -o @.out;./@.out'
55+
endif
56+
if !has_key(g:executioner#extensions, 'hs')
57+
let g:executioner#extensions['hs'] = 'ghci %'
58+
endif
59+
if !has_key(g:executioner#extensions, 'js')
60+
let g:executioner#extensions['js'] = 'node %'
61+
endif
62+
if !has_key(g:executioner#extensions, 'm')
63+
let g:executioner#extensions['m'] = 'matlab'
64+
endif
65+
if !has_key(g:executioner#extensions, 'ml')
66+
let g:executioner#extensions['ml'] = 'ocaml % -o @.out;./@.out'
67+
endif
68+
if !has_key(g:executioner#extensions, 'php')
69+
let g:executioner#extensions['php'] = 'php %'
70+
endif
71+
if !has_key(g:executioner#extensions, 'pl')
72+
let g:executioner#extensions['pl'] = 'perl %'
73+
endif
74+
if !has_key(g:executioner#extensions, 'prolog')
75+
let g:executioner#extensions['prolog'] = 'swipl %'
76+
endif
77+
if !has_key(g:executioner#extensions, 'py')
78+
let g:executioner#extensions['py'] = 'python3 %'
79+
endif
80+
if !has_key(g:executioner#extensions, 'py2')
81+
let g:executioner#extensions['py2'] = 'python2 %'
82+
endif
83+
if !has_key(g:executioner#extensions, 'R')
84+
let g:executioner#extensions['R'] = 'Rscript %'
85+
endif
86+
if !has_key(g:executioner#extensions, 'r')
87+
let g:executioner#extensions['r'] = 'Rscript %'
88+
endif
89+
if !has_key(g:executioner#extensions, 'rb')
90+
let g:executioner#extensions['rb'] = 'ruby %'
91+
endif
92+
if !has_key(g:executioner#extensions, 'rc')
93+
let g:executioner#extensions['rc'] = 'rustc % -o @.out;./@.out'
94+
endif
95+
if !has_key(g:executioner#extensions, 'sh')
96+
let g:executioner#extensions['sh'] = 'bash %'
97+
endif
98+
if !has_key(g:executioner#extensions, 'swift')
99+
let g:executioner#extensions['swift'] = 'swiftc % -o @.out;./@.out'
100+
endif
63101

64-
" file name : command
65-
" Command is executed if file has specified name
66-
if !exists("g:executioner#names")
67-
let g:executioner#names = {
68-
\ 'makefile': 'make',
69-
\}
102+
" file name : command
103+
" Command is executed if file has specified name
104+
if !exists("g:executioner#names")
105+
let g:executioner#names = {}
106+
endif
107+
if !has_key(g:executioner#names, 'makefile')
108+
let g:executioner#names['makefile'] = 'make'
109+
endif
70110
endif
71111

72112
function! s:SplitNameAndExtenstion(file) abort

0 commit comments

Comments
 (0)