Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

(Fwd) Re: compctl -y problem.



Sorry about the duplication to zsh-workers recipients ... I meant to change
the destination address but then clicked Send too quickly.

--- Forwarded mail from <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> ("Bart Schaefer")

From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 May 2001 16:35:08 +0000
To: zsh-workers@xxxxxxxxxx
Subject: Re: compctl -y problem.
Cc: Cesar Crusius <crusius@xxxxxxxxxxxxxxxxxxx>

(Part of this thread went to zsh-workers ... returning now to zsh-users
with a workaround)

On May 25,  3:11pm, Bart Schaefer wrote:
}
} I know Sven won't be thrilled about being asked to fix anything in the
} old compctl code ... perhaps we should just remove the `-y' option, as
} it's new since 3.0 anyway, and document the correct way to achieve the
} same effect by using the new completion system (which, incidentally, I
} don't know how to do ... `compadd -d' doesn't quite cut it).

On further reading of the compadd doc, `compadd -ld ...' appears to be
the thing to do, though it's a bit convoluted.

autoload -U compinit
compinit

function _aecd {
  local change_descriptions reply
  # Force change_descriptions to be a one-element array
  change_descriptions=("$(aereport changes -unf | grep -v completed)")
  # The name "reply" is not special here, I just happened to use it
  reply=($(aereport changes -terse | grep -v completed | sed -e 's/ .*$//'))
  # Display the change_descriptions in place of the first completion
  compadd -ld change_descriptions $reply[1]
  # Add the rest of the completions, but don't display them in the list
  compadd -na 'reply[2,-1]'
  # Force the list to appear so the descriptions are visible
  compstate[list]='list force'
}
compdef _aecd aecd

It does appear that "compadd -d" still produces a sub-optimal display in
this case if there are any lines in $change_descriptions that have exactly
$COLUMNS characters; but it properly returns the cursor to the right spot
even so.

I don't know what the output of `aereport changes` looks like, so it may
be that there's a simpler solution.  For example, if the same number of
lines will be returned by `aereport changes -unf` and `... -terse`, this
will work:

function _aecd {
  local change_descriptions reply
  change_descriptions=(${(f)"$(aereport changes -unf | grep -v completed)"})
  reply=($(aereport changes -terse | grep -v completed | sed -e 's/ .*$//'))
  compadd -ld change_descriptions -a reply
  compstate[list]='list force'
}

You may also wish to drop that compstate[list] assignment and instead use
the force-list style to control it:

zstyle ':completion:*:aecd' force-list always

See the manual for more.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


---End of forwarded mail from <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> ("Bart Schaefer")

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author