Commit a3b80865 by HiPhish

Allow function references in settings

parent 5b82fa1e
......@@ -94,6 +94,14 @@ in the rest.
" Add Python syntax highlighting
let g:repl['python'] = {'syntax': 'python'}
You can also use function references of lambdas as option values if the
function reference does not take any arguments.
.. code-block:: vim
" Add Python syntax highlighting
let g:repl['python'] = {'syntax': {-> 'python'}}
After Nvim has loaded you can the dictionary entries. If you wanted to turn
syntax highlighting back off after starting up Nvim you would execute
......@@ -143,16 +151,12 @@ bound to the same interface. You cannot use Vim's commands to edit text, you
instead have to enter terminal mode (insert mode for the terminal) to modify
text.
Syntax highlighting uses Vim's Scheme highlighting, but this might not always
be adequate. Highlighting the prompt or the backtrace as if it was regular
Scheme code is wrong.
License
#######
REPL.nvim is release under the terms of the MIT license. See the `LICENSE.txt`_
REPL.nvim is release under the terms of the MIT license. See the `COPYING.txt`_
file for details.
.. _LICENSE.txt: LICENSE.txt
.. _COPYING.txt: COPYING.txt
......@@ -2,7 +2,7 @@
Things that need to be done
#############################
:date: 2017-04-03
:date: 2017-04-08
.. default-role:: code
......@@ -55,12 +55,6 @@ Use a regular buffer
be a superior choice.
De-hardcode settings
Settings must be hard-coded by the user; for instance, this means the user
has to specify a particular string for the binary. It would be preferable if
the user could specify a function reference that returns the string instead.
Have functions in addition to the command
The `:Repl` command is a good interface for users, but other plugins could
make use of `repl#...()`-style functions. A file type plugin could then use
......
......@@ -111,17 +111,23 @@ CONFIGURATION *repl.nvim-configuration*
All settings are contained inside the `g:repl['type']` dictionary, where
'type' is the type of the REPL. The key is the name of the setting and its
value is the value. You can set individual entries according to your wishes;
if you wanted to disable syntax highlighting in the REPL you would add the
following to your `init.vim`:
value is the value or a function reference. You can set individual entries
according to your wishes; if you wanted to disable syntax highlighting in the
REPL you would add the following to your `init.vim`:
>
let g:repl['python'] = {'syntax': ''}
<
You do not have to add the default settings to your dictionary, this plugin is
smart enough to not lose the defaults.
Note After Nvim has loaded up do not re-assign the `g:guile_repl` variable, set
its individual entries instead.
Settings are allowed to be a function reference (or a lambda) to a function
which takes no arguments. This allows you to dynamically generate settings
instead of deciding ahead of time.
>
let g:repl['python'] = {'syntax': {-> ''}}
<
Note After Nvim has loaded up do not re-assign the `g:repl` variable, set its
individual entries instead.
It is also possible to specify local setting by using one of the scopes `t:`, `w:`
or `b:`, with later ones taking precedence. The following is a listing of the
......
......@@ -95,32 +95,36 @@ function! s:repl(mods, bang, ...)
" loop over the lower scopes in a given order. If we encounter the same
" setting it overwrites the previous values. The scopes are ordered by
" ascending significance, with the most significant being last.
for l:key in keys(g:repl[l:type])
silent execute 'let l:'.l:key.' = g:repl[l:type]["'.key.'"]'
let l:repl = copy(g:repl[l:type])
for l:key in keys(l:repl)
for l:scope in ['t', 'w', 'b']
let l:entry = l:scope.':repl["'.l:type.'"]["'.l:key.'"]'
if exists(l:entry)
silent execute 'let l:'.l:key.' = '.l:entry
silent execute 'let l:repl["'.l:key.'"] = '.l:entry
endif
endfor
" If the option is a function reference call it
if type(l:repl[l:key]) == type(function('type'))
let l:repl[l:key] = l:repl[l:key]()
endif
endfor
" Append the argument to the command to the argument list (but skip the
" first argument, that is the file type)
let l:args = l:args + a:000[1:]
let l:repl.args = l:repl.args + a:000[1:]
" Open a new buffer and launch the terminal
silent execute a:mods 'new'
silent execute 'terminal' l:binary join(l:args, ' ')
silent execute 'set syntax='.l:syntax
silent let b:term_title = l:title
silent execute 'terminal' l:repl.binary join(l:repl.args, ' ')
silent execute 'set syntax='.l:repl.syntax
silent let b:term_title = l:repl.title
" Collect information about this REPL instance
let b:repl = {
\ '-': {
\ 'type' : l:type,
\ 'binary' : l:binary,
\ 'args' : l:args,
\ 'binary' : l:repl.binary,
\ 'args' : l:repl.args,
\ 'job_id' : b:terminal_job_id,
\ 'buffer' : bufnr('%')
\ }
......
......@@ -39,6 +39,18 @@ Then (Arugments are appended to defaults):
#-----------------------------------------------------------------------------
Execute (Function reference settings):
function! FooSyntax()
return 'foo_syntax'
endfunction
let g:repl[g:ft].syntax = function('FooSyntax')
silent Repl
Then (Function reference gets evaluated):
AssertEqual 'foo_syntax', &syntax
#-----------------------------------------------------------------------------
Execute (Tab-local settings override global ones):
let t:repl = {g:ft : {'title': 'Alternative title'}}
silent Repl
......
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