* _man igores global matchers @ 2001-05-29 12:05 Andrej Borsenkow 2001-05-29 12:18 ` Sven Wischnowsky 0 siblings, 1 reply; 14+ messages in thread From: Andrej Borsenkow @ 2001-05-29 12:05 UTC (permalink / raw) To: ZSH Workers Mailing List I am not sure, where to put it in; I was under impression that _wanted does it automagically? -andrej ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-05-29 12:05 _man igores global matchers Andrej Borsenkow @ 2001-05-29 12:18 ` Sven Wischnowsky 2001-05-31 13:32 ` Andrej Borsenkow 0 siblings, 1 reply; 14+ messages in thread From: Sven Wischnowsky @ 2001-05-29 12:18 UTC (permalink / raw) To: zsh-workers Andrej Borsenkow wrote: > I am not sure, where to put it in; I was under impression that _wanted does > it automagically? Look at _man, you'll see things like: rep=( $manpath/(sman|man|cat)*/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) I.e., it does its matching/filtering itself, before the completion code has a chance to use any match specs. That's ugly. But caching could be pretty costly. Maybe we should make it configurable, mentioning the problem with match specs? Any other ideas, anyone? Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: _man igores global matchers 2001-05-29 12:18 ` Sven Wischnowsky @ 2001-05-31 13:32 ` Andrej Borsenkow 2001-05-31 15:24 ` Sven Wischnowsky 2001-05-31 15:46 ` Bart Schaefer 0 siblings, 2 replies; 14+ messages in thread From: Andrej Borsenkow @ 2001-05-31 13:32 UTC (permalink / raw) To: zsh-workers > > Look at _man, you'll see things like: > > rep=( $manpath/(sman|man|cat)*/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) > > I.e., it does its matching/filtering itself, before the completion code > has a chance to use any match specs. > > That's ugly. But caching could be pretty costly. Maybe we should make > it configurable, mentioning the problem with match specs? > > Any other ideas, anyone? > Is it possible just use _path_files? for i in $manpath; do _path_files -W $i '*.(bz2|z|gz|Z).<->*' done or like? Alternatively, it is nice having _path_files to support -O/-A flags. Was it not discussed somewhere? -andrej ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: RE: _man igores global matchers 2001-05-31 13:32 ` Andrej Borsenkow @ 2001-05-31 15:24 ` Sven Wischnowsky 2001-05-31 15:46 ` Bart Schaefer 1 sibling, 0 replies; 14+ messages in thread From: Sven Wischnowsky @ 2001-05-31 15:24 UTC (permalink / raw) To: zsh-workers Andrej Borsenkow wrote: > > > > Look at _man, you'll see things like: > > > > rep=( $manpath/(sman|man|cat)*/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) > > > > I.e., it does its matching/filtering itself, before the completion code > > has a chance to use any match specs. > > > > That's ugly. But caching could be pretty costly. Maybe we should make > > it configurable, mentioning the problem with match specs? > > > > Any other ideas, anyone? > > > > Is it possible just use _path_files? > > for i in $manpath; do > _path_files -W $i '*.(bz2|z|gz|Z).<->*' > done Probably, but more expensive (dunno how much slower it makes it, though). And one would have to get rid of the paths and suffixes, which isn't trivial. > or like? Alternatively, it is nice having _path_files to support -O/-A > flags. Was it not discussed somewhere? I seem to remember that someone said it would be nice to have, but it's so hard to implement, because we can't easily rely on the compadd- options since they are used by _path_files itself. On the other hand, _path_files builds an array with the matches, but what to do with all the prefixes and suffixes that make the calls to compadd so complicated in _path_files? Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-05-31 13:32 ` Andrej Borsenkow 2001-05-31 15:24 ` Sven Wischnowsky @ 2001-05-31 15:46 ` Bart Schaefer 2001-05-31 17:20 ` Bart Schaefer 1 sibling, 1 reply; 14+ messages in thread From: Bart Schaefer @ 2001-05-31 15:46 UTC (permalink / raw) To: Andrej Borsenkow, zsh-workers On May 31, 5:32pm, Andrej Borsenkow wrote: } } > Look at _man, you'll see things like: } > } > rep=( $manpath/(sman|man|cat)*/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) } > } > I.e., it does its matching/filtering itself, before the completion code } > has a chance to use any match specs. } > } > That's ugly. But caching could be pretty costly. Maybe we should make } > it configurable, mentioning the problem with match specs? I presume by "caching could be pretty costly" you mean something like the patch below (which I will not commit without positive feedback). There's not actually a cache there, but it does create some arrays with 5000 or so elements. } > Any other ideas, anyone? } } Is it possible just use _path_files? No, because you're not completing the file names, you're completing just some base part of the file names. } Alternatively, it is nice having _path_files to support -O/-A flags. } Was it not discussed somewhere? It was discussed. The problem is that _path_files may call compadd more than once to add different sets of completions, which is not presently supported with -A/-O (each new call would overwrite the matches added by a previous call). This patch drops the filtering on man page name and instead slurps up all the file basenames into the `rep' array, then passes that and the global matcher spec to compadd to let it sort out the mess. If you have several matchers this can get pretty slow, so it ought at least to cache `rep' somewhere during the loop over the matchers; as it stands this is mostly a proof of concept. Index: Completion/Unix/Command/_man =================================================================== retrieving revision 1.1.1.1 diff -c -r1.1.1.1 _man --- Completion/Unix/Command/_man 2001/04/09 20:14:09 1.1.1.1 +++ Completion/Unix/Command/_man 2001/05/31 15:20:19 @@ -6,16 +6,6 @@ _files || return 0 fi -if [[ $compstate[pattern_match] != [^*] ]]; then - # If a string other than *, we just want correction, so no `*'. - star='*' -fi - -if [[ -n $_comp_correct ]]; then - # If this is set, we are correcting with this many approximations. - approx="(#a${_comp_correct})" -fi - if (( ! $#manpath )); then local mp mp=($(manpath 2>/dev/null)) @@ -32,10 +22,10 @@ mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N)) if [[ $words[2] = (<->*|1M|l|n) ]]; then rep=( - $manpath/(sman|man|cat)${words[2]}/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) + $manpath/(sman|man|cat)${words[2]}/*.*(:t) ) (($#mrd)) && rep[$#rep+1]=($(awk "\$2 == \"$words[2]\" {print \$1}" $mrd)) else - rep=( $manpath/(sman|man|cat)*/${~approx}$PREFIX${~star}$SUFFIX.*(:t) ) + rep=( $manpath/(sman|man|cat)*/*.*(:t) ) (($#mrd)) && rep[$#rep+1]=($(awk '{print $1}' $mrd)) fi @@ -43,5 +33,5 @@ # Remove any compression suffix, then remove the minimum possible string # beginning with .<->: that handles problem cases like files called # `POSIX.1.5'. -(( $#rep )) && _wanted manuals expl 'manual page' \ - compadd - ${${rep%%.(bz2|z|gz|Z)}%.<->*} +(( $#rep )) && rep=(${${rep%%.(bz2|z|gz|Z)}%.<->*}) && + _wanted manuals expl 'manual page' compadd -M "$_matcher" -a rep -- 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-05-31 15:46 ` Bart Schaefer @ 2001-05-31 17:20 ` Bart Schaefer 2001-06-01 11:40 ` Sven Wischnowsky 0 siblings, 1 reply; 14+ messages in thread From: Bart Schaefer @ 2001-05-31 17:20 UTC (permalink / raw) To: Andrej Borsenkow, zsh-workers [-- Attachment #1: Type: text/plain, Size: 936 bytes --] I wrote: } } This patch drops the filtering on man page name and instead slurps up all } the file basenames into the `rep' array, then passes that and the global } matcher spec to compadd to let it sort out the mess. If you have several } matchers this can get pretty slow, so it ought at least to cache `rep' } somewhere during the loop over the matchers; as it stands this is mostly } a proof of concept. Here's a better variation, which actually does cache the results for one pass around the matcher loop. It's quite a bit faster than with the patch from 14621, but still slower than the existing _man. The diff is bigger than the file, because of re-indentation, so I've just attached the entire file. -- 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 [-- Attachment #2: Text --] [-- Type: text/plain , Size: 1291 bytes --] #compdef man apropos whatis local rep expl mrd if [[ $service == man ]] && (( $words[(I)-l] + $words[(I)--local-file] )); then _files || return 0 fi if (( ! $#manpath )); then local mp mp=($(manpath 2>/dev/null)) [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} ) manpath=( $mp ) (( $#manpath )) || manpath=( ${(s.:.)$(manpath 2>/dev/null)} ) || manpath=( /usr/man(-/) /(opt|usr)/(dt|share|X11R6|local)/(cat|)man(-/) ) fi if (( _matcher_num < 2 )); then # `sman' is the SGML manual directory for Solaris 7. # 1M is system administrator commands on SVR4 mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N)) if [[ $words[2] = (<->*|1M|l|n) ]]; then rep=( $manpath/(sman|man|cat)${words[2]}/*.*(:t) ) (($#mrd)) && rep[$#rep+1]=($(awk "\$2 == \"$words[2]\" {print \$1}" $mrd)) else rep=( $manpath/(sman|man|cat)*/*.*(:t) ) (($#mrd)) && rep[$#rep+1]=($(awk '{print $1}' $mrd)) fi # Remove any compression suffix, then remove the minimum possible string # beginning with .<->: that handles problem cases like files called # `POSIX.1.5'. rep=(${${rep%%.(bz2|z|gz|Z)}%.<->*}) mrd=( ${(q)rep} ) eval "_man_cached() { rep=( $mrd ) }" else _man_cached fi (( $#rep )) && _wanted manuals expl 'manual page' compadd -M "$_matcher" -a rep ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-05-31 17:20 ` Bart Schaefer @ 2001-06-01 11:40 ` Sven Wischnowsky 2001-06-01 11:49 ` Sven Wischnowsky ` (2 more replies) 0 siblings, 3 replies; 14+ messages in thread From: Sven Wischnowsky @ 2001-06-01 11:40 UTC (permalink / raw) To: zsh-workers Bart Schaefer wrote: > I wrote: > } > } This patch drops the filtering on man page name and instead slurps up all > } the file basenames into the `rep' array, then passes that and the global > } matcher spec to compadd to let it sort out the mess. If you have several > } matchers this can get pretty slow, so it ought at least to cache `rep' > } somewhere during the loop over the matchers; as it stands this is mostly > } a proof of concept. > > Here's a better variation, which actually does cache the results for one > pass around the matcher loop. It's quite a bit faster than with the > patch from 14621, but still slower than the existing _man. I have one, too... This uses _path_files' builtin compfiles to try to get smarter glob patterns with respect to the matchers in use. It gives me acceptable speed but could still be improved, e.g. by caching the man dirs to use (using a hash with $words[2] as the key if it gives the section). These won't take up too much space and don't change that often (and we could compare $MANPATH to the one that was used when the dirs were cached, making it really safe). So, ... should we? How fast is it for you? Bye Sven #compdef man apropos whatis _man() { local dirs expl mrd awk if [[ $service == man ]] && (( $words[(I)-l] + $words[(I)--local-file] )); then _files || return 0 fi if (( ! $#manpath )); then local mp mp=($(manpath 2>/dev/null)) [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} ) manpath=( $mp ) fi (( $#manpath )) || manpath=( ${(s.:.)$(manpath 2>/dev/null)} ) || manpath=( /usr/man(-/) /(opt|usr)/(dt|share|X11R6|local)/(cat|)man(-/) ) # `sman' is the SGML manual directory for Solaris 7. # 1M is system administrator commands on SVR4 mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N)) if [[ $words[2] = (<->*|1M|l|n) ]]; then dirs=( $^manpath/(sman|man|cat)${words[2]}/ ) awk="\$2 == \"$words[2]\" {print \$1}" else dirs=( $^manpath/(sman|man|cat)*/ ) awk='{print $1}' fi _wanted manuals expl 'manual page' _man_pages } _man_pages() { local matcher pages dummy zparseopts -E M:=matcher if (( $#matcher )); then matcher="$matcher[2]" else matcher= fi pages=( $dirs ) compfiles -p pages '' '' "$matcher" '' dummy '*' pages=( $~pages(:t:r) ) (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd)) # Remove any compression suffix, then remove the minimum possible string # beginning with .<->: that handles problem cases like files called # `POSIX.1.5'. compadd "$@" - ${pages%.<->*} } _man "$@" -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 11:40 ` Sven Wischnowsky @ 2001-06-01 11:49 ` Sven Wischnowsky 2001-06-01 12:15 ` Clint Adams 2001-06-01 13:57 ` Bart Schaefer 2001-06-01 15:56 ` Bart Schaefer 2 siblings, 1 reply; 14+ messages in thread From: Sven Wischnowsky @ 2001-06-01 11:49 UTC (permalink / raw) To: zsh-workers I forgot to ask... _man uses `$^manpath/(sman|man|cat)*', why both `man' and `cat'? For people like me who have a pretty complete set of catman pages this makes every page be included twice. Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 11:49 ` Sven Wischnowsky @ 2001-06-01 12:15 ` Clint Adams 0 siblings, 0 replies; 14+ messages in thread From: Clint Adams @ 2001-06-01 12:15 UTC (permalink / raw) To: Sven Wischnowsky; +Cc: zsh-workers On Fri, Jun 01, 2001 at 01:49:36PM +0200, Sven Wischnowsky wrote: > I forgot to ask... > > _man uses `$^manpath/(sman|man|cat)*', why both `man' and `cat'? For > people like me who have a pretty complete set of catman pages this makes > every page be included twice. There are some systems that have preformatted catpages with no equivalent in nroff format. I'd imagine that this is why. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 11:40 ` Sven Wischnowsky 2001-06-01 11:49 ` Sven Wischnowsky @ 2001-06-01 13:57 ` Bart Schaefer 2001-06-01 14:20 ` Sven Wischnowsky 2001-06-01 15:56 ` Bart Schaefer 2 siblings, 1 reply; 14+ messages in thread From: Bart Schaefer @ 2001-06-01 13:57 UTC (permalink / raw) To: Sven Wischnowsky, zsh-workers On Jun 1, 1:40pm, Sven Wischnowsky wrote: } Subject: Re: _man igores global matchers } } Bart Schaefer wrote: } } This uses _path_files' builtin compfiles to try to get smarter glob } patterns with respect to the matchers in use. Except that it doesn't appear to reference the global $_matcher anywhere? How does "the matcher in use" ever get to _man_pages ? Perhaps this: } _wanted manuals expl 'manual page' _man_pages Should be: _wanted manuals expl 'manual page' _man_pages -M "$_matcher" ? Or am I missing something obvious? -- 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 13:57 ` Bart Schaefer @ 2001-06-01 14:20 ` Sven Wischnowsky 2001-06-01 15:46 ` Bart Schaefer 0 siblings, 1 reply; 14+ messages in thread From: Sven Wischnowsky @ 2001-06-01 14:20 UTC (permalink / raw) To: zsh-workers Bart Schaefer wrote: > On Jun 1, 1:40pm, Sven Wischnowsky wrote: > } Subject: Re: _man igores global matchers > } > } Bart Schaefer wrote: > } > } This uses _path_files' builtin compfiles to try to get smarter glob > } patterns with respect to the matchers in use. > > Except that it doesn't appear to reference the global $_matcher anywhere? > How does "the matcher in use" ever get to _man_pages ? > > Perhaps this: > > } _wanted manuals expl 'manual page' _man_pages > > Should be: > > _wanted manuals expl 'manual page' _man_pages -M "$_matcher" > > ? Or am I missing something obvious? It's added automatically in _description, called from _wanted. That's actually the main reason for putting that code into a separate function (that together with laziness). But now that you remind me... the expl array may contain more than one -M option, so the code that extracts the matchers should look like: zparseopts -E M+:=matcher if (( $#matcher )); then matcher=( ${matcher:#-M} ) matcher="$matcher" else matcher= fi Btw, I'm leaving till Wednesday now, so won't be able to commit this (or any changes for the disown stuff). Have fun... Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 14:20 ` Sven Wischnowsky @ 2001-06-01 15:46 ` Bart Schaefer 2001-06-06 9:37 ` PATCH: " Sven Wischnowsky 0 siblings, 1 reply; 14+ messages in thread From: Bart Schaefer @ 2001-06-01 15:46 UTC (permalink / raw) To: zsh-workers On Jun 1, 4:20pm, Sven Wischnowsky wrote: } Subject: Re: _man igores global matchers } } Bart Schaefer wrote: } } > Except that it doesn't appear to reference the global $_matcher anywhere? } } It's added automatically in _description, called from _wanted. Aha. I'd forgotten about that. That does mean that ANY command called via _wanted, _requested, et al. must be able to accept some subset of the compadd arguments, correct? That perhaps should be documented. -- 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* PATCH: Re: _man igores global matchers 2001-06-01 15:46 ` Bart Schaefer @ 2001-06-06 9:37 ` Sven Wischnowsky 0 siblings, 0 replies; 14+ messages in thread From: Sven Wischnowsky @ 2001-06-06 9:37 UTC (permalink / raw) To: zsh-workers Bart Schaefer wrote: > On Jun 1, 4:20pm, Sven Wischnowsky wrote: > } Subject: Re: _man igores global matchers > } > } Bart Schaefer wrote: > } > } > Except that it doesn't appear to reference the global $_matcher anywhere? > } > } It's added automatically in _description, called from _wanted. > > Aha. I'd forgotten about that. > > That does mean that ANY command called via _wanted, _requested, et al. > must be able to accept some subset of the compadd arguments, correct? > > That perhaps should be documented. Somehow I thought it were -- and it is, but only very indirectly, at the description of _all_labels. Hope this makes it clearer. I'm not sure if we should list the options that may be stored in expl. On one hand, it might be helpful, but if that set of options changes sometime, we might forget to update the lists in the docs... Bye Sven Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.127 diff -u -r1.127 compsys.yo --- Doc/Zsh/compsys.yo 2001/05/31 11:58:40 1.127 +++ Doc/Zsh/compsys.yo 2001/06/06 09:36:38 @@ -3834,6 +3834,9 @@ ... (( ret )) || break done) + +Note that this means that the var(command) has to accept the options +that have to be passed down to tt(compadd). ) findex(_retrieve_cache) item(tt(_retrieve_cache) var(cache_identifier))( @@ -4036,6 +4039,9 @@ the var(command). This is because tt(_wanted) also implements the loop over the tags, not just the one for the labels; conversely, it should not be called in the middle of a tt(_tags) loop. + +Note that, as for tt(_requested), the var(command) has to accept the options +that have to be passed down to tt(compadd). Like tt(_tags) this function supports the tt(-C) option to give a different name for the argument context field. -- Sven Wischnowsky wischnow@informatik.hu-berlin.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: _man igores global matchers 2001-06-01 11:40 ` Sven Wischnowsky 2001-06-01 11:49 ` Sven Wischnowsky 2001-06-01 13:57 ` Bart Schaefer @ 2001-06-01 15:56 ` Bart Schaefer 2 siblings, 0 replies; 14+ messages in thread From: Bart Schaefer @ 2001-06-01 15:56 UTC (permalink / raw) To: zsh-workers On Jun 1, 1:40pm, Sven Wischnowsky wrote: } } This uses _path_files' builtin compfiles to try to get smarter glob } patterns with respect to the matchers in use. This definitely appears to be the way to go. It's not as fast as caching all the man page basenames in a huge array, but it's quite a bit faster than globbing up that array in the first place. } It gives me acceptable speed but could still be improved, e.g. by } caching the man dirs to use (using a hash with $words[2] as the key if } it gives the section). I think it's actually good enough as is, but I know there are still people out there with slow disks and sub-200MHz CPUs, so ... -- 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2001-06-06 9:39 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-05-29 12:05 _man igores global matchers Andrej Borsenkow 2001-05-29 12:18 ` Sven Wischnowsky 2001-05-31 13:32 ` Andrej Borsenkow 2001-05-31 15:24 ` Sven Wischnowsky 2001-05-31 15:46 ` Bart Schaefer 2001-05-31 17:20 ` Bart Schaefer 2001-06-01 11:40 ` Sven Wischnowsky 2001-06-01 11:49 ` Sven Wischnowsky 2001-06-01 12:15 ` Clint Adams 2001-06-01 13:57 ` Bart Schaefer 2001-06-01 14:20 ` Sven Wischnowsky 2001-06-01 15:46 ` Bart Schaefer 2001-06-06 9:37 ` PATCH: " Sven Wischnowsky 2001-06-01 15:56 ` 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).