Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to get prefix with quotes in completion widgets?



Sven Wischnowsky wrote:
> the whole `(...)' is reported to the completion code (from the lexer
> invoked by it) as one string, with quotes inside it, not at the
> beginning, so the completion code doesn't handle them specially.
> 
> So, to answer your question: in *this* case, with the probably not
> intended interpretation of the command line which can't be changed in
> the completion code, there is no way to find the quotes other than by
> looking e.g. at $BUFFER and $CURSOR of $words[CURRENT] (the former two
> are zle-parameters accessible read-only in the completion code).

I am finding that BUFFER/LBUFFER etc also have the quotes removed which
puzzled me. Does this mean these behave differently in a completion
widget to a ZLE one? Else how can the basic editing functions work?
If so, why do they behave differently?

The words array is the only thing that seems to come through intact.

eg:

BUFFER:example insert ( foo, bar ):
LBUFFER:example insert ( foo, b:
words:example insert ( 'foo', 'bar' ):

> But if the stuff you want to complete really looks different from what
> you sent, there might be a way. And anyway I'd like to know in which
> real-world case you need it, we might have other ideas to help you.

Well what I am completing is SQL. For years I've had a system which lets
me enter SQL directly at the command line to run it in whatever database
(currently Sybase & Oracle). Thus I can use the full power of Zsh
editing & history etc for SQL. It's always done basic completion of
tables & columns using a simple decoding of the statement to select the
right columns, even using compctl.

I re-wrote it when the new completion system came out & improved it then
to handle table aliases & joins etc, and currently it works fine for 90%
of stuff. However, I'm in the process of re-writing it to properly LL(k)
parse the SQL statement so that it produces the correct results all the
time. I've half written the parser and it handles most of the usual stuff
now but I'm having problems with the SQL syntax which includes quotes,
and particularly that which includes brackets.

The things I'm particularly interested in are insert statements,
sub-selects, etc. because they don't currently work.
eg.
  sql insert into TABLE ( column_1, column_2 ) values ( 'value1', 2 )

  sql select column_1 from TABLE_1 where column_2 in ( select values_1
      from TABLE_2 where values_2 in ( 1, 3, 5 ) )

The words array seems to have exactly what I want (just the command being
completed without other stuff on the command line, supplied otherwise
untouched), however although CURRENT tells me which word the cursor is
in, I can't get the character position reliably when () and quotes are
present.

Whole () expressions appear as one word in the words array, which doesn't
bother me because I join it together before parsing it, but does make the
cursor location even more important.

On a related note it has occurred to me I may get problems when offering
completions inside brackets, but I've not got to that yet. I'm hoping to
be able to get around it using PREFIX and SUFFIX or one of their
relatives.

Cheers,

Martin.


This message is for the named person's use only. It may contain sensitive and private proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. CREDIT SUISSE GROUP and each legal entity in the CREDIT SUISSE FIRST BOSTON or CREDIT SUISSE ASSET MANAGEMENT business units of CREDIT SUISSE FIRST BOSTON reserve the right to monitor all e-mail communications through its networks. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be the views of any such entity.
Unless otherwise stated, any pricing information given in this message is indicative only, is subject to change and does not constitute an offer to deal at any price quoted. Any reference to the terms of executed transactions should be treated as  preliminary only and subject to our formal written confirmation.




Messages sorted by: Reverse Date, Date, Thread, Author