Re: [code] [textadept] Adaptsense and symbol autocompletion

From: Richard Philips <richard.philips.att.gmail.com>
Date: Mon, 14 Oct 2013 09:46:08 +0200

>
>> - would it be useful ?
>
> It could be if and only if the signature was inserted as a snippet so
> the user could tab through the arguments. Having to navigate and
> manually replace args would be awful.
>

Never thought about that! I think I could accomplish that.

>> - any pointers on how to approach this ?
>
> I would probably connect to the `events.AUTO_C_SELECTION` event. The
> following my untested idea:
>
> events.connect(events.AUTO_C_SELECTION, function(text, position)
> local lexer = buffer:get_lexer()
> if not _M[lexer] or not _M[lexer].sense then return end
> -- Insert autocompleted text.
> buffer:add_text(text:sub(buffer.current_pos - position, -1))
> -- Get the full, autocompleted symbol.
> local symbol, part = _M[lexer].sense:get_symbol()
> local full_symbol = symbol..'.'..part -- or '->', etc.
> -- Get its API documentation, signature, and arg list.
> local docs = _M[lexer].sense:get_apidoc(full_symbol)
> if not docs then return end
> local doc = docs[docs.pos] -- get the correct API doc
> doc = doc:match('%b()') -- extract arg list
> -- Compose and insert snippet with those args.
> local n = 0
> textadept.snippets._insert(doc:gsub('[^,]+', function(arg)
> n = n + 1
> return '%'..n..'('..arg..')'
> end))
> buffer:auto_c_cancel() -- do not let Textadept insert `text`
> end)
>
> This example does not handle the proper placeholders for optional
> arguments, but that exercise is left to the reader.
>
> Cheers,
> Mitchell

Good starting point! (Almost done :-)

I will look into it.

Richard

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 14 Oct 2013 - 03:46:08 EDT

This archive was generated by hypermail 2.2.0 : Mon 14 Oct 2013 - 06:38:19 EDT