zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-user <zsh-users@zsh.org>
Subject: Re: _history_complete_word and history word begin with quote
Date: Fri, 3 Apr 2015 09:51:22 -0700	[thread overview]
Message-ID: <150403095122.ZM13703@torch.brasslantern.com> (raw)
In-Reply-To: <20150403061621.GF2805@localhost.localdomain>

On Apr 3,  2:16pm, Han Pingtian wrote:
}
} Looks like if a history word begins with quote, _history_complete_word
} cannot complete it?

This is a more generic issue which just happens to be more easily seen
with _history_complete_word.  The gist of it is that, if the word has
an quote mark to the left of the cursor, then completion does not treat
the quote as part of the word to be matched, but instead tries to append
new text to the quoted string.

This applies everywhere, not just for history words; e.g. if you type an
open quote and then press TAB to complete file names, those names will
appear after the opening quote and a closing quote will be offered if
the file is not a directory.  This is meant to allow the user to choose
how a file name that contains spaces or metacharacters will be quoted in
the final command line, rather than forcing a quoting style.  (It would
be a whole lot easier for the internals if we forced the quoting, and
completion did that at first years ago, but too many users griped.)

There is presently no way to turn this off or otherwise force the quote
to become part of the match target.  $compstate[quote] is read-only.

The closest we could get is to run "compset -q" when then produces
completions like this:

torch% echo "\"foo bar\"
world        hello        print        \"foo bar\"  print  

Or without the quote on the command line:

torch% echo 
world         hello         print         \"foo\ bar\"  print       


We could instead peel the quotes off the history words before offering
them as completions (diff below) but this might have unwanted side-
effects elsewhere.

diff --git a/Completion/Base/Completer/_history b/Completion/Base/Completer/_history
index 63878ac..cd69ca1 100644
--- a/Completion/Base/Completer/_history
+++ b/Completion/Base/Completer/_history
@@ -51,9 +51,14 @@ ISUFFIX=
 # We skip the first element of historywords so the current word doesn't
 # interfere with the completion
 
+local -a hslice
 while [[ $compstate[nmatches] -eq 0 && beg -lt max ]]; do
+  if [[ -n $compstate[quote] ]]
+  then hslice=( ${(Q)historywords[beg,beg+slice]} )
+  else hslice=( ${historywords[beg,beg+slice]} )
+  fi
   _wanted "$opt" history-words expl 'history word' \
-      compadd -Q -a 'historywords[beg,beg+slice]'
+      compadd -Q -a hslice
   (( beg+=slice ))
 done
 


      reply	other threads:[~2015-04-03 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03  6:16 Han Pingtian
2015-04-03 16:51 ` Bart Schaefer [this message]

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=150403095122.ZM13703@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@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).