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

Re: Custom auto complete



On Aug 6, 12:37am, Domagoj Pintaric wrote:
}
} The solution you posted sort of dose what I want. With this code I have to
} type ?<some char(s)> in order for it to work. If I just type ? and hit tab
} it dose not work.

Hm.  I did test it.  Could you post the actual function?

} I get that's because of  ( \?* ) and I tried (\?) but it dose not work.
} Interesting, if I use for example ( \! ) that works as expected. Is the '?'
} special for some reason?

Depends on the order of your completer style.  I only tried with _query
as the first one.  If e.g. you have _expand in there ahead of _query,
_expand will try to use the "?" on the command line as a glob pattern.

You haven't really told us enough details to make a diagnosis.  On the
other hand you seem to prefer the custom key binding, so maybe it does
not matter.

} zle -C custom-complete menu-expand-or-complete _parse_sb_file

Why did you chose menu-expand-or-complete here, rather than just
menu-complete?  When would you be using this binding for expansion?

See also below ...

} _parse_sb_file () {
}         WORDS=(${(f)"$(<$SB_FILE_PATH)"}) 
}         ARRAY=() 
}         integer POS=1
}         for ITEM in ${WORDS}
}         do
}                 ARRAY[${POS}]=${POS}") "${WORDS[${POS}]} 
}                 (( POS++ ))
}         done
}         compadd -l -d ARRAY -a -S '' -- WORDS
} }
} 
} bindkey ${CTRLTAB_KEY} custom-complete
} 
} This works but I have some issues with this to:
} 
} 1) if I press ctrl-tab I can not select the options with arrow keys I can
} just switch them with ctrl-tab, unless I first run for example "cp <TAB>"

This is very likely because you haven't yet loaded the zsh/complist module
the first time you try this, or you've loaded it but not set $MENUSELECT.
When you invoke the completion system with <TAB> it loads the module and
sets the variable for you, and thereafter menu completion notices that
$MENUSELECT has become set and enters the selection list.

If you load the module yourself, you can bind to the menu-select widget
and force entry into the selection list every time:

    zmodload zsh/complist
    zle -C custom-complete menu-select _parse_sb_file

} 2) if I have this string, for example, in a file "cp file1 file2" it is
} inserted like this "cp\ file1\ file2". The white spaces are escaped, how
} can I disable this, and tell zsh to insert a string as it is.

You need the -Q option when calling "compadd".  However, note that when
deciding to re-enter completion, the command line is going to be split
on spaces, even if those spaces were inserted by a previous completion.



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