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: Tue, 12 Jan 2016 11:39:28 -0800	[thread overview]
Message-ID: <160112113928.ZM9065@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVBCEM=46YmgmhPR==Rq+pSfY+hgr8bcOMLV=zLFm6THBg@mail.gmail.com>

On Jan 12,  2:09pm, Sebastian Gniazdowski wrote:
} Subject: Re: _history-complete-older problems with $(
}
} I think the hacks are acceptable if the code will be used only by
} Alt-/ (_history-complete-older). How to accomplish this, btw?

You would need to change the _history_complete_word_gen_matches
function in the _history_complete_word file to replace

    _main_complete _history

with

    _main_complete _widen_for_history

} Are this expected values? Because despite proposing $(( 0 + 1 ))
} correctly after $(<TAB>  (btw., not after $(<Alt-/>), the completer
} behaves weird. For "ls <TAB>" it doesn't propose any files.

I can't reproduce this.  There may need to be some tests for success
of the calls to "builtin compadd" in the substitute compadd function;
given

    zstyle ':completion:*' completer _widen_for_history _complete

(the _complete at the end is important) there will only be completions
generated by _complete when _widen_for_history returns nonzero.  It is
possible you've found some circumstance in which it returns 0 but does
not add any actual matches.

I'm not trivally able to reproduce that.

} > 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.
} 
} I would gladly perform the work but the code is quite difficult. Could
} you state in one sentence what it is doing? Variables $CURRENT, $word
} aren't documented in zshzle.1.

They're documented in "man zshcompwid".

} What does the {} always {} block of code do?

 { TRY-LIST } always { ALWAYS-LIST }
     First execute TRY-LIST.  Regardless of errors, or break, continue,
     or return commands encountered within TRY-LIST, execute
     ALWAYS-LIST.  Execution then continues from the result of the
     execution of TRY-LIST; in other words, any error, or break,
     continue, or return command is treated in the normal way, as if
     ALWAYS-LIST were not present.  The two chunks of code are referred
     to as the `try block' and the `always block'.

} Next, I would guess that "builtin compadd -O found "$@""
} performs one run of matching, is this correct?

    -O ARRAY
          If this option is given, the WORDS are _not_ added to the set
          of possible completions.  Instead, matching is done as usual
          and all of the WORDS given as arguments that match the string
          on the command line will be stored in the array parameter
          whose name is given as ARRAY.

} Why second comadd, and
} what does "${(@)${(@)found#$PREFIX}%$SUFFIX}" do?

Suppose you have "$(" on the line, and the completion is $((1+2)).  The
$found array will contain "$((1+2))" (and possibly other elements).  In
the setup to at the beginning of _widen_for_history, PREFIX="$(" was
assigned (that $left[-1]).  So now we need to remove "$(" from the
values in $found to get the actual string to insert to finish the word,
i.e., "(1+2))".  Similarly we would need to remove $SUFFIX (taken from
$right) from the end of the values if there were one.

${...#$PREFIX} removes from the left and ${...%$SUFFIX} removes from
the right.

Normally "builtin compadd" would handle this for us, but internally it
still thinks it is populating command words that must follow the open
paren; so we have to fix things up before we make the final call.

(That's not an entirely accurate description of the "internally" part
but it suffices to explain why we must trim the prefix/suffix.)


  reply	other threads:[~2016-01-12 19:39 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
2016-01-12 13:09     ` Sebastian Gniazdowski
2016-01-12 19:39       ` Bart Schaefer [this message]
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=160112113928.ZM9065@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).