From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7811 invoked by alias); 1 Mar 2011 20:40:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28835 Received: (qmail 19207 invoked from network); 1 Mar 2011 20:40:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) 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.1 Received-SPF: none (ns1.primenet.com.au: domain at klanderman.net does not designate permitted sender hosts) From: Greg Klanderman To: Zsh list Subject: PATCH: zstyle to control completion of functions/parameters beginning with underscore Reply-To: gak@klanderman.net Date: Tue, 01 Mar 2011 15:39:55 -0500 In-Reply-To: <2d460de70905280148iebfcegcb4143c33e510efd@mail.gmail.com> (Richard Hartmann's message of "Thu, 28 May 2009 10:48:45 +0200") Message-ID: User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.17 (linux) References: <1238890030-4683-1-git-send-email-ft@bewatermyfriend.org> <090404193718.ZM19801@torch.brasslantern.com> <20090405191304.1908fca8@pws-pc> <090405151115.ZM13159@torch.brasslantern.com> <20090406100929.505617e2@news01> <2d460de70905270930j681da6a5kf7848d67d89f0c69@mail.gmail.com> <20090527175941.3bbe2eba@news01> <2d460de70905280148iebfcegcb4143c33e510efd@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Following up to http://www.zsh.org/mla/workers/2009/msg00793.html from almost two years ago: >>>>> On May 28, 2009 Richard Hartmann wrote: > On Wed, May 27, 2009 at 21:12, Greg Klanderman wrote: >> But in the same vein, what I really want is a way to configure the >> behavior for functions, variables, etc. beginning with "_" to be like >> filenames beginning with ".": completion should work if I have >> explicitly typed the leading "_", but even substring matching should >> not *generate* a leading "_". > I think this is a good explanation of what, imo, the final goal should be. What do you guys think of the patch below? I'm open to better names for the zstyle.. I've tested it a fair amount locally. thanks, Greg Index: Completion/Zsh/Type/_command_names =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_command_names,v retrieving revision 1.9 diff -u -r1.9 _command_names --- Completion/Zsh/Type/_command_names 19 Aug 2007 23:31:31 -0000 1.9 +++ Completion/Zsh/Type/_command_names 1 Mar 2011 20:28:22 -0000 @@ -4,10 +4,20 @@ # complete only external commands and executable files. This and a # `-' as the first argument is then removed from the arguments. -local args defs +local args defs hide ffilt zstyle -t ":completion:${curcontext}:commands" rehash && rehash +zstyle -s ":completion:${curcontext}:functions" hide-internal hide +case "${hide:-never}" in + no|false|never) + ffilt='';; + yes|true|always) + ffilt='[(I)[^_.]*]';; + auto|dtrt) + [[ $PREFIX = [_.]* ]] && ffilt='' || ffilt='[(I)[^_.]*]';; +esac + defs=( 'commands:external command:_path_commands' ) @@ -24,7 +34,7 @@ defs=( "$defs[@]" 'builtins:builtin command:compadd -k builtins' - 'functions:shell function:compadd -k functions' + "functions:shell function:compadd -k functions$ffilt" 'aliases:alias:compadd -k aliases' 'suffix-aliases:suffix alias:_suffix_alias_files' 'reserved-words:reserved word:compadd -k reswords' Index: Completion/Zsh/Type/_parameters =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_parameters,v retrieving revision 1.1 diff -u -r1.1 _parameters --- Completion/Zsh/Type/_parameters 2 Apr 2001 11:20:15 -0000 1.1 +++ Completion/Zsh/Type/_parameters 1 Mar 2011 20:28:22 -0000 @@ -6,7 +6,7 @@ # If you specify a -g option with a pattern, the pattern will be used to # restrict the type of parameters matched. -local expl pattern fakes faked tmp +local expl pattern fakes faked tmp hide pfilt pattern=(-g \*) zparseopts -D -K -E g:=pattern @@ -23,8 +23,18 @@ done fi +zstyle -s ":completion:${curcontext}:parameters" hide-internal hide +case "${hide:-never}" in + no|false|never) + pfilt='';; + yes|true|always) + pfilt='[^_.]';; + auto|dtrt) + [[ $PREFIX = [_.]* ]] && pfilt='' || pfilt='[^_.]';; +esac + _wanted parameters expl parameter \ compadd "$@" -Q - \ - "${(@k)parameters[(R)${pattern[2]}~*local*]}" \ + "${(@M)${(@k)parameters[(R)${pattern[2]}~*local*]}:#${~pfilt}*}" \ "$fakes[@]" \ "${(@)${(@M)faked:#${~pattern[2]}}%%:*}" Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.232 diff -u -r1.232 compsys.yo --- Doc/Zsh/compsys.yo 17 Dec 2010 17:10:48 -0000 1.232 +++ Doc/Zsh/compsys.yo 1 Mar 2011 20:28:22 -0000 @@ -1658,6 +1658,14 @@ completions at all, the tt(tag-order) style can be modified as described below. ) +kindex(hide-internal, completion style) +item(tt(hide-internal))( +This style is applicable to the tt(functions) and tt(parameters) completion +tags. If tt(true), never complete internal names (i.e. those whose names +begin with '_' or '.'). If tt(false) (the default) then always complete +internal names. If tt(auto), then only complete internal names when the +leading character is explicitly matched. +) kindex(hosts, completion style) item(tt(hosts))( A list of names of hosts that should be completed. If this is not set,