zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: _history-complete-older problems with $(
Date: Mon, 11 Jan 2016 16:15:01 -0800	[thread overview]
Message-ID: <160111161501.ZM5305@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVDVR=B8SWX+gSiNvtODWZ-25LtDz7jXVDH8BtrcxMnjXQ@mail.gmail.com>

On Jan 11,  5:21pm, Sebastian Gniazdowski wrote:
} Subject: Re: _history-complete-older problems with $(
}
} on IRC it came up that $( is a start of a subshell and that it makes
} completion start over at this place. Seems that $(( works in the same
} way. Is there any possibility to change that? Even at level of C code?

The following produces the correct set of completion matches (pardon the
unimaginative name) but is a bit of a hack (it breaks _complete_debug
and _complete_help):

  _widen_for_history () {
    local -a left=( "${(z)LBUFFER}" )
    local right="${words[CURRENT]#${left[-1]}}"
    words=( "${(z)BUFFER}" )
    CURRENT=${#left}
    PREFIX="${left[-1]}"
    IPREFIX=''
    SUFFIX="${right}"
    ISUFFIX=''
    {
      compadd () {
	local -a found
	builtin compadd -O found "$@"
	builtin compadd -Q -U "${(@)${(@)found#$PREFIX}%$SUFFIX}"
      }
      _history
    } always {
      unfunction compadd
    }
  }
  zstyle ':completion:*' completer _widen_for_history _complete

This needs some work around the issue of empty words, i.e., when
completing in empty parens such as $(<TAB>) then $words[CURRENT] is
empty and the trailing paren must be copied from $RBUFFER to SUFFIX.
I haven't dived into that detail.

It could be further refined (with a lot of work) to widen only to the
next "outward" command, e.g., in

  foo $(bar $(<TAB>

to extend back only as far as "bar" rather than to "foo", which might
turn out to be important for some multi-line buffers, I'm not sure.

Another approach would be to create a custom key binding for a widget
which

- inserts an open quote before the current word
- invokes completion with completer style set to _history
- removes quoting again

but that has its own complications if the word on the line is already
quoted, etc.


  reply	other threads:[~2016-01-12  0:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-10 19:35 Sebastian Gniazdowski
2016-01-11 16:21 ` Sebastian Gniazdowski
2016-01-12  0:15   ` Bart Schaefer [this message]
2016-01-12 13:09     ` Sebastian Gniazdowski
2016-01-12 19:39       ` Bart Schaefer
2016-01-13  1:01         ` Daniel Shahaf
2016-01-13  2:01           ` Bart Schaefer
2016-01-13 16:40             ` Sebastian Gniazdowski
2016-01-14  4:48               ` Bart Schaefer
2016-01-14 11:30                 ` Sebastian Gniazdowski
2016-01-14 11:37                   ` Sebastian Gniazdowski
2016-01-14 11:59                     ` Sebastian Gniazdowski
2016-01-15  3:18                   ` Bart Schaefer
2016-01-15  5:07                     ` Sebastian Gniazdowski
2016-01-15  6:26                     ` Daniel Shahaf
2016-01-14 18:55                 ` Sebastian Gniazdowski
2016-01-14  9:52               ` Sebastian Gniazdowski
2016-01-14 10:14                 ` Sebastian Gniazdowski
2016-01-14 10:55                   ` Sebastian Gniazdowski
2016-01-15  3:05                     ` Bart Schaefer
2016-01-15  6:26                 ` Daniel Shahaf
2016-01-13  1:01       ` Daniel Shahaf
2016-01-13  1:59         ` Bart Schaefer
2016-01-12  7:57 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160111161501.ZM5305@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).