* PATCH: _unexpand @ 2005-07-10 1:18 Travis Spencer 2005-07-10 3:38 ` Bart Schaefer 0 siblings, 1 reply; 6+ messages in thread From: Travis Spencer @ 2005-07-10 1:18 UTC (permalink / raw) To: zsh-workers Here is a patch to add completion for the UNIX and Linux version of unexpand. --- /dev/null Sat Jul 9 18:12:21 2005 +++ Completion/Unix/Command/_unexpand Sat Jul 9 18:12:36 2005 @@ -0,0 +1,15 @@ +#compdef unexpand +# +# $Id:$ +# +# Copyright (C) 2005 Travis L. Spencer +# ALL RIGHTS RESERVED +# +# See the file LICENCE in the root of the zsh distribution for +# licensing information. +# + +_arguments \ + '-a[convert all whitespace, instead of just initial whitespace]' \ + '-t[use the given tab width or a list of specific tab positions]:tablist' \ + '*:file:_files' --- /dev/null Sat Jul 9 18:12:21 2005 +++ Completion/Linux/Command/_unexpand Sat Jul 9 18:12:49 2005 @@ -0,0 +1,18 @@ +#compdef unexpand +# +# $Id:$ +# +# Copyright (C) 2005 Travis L. Spencer +# ALL RIGHTS RESERVED +# +# See the file LICENCE in the root of the zsh distribution for +# licensing information. +# + +_arguments \ + {-a,--all}'[convert all whitespace, instead of just initial whitespace]' \ + '--first-only[convert only leading sequences of whitespace]' \ + {-t,--tabs=}'[use comma separated list of tab positions]:tablist' \ + '(* -)--help[display help message and exit]' \ + '(* -)--version[output version information and exit]' \ + '*:file:_files' ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: _unexpand 2005-07-10 1:18 PATCH: _unexpand Travis Spencer @ 2005-07-10 3:38 ` Bart Schaefer 2005-07-10 6:14 ` Travis Spencer 0 siblings, 1 reply; 6+ messages in thread From: Bart Schaefer @ 2005-07-10 3:38 UTC (permalink / raw) To: zsh-workers On Jul 9, 6:18pm, Travis Spencer wrote: } Subject: PATCH: _unexpand } } Here is a patch to add completion for the UNIX and Linux version of } unexpand. As the completion functions are preferentially installed all into a single directory (it's an extra configure option to install them in separate subdirectories), it is necessary to pick one location for any function -- I suggest Completion/Unix/Command/_unexpand in this case -- and have the function internally decide which version of the command it should be completing for. In other words, combine these into one file with an "if" test of some sort, and then they could be added to the distribution. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: _unexpand 2005-07-10 3:38 ` Bart Schaefer @ 2005-07-10 6:14 ` Travis Spencer 2005-07-10 16:20 ` Bart Schaefer 0 siblings, 1 reply; 6+ messages in thread From: Travis Spencer @ 2005-07-10 6:14 UTC (permalink / raw) To: zsh-workers On 7/9/05, Bart Schaefer <schaefer@brasslantern.com> wrote: > On Jul 9, 6:18pm, Travis Spencer wrote: > } Subject: PATCH: _unexpand > } > } Here is a patch to add completion for the UNIX and Linux version > of > } unexpand. > > As the completion functions are preferentially installed all into a > single directory (it's an extra configure option to install them in > separate subdirectories), it is necessary to pick one location for > any function -- I suggest Completion/Unix/Command/_unexpand in this > case -- and have the function internally decide which version of the > command it should be completing for. Glancing over the CVS repository's directory structure and some posts about MAC-only programs made me unsure. Good to know. Thanks. > In other words, combine these into one file with an "if" test of > some sort, and then they could be added to the distribution. I looked through the existing functions in the distribution, and I saw a function that looked pretty good -- _pick_variant. That sounded like it might be useful, so I figured out how it worked and coded it up. It worked fine on my Linux box but not on my Solaris system. In my Sol environment, I have the FSF's unexpand at the head of my path. I wanted to test it with the Sun version, so I reexported my PATH and rehashed. To my surprise, the tab completion still showed the GNU flags. I double, triple and even quadruple checked my use of the _pick_variant function, and I'm sure I was calling it correctly. I think there is a bug in that function. Here is a typescript showing what I did. The first run (2345-2349) in the output is with the non-_pick_variant version of my completion. The second run (2350-2354), uses _pick_variant. Script started on Sat Jul 09 22:35:28 2005 2345 tspencer@murzim.cs (~) > unexpand --version unexpand (coreutils) 5.2.1 Written by David MacKenzie. Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 2346 tspencer@murzim.cs (~) > unexpand - --all -a -- convert all whitespace, instead of just initial whitespace --first-only -- convert only leading sequences of whitespace --help -- display help message and exit --tabs -t -- use comma separated list of tab positions --version -- output version information and exit 2346 tspencer@murzim.cs (~) > export PATH=/usr/bin:$PATH ; rehash 2347 tspencer@murzim.cs (~) > unexpand --version unexpand: illegal option -- - usage: unexpand [-a ] [-t tablist] [file ...] 2348 tspencer@murzim.cs (~) > unexpand - -a -- convert all whitespace, instead of just initial whitespace -t -- use comma separated list of tab positions 2349 tspencer@murzim.cs (~) > script done on Sat Jul 09 22:36:25 2005 Script started on Sat Jul 09 22:36:37 2005 2350 tspencer@murzim.cs (~) > unexpand --version unexpand (coreutils) 5.2.1 Written by David MacKenzie. Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 2351 tspencer@murzim.cs (~) > unexpand - --all -a -- convert all whitespace, instead of just initial whitespace --first-only -- convert only leading sequences of whitespace --help -- display help message and exit --tabs -t -- use comma separated list of tab positions --version -- output version information and exit 2351 tspencer@murzim.cs (~) > export PATH=/usr/bin:$PATH; rehash 2352 tspencer@murzim.cs (~) > unexpand --version unexpand: illegal option -- - usage: unexpand [-a ] [-t tablist] [file ...] 2353 tspencer@murzim.cs (~) > unexpand - --all -a -- convert all whitespace, instead of just initial whitespace --first-only -- convert only leading sequences of whitespace --help -- display help message and exit --tabs -t -- use comma separated list of tab positions --version -- output version information and exit 2354 tspencer@murzim.cs (~) > script done on Sat Jul 09 22:37:34 2005 See how _pick_variant continues to output the GNU options even after reexporting the PATH and rehashing? BTW, this was run with zsh 4.2.0, but _pick_variant doesn't seem to be any different in the latest CVS. At any rate, here is the updated patch. --- /dev/null Sat Jul 9 22:45:45 2005 +++ Completions/Unix/Command/_unexpand Sat Jul 9 22:46:12 2005 @@ -0,0 +1,43 @@ +#compdef unexpand +# +# $Id:$ +# +# Copyright (C) 2005 Travis L. Spencer +# ALL RIGHTS RESERVED +# +# See the file LICENCE in the root of the zsh distribution for +# licensing information. +# + +local all tabs ret=1 +local -a args + +all="convert all whitespace, instead of just initial whitespace" +tabs="use comma separated list of tab positions" +args=( + "(--all)-a[$all]" + "(--tabs)-t[$tabs]:tablist" + "*:file:_files" +) + +#if _pick_variant gnu="Free Soft" unix --version; then +if (unexpand --version 2>&1 | grep -i "Free Soft") > /dev/null ; then + args+=( + "(-a)--all[$all]" + "--first-only[convert only leading sequences of whitespace]" + "(-t)--tabs=[$tabs]:tablist" + "(* -)--help[display help message and exit]" + "(* -)--version[output version information and exit]" + ) +fi + +_arguments "$args[@]" && ret=0 + +return ret + +: <<EMACS_LOCAL_VARIABLES +Local Variables: +mode: shell-script +mode: flyspell-prog +End: +EMACS_LOCAL_VARIABLES ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: _unexpand 2005-07-10 6:14 ` Travis Spencer @ 2005-07-10 16:20 ` Bart Schaefer 2005-07-11 0:52 ` Travis Spencer 0 siblings, 1 reply; 6+ messages in thread From: Bart Schaefer @ 2005-07-10 16:20 UTC (permalink / raw) To: zsh-workers On Jul 9, 11:14pm, Travis Spencer wrote: } } I looked through the existing functions in the distribution, and I saw } a function that looked pretty good -- _pick_variant. } [...] I have the FSF's unexpand at the head of my path. } I wanted to test it with the Sun version, so I reexported my PATH and } rehashed. To my surprise, the tab completion still showed the GNU } flags. That may be because _pick_variant caches its results so that it doesn't have to re-run the command every time you do a completion. It appears from both of those typescripts as if you first tried a completion with the gnu version, then changed your path and tried again. That won't do the right thing; you have to try completion the very first time with the version that you will always be using thereafter. Try "unset _cmd_variant" right after you change your path, to clear the _pick_variant cache. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: _unexpand 2005-07-10 16:20 ` Bart Schaefer @ 2005-07-11 0:52 ` Travis Spencer 2005-07-11 3:26 ` Bart Schaefer 0 siblings, 1 reply; 6+ messages in thread From: Travis Spencer @ 2005-07-11 0:52 UTC (permalink / raw) To: zsh-workers On Sun, Jul 10, 2005 at 04:20:10PM +0000, Bart Schaefer wrote: > Try "unset _cmd_variant" right after you change your path, to clear the > _pick_variant cache. Ya, that did it. I guess the use of _pick_variant will work, but IMO rehash should invalidate the cache that _pick_variant is hanging onto. I've aliased rehash to `rehash && unset _cmd_variant', so I don't get bit by that one again. Here is a patch that uses _pick_variant instead: --- /dev/null Sun Jul 10 17:44:10 2005 +++ Completion/Unix/Command/_unexpand Sun Jul 10 17:32:36 2005 @@ -0,0 +1,42 @@ +#compdef unexpand +# +# $Id:$ +# +# Copyright (C) 2005 Travis L. Spencer +# ALL RIGHTS RESERVED +# +# See the file LICENCE in the root of the zsh distribution for +# licensing information. +# + +local all tabs ret=1 +local -a args + +all="convert all whitespace, instead of just initial whitespace" +tabs="use comma separated list of tab positions" +args=( + "(--all)-a[$all]" + "(--tabs)-t[$tabs]:tablist" + "*:file:_files" +) + +if _pick_variant gnu="Free Soft" unix --version; then + args+=( + "(-a)--all[$all]" + "--first-only[convert only leading sequences of whitespace]" + "(-t)--tabs=[$tabs]:tablist" + "(* -)--help[display help message and exit]" + "(* -)--version[output version information and exit]" + ) +fi + +_arguments "$args[@]" && ret=0 + +return ret + +: <<EMACS_LOCAL_VARIABLES +Local Variables: +mode: shell-script +mode: flyspell-prog +End: +EMACS_LOCAL_VARIABLES ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: _unexpand 2005-07-11 0:52 ` Travis Spencer @ 2005-07-11 3:26 ` Bart Schaefer 0 siblings, 0 replies; 6+ messages in thread From: Bart Schaefer @ 2005-07-11 3:26 UTC (permalink / raw) To: zsh-workers On Jul 10, 5:52pm, Travis Spencer wrote: } } rehash should invalidate the cache that _pick_variant is hanging onto. Eventually zsh will have something like ksh's "discipline functions" at which point it might be possible to arrange for this to happen when the path is reset. As it is, there isn't any good way to "hook" an action without potentially conflicting with something the user has done. } Here is a patch that uses _pick_variant instead: I'll commit this. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-07-11 3:27 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-10 1:18 PATCH: _unexpand Travis Spencer 2005-07-10 3:38 ` Bart Schaefer 2005-07-10 6:14 ` Travis Spencer 2005-07-10 16:20 ` Bart Schaefer 2005-07-11 0:52 ` Travis Spencer 2005-07-11 3:26 ` Bart Schaefer
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).