From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27135 invoked by alias); 13 Feb 2013 17:39:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17637 Received: (qmail 19920 invoked from network); 13 Feb 2013 17:39:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130213093924.ZM831@torch.brasslantern.com> Date: Wed, 13 Feb 2013 09:39:24 -0800 In-reply-to: <511B6069.1070302@desy.de> Comments: In reply to Jan Eike von Seggern "Caching variables during completion" (Feb 13, 10:44am) References: <511B6069.1070302@desy.de> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Caching variables during completion MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 13, 10:44am, Jan Eike von Seggern wrote: } } my question first: Is it possible to set a variable only once during } every command-line completion, i.e. only after hitting for the } first time and then keeping the contents for this specific command-line? Depending on whether you mean all completions for the current command line or just all repetitions of completion for the same word (e.g., cycling through a menu) there may be different approaches to this. Within completion on a single word, you can look at the _oldlist completer for an example. Based on your additional explanation, though, I suspect that's not what you're after, but the basic idea is still the same: Create a function which you reference at the beginning of the completer zstyle. That function tests (somehow) whether the cached state needs to be refreshed. In your particular example, it should work to cache the value of $HISTNO and then reload the cache if it has changed. Crudely: _xrcache() { if (( $_xr_HISTNO != $HISTNO )) then _xr_HISTNO=$HISTNO _xr_output=$(xrandr -q) fi return 1 # always "fail" so other completers are tried } zstyle ':completion:*' completer _xrcache _oldlist _expand _complete # etc.