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

From: Mitchell <m.att.foicica.com>
Date: Sun, 13 Oct 2013 20:09:47 -0400 (EDT)

Hi Richard,

On Sun, 13 Oct 2013, Richard Philips wrote:

> Hi,
>
> I'm looking into the adaptsense capability of textadept.
>
> I have the impression that the symbol autocompletion is restricted to the
> name of the function (method, class, ..).
> I would like to see that autocompletion generates also the signature.
>
> An example: (Python)
>
> autocompletion of:
>
> x = string.tr
>
> gives
>
> x = string.translate
>
>
> Good. But often more useful would be:
>
> x = string.translate(/s/, /table/[, /deletechars/])
>
>
> Now, before I try to handle this problem, a few questions:
>
> - did I overlook an obvious solution ?

No, Adeptsense does not support this.

> - 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.

> - 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

-- 
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 Sun 13 Oct 2013 - 20:09:47 EDT

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