Commit 92acd625 by HiPhish

Add a text preprocessor setting

Also did the following things:
  - The Python REPL comes with a preprocessor that strips blank lines
  - All settings except 'bin' are optional
  - Define REPL explicitly for Python 3
parent 541a7028
......@@ -100,15 +100,27 @@ endf
function! repl#spawn(mods, repl, type)
" Open a new buffer and launch the terminal
silent execute a:mods 'new'
silent execute 'terminal' a:repl.bin join(a:repl.args, ' ')
silent execute 'set syntax='.a:repl.syntax
silent let b:term_title = a:repl.title
let l:args = has_key(a:repl, 'args') ? a:repl.args : []
silent execute 'terminal' a:repl.bin join(l:args, ' ')
if has_key(a:repl, 'syntax')
let l:Syntax = a:repl.syntax
if type(l:Syntax) == type(function('type'))
let l:Syntax = l:Syntax()
endif
silent execute 'set syntax='.l:Syntax
endif
if has_key(a:repl, 'title')
silent let b:term_title = a:repl.title
endif
let b:repl = {
\ '-': {
\ 'type' : a:type,
\ 'bin' : a:repl.bin,
\ 'args' : a:repl.args,
\ 'args' : l:args,
\ 'job_id' : b:terminal_job_id,
\ 'buffer' : nvim_get_current_buf()
\ }
......
......@@ -141,8 +141,9 @@ as a dictionary like this:
>
call repl#define_repl('python', {'syntax': ''}, 'force')
<
Here we turn off syntax highlighting for Python REPL buffers. We `'force'`
this setting in order to override whatever the default setting might be.
Here we explicitly turn off syntax highlighting for Python REPL buffers. We
`'force'` this setting in order to override whatever the default setting might
be. All settings except for `'bin'` are optional.
It is also possible to specify local settings by using one of the scopes `t:`,
`w:` or `b:` as the scope for the `repl` dictionary, with later scopes taking
......@@ -158,30 +159,36 @@ g:repl['type']['bin'] *g:repl['type']['bin']*
Which binary to execute for the REPL. The default uses the system binary.
------------------------------------------------------------------------------
g:repl['type']['args'] *g:repl['type']['args']*
g:repl['type']['args'] = [] *g:repl['type']['args']*
Which arguments to pass to the executable, these arguments will be passed
before the user-supplied arguments.
------------------------------------------------------------------------------
g:repl['type']['syntax'] *g:repl['type']['syntax']*
g:repl['type']['syntax'] = '' *g:repl['type']['syntax']*
Which syntax highlighting to use for the REPL. Use the empty string if you
wish to disable syntax highlighting.
------------------------------------------------------------------------------
g:repl['type']['title'] *g:repl['type']['title']*
g:repl['type']['title'] = b:term_title *g:repl['type']['title']*
The value used for the terminal buffer's `b:term_title` variable.
------------------------------------------------------------------------------
g:repl['type']['spawn'] *g:repl['type']['spawn']*
g:repl['type']['preproc'] = {txt -> txt} *g:repl['type']['preproc']*
Optional, defaults to |repl#spawn()|; this function opens a new buffer and
sets up the REPL process. See |repl#spawn()| for details.
When sending text to the REPL it is preprocessed by this function first. The
default is to pass the text unmodified. A preprocessor could for example
remove blank lines if they are known to cause problems with the REPL.
This option is intended for REPLs which do something special, like not using
the terminal. For most REPLs the default is exactly what you want to use.
------------------------------------------------------------------------------
g:repl['type']['spawn'] = repl#spawn() *g:repl['type']['spawn']*
This function opens a new buffer and sets up the REPL process. For details see
|repl#spawn()|. This option is intended for REPLs which do something special,
like not using the terminal. For most REPLs the default is exactly what you
want to use.
......
......@@ -58,6 +58,10 @@ function! s:send_to_repl(type, ...) range
Repl
endif
if has_key(g:repl[&ft], 'preproc')
let l:text = g:repl[&ft]['preproc'](l:text)
endif
call jobsend(g:repl[&ft].instances[0].job_id, l:text)
Repl
startinsert
......
......@@ -30,10 +30,11 @@ endif
" ----------------------------------------------------------------------------
" The default settings
" ----------------------------------------------------------------------------
" bin : Which REPL binary to execute
" args : Arguments to pass to every execution, come before user arguments
" syntax : Syntax highlighting to use for the REPL buffer
" title : Value of b:term_title
" bin : Which REPL binary to execute
" args : Arguments to pass to every execution, come before user arguments
" syntax : Syntax highlighting to use for the REPL buffer
" title : Value of b:term_title
" preproc : Funcref to a text preprocessor before sending it to the REPL
" ----------------------------------------------------------------------------
let s:repl = {
\ 'guile': {
......@@ -45,14 +46,13 @@ let s:repl = {
\ 'lua': {
\ 'bin': 'lua',
\ 'args': [],
\ 'syntax': '',
\ 'title': 'Lua',
\ },
\ 'python': {
\ 'bin': 'python',
\ 'args': [],
\ 'syntax': '',
\ 'title': 'Python REPL',
\ 'preproc': {txt -> join(filter(split(txt, '\n'), {idx, val -> !empty(val)}), "\n")}
\ },
\ 'r7rs-small': {
\ 'bin': 'chibi-scheme',
......@@ -69,12 +69,14 @@ let s:repl = {
\ 'sh': {
\ 'bin': 'sh',
\ 'args': [],
\ 'syntax': '',
\ 'title': 'Bourne Shell',
\ },
\ }
" ----------------------------------------------------------------------------
let s:repl['python3'] = copy(s:repl['python'])
let s:repl['python3']['bin'] = 'python3'
let s:repl['r7rs'] = copy(s:repl['r7rs-small'])
let s:repl['scheme'] = copy(s:repl['r7rs-small'])
" ----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment