From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13809 invoked by alias); 16 Jan 2016 22:54:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37652 Received: (qmail 22099 invoked from network); 16 Jan 2016 22:54:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=GzvLQEBKvga9pT0X0oE/QAA+7qgKwd4cYRSmLIolAIo=; b=L7pgGG/zMr5h0APoiBafrwRUBlFjjhbAtOjjUK8FW/SwiNXbMffIqnOzFbDWrp8Z5N SLFfR8FsvqfqC9g6llyL6RDBNhOsQCFjI4sGqveQLyfH7ozVCmSIvwukK9w/hye168b5 kxXdxNvmx6BUvTnd/ewXGhXai5HZiZXW7Jc1crrthLVdGOEUMMAQ9ZVrSjL6QymKdvwA cucu4p9lAXdR0vge/b2J/5o9Q+wbr6yH6rjwoEJlFUAcJV5hPzTwGN4XrNrPKWHG/E/3 MCzm2MkC7Lhx6/Bp/5W+k7KZzVhS/dlTWLxN/7XD+s/EKVmVixJtIwbbCAcVPxD2oexi 5iPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=GzvLQEBKvga9pT0X0oE/QAA+7qgKwd4cYRSmLIolAIo=; b=AnTrkMKnu1/Ut5aUBnb3rXQxuKm/ql0tmc5HeBJQiv8dw1zX84n1Q/EGv8Xep4w2zJ woPFw9x9eZ3AL01TURJCdDt6sGgYCiof1cePNE2TrvRO+93QWfbH5sRu3vc22VmQjvNn BBx35Wlji1mNw3me399C9MfCkjqgycG95XskS3VASANNE7t1Rxvolb9SljImjCSlAykg 5M1PSeXdTyh4ZRXKoDoxinaET40Nvw+X9sM+0DVPz/2NKM2Y0Gj9/aijYSJ7pGYdY9Mk Gka8a82Ff5q02C8qCWmxLYFC5wbTsImniRIcHLiNbN6wOF3adjtytCU3+WST15W4aBM0 0Ffw== X-Gm-Message-State: ALoCoQnwoRNmH1zgkbmCm0L6YiQEGWP7SCCwhAVfCoL0KxPcVVkoefDPA5DEkMLTiBYbRiN2JDVaTZpzYxyxc1HH6nnX/ivtjA== X-Received: by 10.66.120.200 with SMTP id le8mr25405155pab.61.1452984882340; Sat, 16 Jan 2016 14:54:42 -0800 (PST) From: Bart Schaefer Message-Id: <160116145505.ZM6664@torch.brasslantern.com> Date: Sat, 16 Jan 2016 14:55:05 -0800 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "compadd -Q -U completes $(( without inserting upon it" (Jan 16, 6:25pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: compadd -Q -U completes $(( without inserting upon it MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 16, 6:25pm, Sebastian Gniazdowski wrote: } } This looks like zsh source has embedded tweaks to make math } ($compstate[context] is "math" in second case) completing work more } reasonably. Is there a way to overcome this? Internally, when you invoke a completion widget, the ZLE buffer gets analyzed and divided into three sections: 1) The words array, which is the context where completion happens. 2) Anything before the words array, which completion is not allowed to modify. 3) Anything after the words array, similarly immutable. In "ordinary" command completion, (2) and (3) are empty. When you complete after a token such as $( or $(( that begins a context, those tokens are part of the immutable section that precedes the array of words. You can assign to the words array to change how completion interprets the set of possible matches, but anything you subsequently do has to fit into the part of $BUFFER corresponding to the original $words. You can make the mutable part smaller and expand the immutable parts by calling "compset -q", but nobody considered before that the reverse might also be interesting. The internals of "compset" are a bit of a nightmare, programmed by a brilliant Polish student who was fond of abbreviated variable names and rarely wrote comments. (The comments there are others trying mostly unsuccessfully to untangle his logic.) I've already outlined for you two ways to overcome this: A) Capture the set of matches using "compadd -O", then remove the bits that overlap with the immutable parts of the buffer before "compadd" again of what remains. (It's possible I've given you bad advice regarding the need for the -U option; try it without that as well.) B) Don't invoke completion directly; instead, invoke a normal editing widget to modify the buffer so the tokens do not begin a context, then call the completion widget, and finally clean up the buffer again when the completion widget returns. The tricky bit of (A) is keeping track of which part of the matches is really "immutable" and which part is not. The unfortunate bit of (B) is that it can't work at all as a completer function (zstyle element). There's also option (C) write your own completion system from scratch. When the current compsys was invented, the (z) and (Z) parameter flags didn't exist, so it was felt that it would be easier to allow the exiting completion internals to be callable to do most of that work. We also didn't have keymaps at that point, nor "zle -M" / "zle -R". A lot of what the completion system used to be the only way to do, can probably now be done in the shell language.