zsh-users
 help / color / mirror / code / Atom feed
* custom command completion for a zshdb, a REPL
@ 2011-05-09 13:09 Rocky Bernstein
  2011-05-10  9:59 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Rocky Bernstein @ 2011-05-09 13:09 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

I would like to add debugger command completion to the zsh debugger, zshdb.
 I have looked over the manual pages zshzle and zshcompsys and am still a
bit confused.

I would be grateful if someone could give a simple script as an example.
Suppose the list of REPL (read, print, loop) commands is in  a
blank-delimited string variable "cmds", and that one of the commands is
"foo" which has the list of subcommands for it in string variable "subcmd".

For comparison here is the corresponding bash code:

    typeset cmds; cmds='foo food woot'  # My RLE commands
    level0_complete_fn() {
        if (( COMP_POINT >  0)) ; then
            COMPREPLY=( $(compgen -W  "$cmds" "$COMP_LINE") )
        else
            COMPREPLY=( $cmds )
        fi
    }

    typeset subcmds; foo_subcmds='bar baz'
    foo_subcmd_complete() {
        COMPREPLY=( $foo_subcmds )
    }

    # Use a special version of bash read that handle's readline completion
    enable -f /src/external-vcs/bashdb/builtin/readc readc

    complete -D -F level0_complete_fn
    complete -F foo_subcmd_complete foo

    # Shell initialization
    shopt -s progcomp
    set -o emacs
    bind 'set show-all-if-ambiguous on'
    bind 'TAB:menu-complete'

    readc -e -p 'huh? ' line
    echo "you sez $line"

I would not like to have completion files the available commands and
sub-commands can be dynamic. For example, on the stack frame completion
might be a positive integer up to the number of stack frames. And this
changes in the course of execution.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: custom command completion for a zshdb, a REPL
  2011-05-09 13:09 custom command completion for a zshdb, a REPL Rocky Bernstein
@ 2011-05-10  9:59 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2011-05-10  9:59 UTC (permalink / raw)
  To: zsh-users

On Mon, 9 May 2011 09:09:32 -0400
Rocky Bernstein <rocky.bernstein@gmail.com> wrote:
> I would like to add debugger command completion to the zsh debugger,
> zshdb.

You will need to use "vared" to read the line via ZLE and set a special
completion context.  Have a look at zcalc (Functions/Misc/zcalc) and
_zcalc_line (Completion/Zsh/Context/_zcalc_line).  The way they work
together is that zcalc defines a value for compcontext which corresponds
to the value in the "#compdef" line at the top of _zcalc_line.

Beyond that, it should be just a standard completion function project.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-05-10  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-09 13:09 custom command completion for a zshdb, a REPL Rocky Bernstein
2011-05-10  9:59 ` Peter Stephenson

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).