-
-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
This commit gives lua more power over the completions. Lua code can now decide when, what, and how to complete. It is now possible to complete email addresses using an external command and to complete file paths with a space in it.
@@ -213,7 +240,7 @@ int l_CScreen_sleep(lua_State * l) | |||
|
|||
|
|||
/** | |||
* Implementation of Screen:sleep(). | |||
* Implementation of Screen:stuff(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch :)
I think it's a great idea, but I'd need to read the commits carefully before accepting. Thanks again for a great idea, that looks sane at first glance. It might be the weekend before I have free time to review, but so far it looks great :) |
a4294be
to
250297f
Compare
Merged - with a couple of new issues filed.
Also suddenly realized that I cannot complete " |
You can use the file completion in the lua context like this: do
local _complete_lua = complete_lua
complete_lua = function(buffer)
local token, ret = _complete_lua(buffer)
local _, comps = complete_path(token)
for _, comp in ipairs(comps) do
table.insert(ret, comp)
end
return token, ret
end
end |
The more I use this new code the less I'm happy with it. I think it is obvious that your intention was a good one, and I can see the value in the context-based approach. I just keep finding things that are odd. Like I want to complete an email address in my Lua function names - from my local address-book - and that is now failing because the completion of "emails" is distinct from the completion of "lua". (i.e. I want to complete "
Similarly typing " I'm torn between reverting it, and the previous commits, or trying to overhaul a third time :( |
We could merge the completions, such that they'd attempt all possible contexts, but thats the only straightforward solution I see. i.e. "complete_path" could complete "/blah" - but would ignore anything not starting with "/" Then we'd choose from the union. It seems like there should be no collisions, and this would allow "general" completion. Of course in some situations (adding attachments), or forward/compose we could use the more specific approaches. |
All contexts are distinct by default. You can extend your lua context with all the other contexts if you like. Just add them to the returned table of complete_lua with the token complete_lua returns. |
I agree that it is possible, but what I'm trying to say is that by default we should be completing against all contexts - to give us back the kind of completion we had previously. (As well as the new abilities which you've added.) |
We could also add other completions to complete_lua by default. The Problem with the union approach I see is that we have to use different token for different contexts. And the seperated building blocks are easier to extend than a union function. We have to situations with "broader" completions: lua and shell For shell I didn't write completions because I didn't know the seperators to split on. |
Yeah the problem is that lua-arguments can be "anything", which certainly includes (quoted) email-addresses, and paths. I've filed a bug to update/change the handling as #334 and we can discuss/experiment there. |
I was annoyed because I couldn't complete file paths with spaces in them.
After reading the code I realized that I can't fix this because the c++ code makes assumption where to
complete.
So I came up with a more generic fix. Completions are now context aware.
To achieve this the function 'on_complete' now behaves like a filter for the line buffer used in
CSreen:get_line
. It calls the active context specific functions, which are calledcomplete_context
, collects their results, builds and returns the buffer.This change comes with three contexts:
What do you think ? It is really complicated but it's the best I came up with.