Merge branch 'master' of https://git.rawtext.club/slope-lang/slope-vim-syntax
This commit is contained in:
commit
08706bd610
20
README.md
20
README.md
@ -4,7 +4,7 @@ Vim syntax highlighting for the [slope language](https://git.rawtext.club/slope-
|
||||
|
||||
## Syntax
|
||||
|
||||
The syntax is mostly what you'd expect and borrows a good bit from various scheme/lisp syntax files.
|
||||
The syntax is mostly what you'd expect and borrows a good bit from various scheme/lisp syntax files. It includes a simplified version of "rainbow parens" to try and help make sense of what can, admittedly, be a lot of parens. The rainbow effect is done in the syntax rather than as a plugin.
|
||||
|
||||
## Plugin
|
||||
|
||||
@ -12,16 +12,30 @@ The plugin adds a few niceties (defines comments, sets `lisp` for the buffer to
|
||||
|
||||
The plugin also adds a few functions/mappings:
|
||||
|
||||
- Typing `sr` while in _normal mode_ will attempt to run the current buffer with the slope interpreter
|
||||
- If `slope` is not on your path you can add: `let g:slope_command = '~/somewhere/slope'` (replacing the path with an actual path to a slope interpreter) to your `.vim` file
|
||||
- Typing `sr` while in _normal mode_ will attempt to run the current buffer with the slope interpreter, it will be based on the last save point in the buffer so remember to `:w`
|
||||
- If `slope` is not on your path you can add: `let g:slope_command = '~/somewhere/slope'` (replacing the path with an actual path to a slope interpreter) to your `.vimrc` file
|
||||
- Typing `sr` while in _visual mode_ will attempt to run the currently selected code
|
||||
- Typing `sj` while in normal or visual mode will move the cursor to the next opening parenthesis; `(`
|
||||
- Typing `sk` while in normal or visual mode will move the cursor to the previous opening parenthesis; `(`
|
||||
- Typing `sp` while in normal or visual mode will move the cursor to a matching parenthesis (if you are on a parenthesis)
|
||||
- This is just a remap of `%`, but makes it so you don't have to use the shift key (a presonal preference)
|
||||
|
||||
In the above mappings `s` is used as a leader key, which is the default set by the plugin. If you would like to override this you can add something like the following to your `.vimrc`:
|
||||
|
||||
``` vimscript
|
||||
" Map the slope leader to `L`
|
||||
" Then run the file by typing `Lr`
|
||||
" in normal mode, for example
|
||||
let g:slope_leader="L"
|
||||
```
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
make # from the root of the repo
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
Written by sloum with help from samhunter (thanks!)
|
||||
|
@ -13,18 +13,45 @@ setlocal expandtab
|
||||
|
||||
" Sets the local leader to 's' for use in
|
||||
" mappings within the plugin/buffer
|
||||
let maplocalleader="s"
|
||||
if !exists("g:slope_leader")
|
||||
let g:slope_leader="s"
|
||||
endif
|
||||
let maplocalleader=g:slope_leader
|
||||
|
||||
|
||||
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! 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 to run the current slope file
|
||||
function! RunSlopeFile()
|
||||
silent !clear
|
||||
execute "!" . g:slope_command . " " . bufname("%")
|
||||
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
|
||||
@ -37,6 +64,9 @@ vnoremap <buffer> <localleader>k :call search('\V(', 'b')<cr>
|
||||
" map sr to run the file
|
||||
nnoremap <buffer> <localleader>r :call RunSlopeFile()<cr>
|
||||
|
||||
" map sr to run the selection
|
||||
vnoremap <buffer> <localleader>r :call RunVisualSelection()<cr>
|
||||
|
||||
" map sp to switch to the opposite paren
|
||||
nnoremap <buffer> <localleader>p %
|
||||
vnoremap <buffer> <localleader>p %
|
||||
|
Loading…
Reference in New Issue
Block a user