Commit 80f23122 authored by HiPhish's avatar HiPhish

Improve support for dotted file type

parent a3b80865
......@@ -104,9 +104,23 @@ REPL, except if the argument is `'-'`. If the first argument is `'-'` or there
are no arguments we have to guess the type based on the current file type.
We support the dotted file type syntax: first try all the dot-separated atomic
types from left to right. Later types override previous ones. Finally try the
whole file type. This means that if our file type is `scheme.guile` the types
tried are `scheme`, `guile` and `scheme.guile`, in that order.
types from left to right. Later types override previous ones. Then keep trying
progressively more compound file types until the whole file type. This means
that if our file type is `scheme.guile` the types tried are `scheme`, `guile`
and `scheme.guile`, in that order.
The algorithm is as follows:
- Given a list `FTs` with length `l`
- For `i` in the range from `0` (inclusive) to `l` (exclusive)
- For `j` in the range from `0` (inclusive) to `l - i` (inclusive)
- The file type is `l[j: j + i]` (join items vial `.`)
This algorithm sorts file types by length and gives later types priority over
earlier ones.
If no type could be found an error is displayed and the function returns with
no value and no side effects.
......
......@@ -11,22 +11,6 @@ When adding to or removing anything from this file please adjust the date at
the top.
Improve support for dotted file type
Currently if the file type is `'a.b.c.d'` the plugin will loop over the list
`['a', 'b', 'c', 'd']` and finally try `'a.b.c.d'`. What it needs to do is
loop over all possible combinations of the list elements while preserving
order. In this example the combinations would be
#) `'a'`
#) `'a.b'`
#) `'a.b.c'`
#) `'a.b.c.d'`
#) `'b'`
#) `'b.c'`
#) `'b.c.d'`
#) `'c.d'`
#) `'d'`
Interface for new REPLs
Defining a new REPL is already possible, but due to loading order users
cannot change settings for it like they can for the built-in ones. What we
......@@ -44,10 +28,6 @@ Interface for new REPLs
call repl#define_repl('ruby', ruby)
Document everything
That's self-evident.
Use a regular buffer
At the moment we are using a terminal buffer, but this is subpar because the
user cannot use regular Vim commands. A regular buffer that sends commands
......
......@@ -66,8 +66,14 @@ split with arguments you would run
To terminate a REPL either delete the buffer or terminate the REPL the same
way you would if it was a standalone process.
REPL.nvim supports detection of dotted file types like `scheme.guile`. The
individual types are tried from left to right with later matches overriding
earlier ones. Following the individual types, larger compound types are tried
as well from left to right and increasing it size. Example: if the file type
is `a.b.c` the types tried are `a`, `b`, `c`, `a.b`, `b.c` and `a.b.c`.
------------------------------------------------------------------------------
:Repl! [{ytpe} [{arg} ...]] *:Repl!*
:Repl! [{type} [{arg} ...]] *:Repl!*
If there is already one or more instances running the command will move the
cursor to the REPL window. To explicitly spawn a new instance use `:Repl!`.
......
......@@ -54,14 +54,20 @@ function! s:repl(mods, bang, ...)
return
endif
else
for l:ft in split(&filetype, '\v\.')
if exists('g:repl["'.l:ft.'"]')
let l:type = l:ft
endif
" First split the file type at the dots, then loop over the list
let l:fts = split(&filetype, '\v\.')
" Start with single types and gradually move to longer types, i.e.
" 'a', 'b', 'c', 'a.b', 'b.c', 'a.b.c'
for l:i in range(0, len(l:fts) - 1)
for l:j in range(0, len(l:fts) - l:i -1)
let l:ft = join(l:fts[l:j : l:j + l:i], '.')
if exists('g:repl["'.l:ft.'"]')
let l:type = l:ft
endif
endfor
endfor
if exists('g:repl["'.&filetype.'"]')
let l:type = l:ft
endif
if empty(l:type)
echohl ErrorMsg
echom 'No REPL for current file type defined'
......
......@@ -30,6 +30,39 @@ Then (A terminal buffer with settings set):
quit
#-----------------------------------------------------------------------------
Execute (Dotted file type, single type):
set ft=a.b.c
" Remove false positives just in case they exist
if exists('g:repl["a"]')
remove(g:repl, 'a')
endif
if exists('g:repl["b"]')
remove(g:repl, 'b')
endif
let g:repl['c'] = {'binary': '', 'args': [], 'syntax': '', 'title': ''}
silent Repl
Then (Type 'c' is recognised):
AssertEqual b:repl['-'].type, 'c'
quit
#-----------------------------------------------------------------------------
Execute (Dotted file type, compound type):
set ft=a.b.c
" Remove false positives just in case they exist
if exists('g:repl["a.b"]')
remove(g:repl, 'a.b')
endif
let g:repl['b.c'] = {'binary': '', 'args': [], 'syntax': '', 'title': ''}
silent Repl
Then (Type 'b.c' is recognised):
AssertEqual b:repl['-'].type, 'b.c'
quit
#-----------------------------------------------------------------------------
Execute (User-supplied arguments):
silent Repl - foo bar
......
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