1
0
Fork 0

Refactors run code

This commit is contained in:
sloum 2022-05-29 03:23:39 +00:00
parent da0d272702
commit 7197aa5663
1 changed files with 27 additions and 19 deletions

View File

@ -23,27 +23,35 @@ if !exists("g:slope_command")
let g:slope_command = "slope"
endif
" Function to run the current slope file with the slope interpreter
" the interpreter can be overridden in .vim by setting g:slope_command
" to something else
function! RunSlopeFile()
silent !clear
execute "!" . g:slope_command . " " . bufname("%")
function! SaveAndRunSelection(startline,endline)
let lines = getline(a:startline, a:endline)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - 2]
let lines[0] = lines[0][column_start - 1:]
let tmpdir = tempname()
let tmpfile = tmpdir . "/prog.slo"
call mkdir(tmpdir)
call writefile(lines, tmpfile,"fa")
" the interpreter can be overridden in .vim by setting g:slope_command
" to something else
execute "!" . g:slope_command . " " . tmpfile
return
endfunction
function! RunVisualSelection()
let save_modified = g:modified
let g:modified = false
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - 2]
let lines[0] = lines[0][column_start - 1:]
silent !clear
execute "!" . g:slope_command . " -run \'" . join(lines, "") . "\'"
" Function to run the current slope file
function! RunSlopeFile()
let topline = line("w0")
let botline = line("w$")
call SaveAndRunSelection(topline,botline)
endfunction
" Function to run the current range/selection
function! RunVisualSelection() range
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
call SaveAndRunSelection(line_start, line_end)
endfunction
" map sk and sj to find the next or prev '(' across lines