zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: _info completion
@ 2002-05-12  7:11 Borsenkow Andrej
  2002-05-14  7:51 ` Sven Wischnowsky
  2002-05-14 16:20 ` Oliver Kiddle
  0 siblings, 2 replies; 6+ messages in thread
From: Borsenkow Andrej @ 2002-05-12  7:11 UTC (permalink / raw)
  To: Zsh hackers list

This is based on info-4.2 (the one I have); if you have earlier versions
please check if it works. It assumes that 'info -o - node1 ...' works;
without it completing (nested) menu items is more work than it's worth.

4 lines of parameter substitution is daunting but it tries to parse
three different line entry formats with on regexp and also account for
subtle differences in formatting I have encountered. Suggestions how to
simplify it are gratefully accepted :-)


I would be glad to here comments from our completion function gurus (I
am trying to learn how to write them properly). Specifcially how to use
tags with _describe (should it be _requested .. && _describe ...?).

-andrej

Index: Completion/Unix/Command/_info
===================================================================
RCS file: Completion/Unix/Command/_info
diff -N Completion/Unix/Command/_info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Command/_info	12 May 2002 07:03:52 -0000
@@ -0,0 +1,31 @@
+#compdef info
+
+local context state line expl ret=1
+typeset -A opt_args
+local info=${words[1]}
+
+_arguments -s \
+  '(: -)--apropos=[look up string in indices]:search string: ' \
+  '(-f --file -d --directory)'{-d,--directory=}'[add directory to infopath]:_files -/' \
+  '--dribble=[record keystrokes]:file with keystrokes:_files' \
+  '(-f --file -d --directory)'{-f,--file=}'[info file to show]:info file:_files -g "*.info(|.gz|.bz2)"' \
+  '(: - -h --help)'{-h,--help}'[display usage]' \
+  '(-o --output -O)--index-search=[go directly to node if found]:search string: ' \
+  '(--index-search -o --output -O)'{-o,--output=}'[dump selected nodes to filename]:filename:_files -g "*(^/)"' \
+  '(-R --raw-escapes)'{-R,--raw-escapes}'[do not remove ANSI escapes from man pages]' \
+  '--restore=[read keystrokes from file]:filename:_files -g "*(^/)"' \
+  '(--index-search -o --output -O --show-options --usage)'{-O,--show-options,--usage}'[go to command-line options node]' \
+  '--subnodes[recursively output menu items]' \
+  '--vi-keys[use Vi-like key bindings]' \
+  '(: -)--version[display version information]' \
+  '(--apropos -h --help -O --output --version)*::menu items:->item' && ret=0
+
+case $state in
+  item )
+    local -a items
+    items=(${${(M)${${(f)"$(${info} --output - ${(Q)words[1,CURRENT-1]} 2>/dev/null)"}[1,(r)[[:space:]]#--- The Detailed Node Listing ---[[:space:]]#]}:#\* *~\* Menu:*}:/(#b)\* ([^:]#):(#B)([[:space:]]##\(*\)[^.]#.[[:space:]]#|(|:)([[:space:]]##|(#e)))(#b)(*)/$match[1]:$match[2]})
+    _describe "menu item" items && ret=0
+  ;;
+esac
+
+return $ret


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

* Re: PATCH: _info completion
  2002-05-12  7:11 PATCH: _info completion Borsenkow Andrej
@ 2002-05-14  7:51 ` Sven Wischnowsky
  2002-05-14 16:20 ` Oliver Kiddle
  1 sibling, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 2002-05-14  7:51 UTC (permalink / raw)
  To: zsh-workers


Borsenkow Andrej wrote:

> ...
>
> This is based on info-4.2 (the one I have); if you have earlier versions
> please check if it works. It assumes that 'info -o - node1 ...' works;
> without it completing (nested) menu items is more work than it's worth.
> 
> 4 lines of parameter substitution is daunting but it tries to parse
> three different line entry formats with on regexp and also account for
> subtle differences in formatting I have encountered. Suggestions how to
> simplify it are gratefully accepted :-)

I haven't yet tried to work my way into it, but I give the crown for
the most fiendish substitution to you ;-)

> I would be glad to here comments from our completion function gurus (I
> am trying to learn how to write them properly). Specifcially how to use
> tags with _describe (should it be _requested .. && _describe ...?).

_describe has it's own tag handling. It normally uses the tag `values'
or (with the -o option) `options'. One can give it another tag as an
argument after the -t option: _describe -t foos.

I forgot to put that into the docs, it seems, below is a patch.


Bye
  Sven

Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.154
diff -u -r1.154 compsys.yo
--- Doc/Zsh/compsys.yo	8 May 2002 09:11:28 -0000	1.154
+++ Doc/Zsh/compsys.yo	14 May 2002 07:51:52 -0000
@@ -3616,7 +3616,7 @@
 the functions for the fields if they are called.
 )
 findex(_describe)
-item(tt(_describe) [ tt(-o) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)(
+item(tt(_describe) [ tt(-o) | tt(-t) var(tag) ] var(descr) var(name1) [ var(name2) ] var(opts) ... tt(-)tt(-) ...)(
 This function is useful for preparing a list of command options or
 arguments, together with their descriptions var(descr), as matches.
 Multiple groups separated by tt(-)tt(-) can be supplied, potentially with
@@ -3639,6 +3639,9 @@
 the tt(prefix-hidden), tt(prefix-needed) and tt(verbose) styles to find out
 if the strings should be added at all and if the descriptions should be
 shown.  Without the `tt(-o)' option, only the tt(verbose) style is used.
+With the tt(-t) option a var(tag) can be specified that should be used
+instead of the default `tt(values)' or, if the tt(-o) option is given,
+`tt(options)'.
 
 If selected by the tt(list-grouped) style, strings with the same
 description will be added in a way that they appear together in the list.

-- 
Sven Wischnowsky                          wischnow@berkom.de


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

* Re: PATCH: _info completion
  2002-05-12  7:11 PATCH: _info completion Borsenkow Andrej
  2002-05-14  7:51 ` Sven Wischnowsky
@ 2002-05-14 16:20 ` Oliver Kiddle
  2002-05-14 16:37   ` Borsenkow Andrej
  2002-05-23 14:42   ` Borsenkow Andrej
  1 sibling, 2 replies; 6+ messages in thread
From: Oliver Kiddle @ 2002-05-14 16:20 UTC (permalink / raw)
  To: Borsenkow Andrej; +Cc: Zsh hackers list

On Sun, May 12, 2002 at 11:11:44AM +0400, Borsenkow Andrej wrote:
> This is based on info-4.2 (the one I have); if you have earlier versions
> please check if it works. It assumes that 'info -o - node1 ...' works;
> without it completing (nested) menu items is more work than it's worth.

Works fine in info 4.1 too (though I rarely worry too much about
anything other than latest versions).

> 4 lines of parameter substitution is daunting but it tries to parse
> three different line entry formats with on regexp and also account for
> subtle differences in formatting I have encountered. Suggestions how to
> simplify it are gratefully accepted :-)

I'm impressed. I thought about doing this some while ago and decided
that it was just more hassle than it was worth, even with info -o.
I haven't yet tried to understand the substitution yet either.

I've got a few bits of other texinfo completions at home along with
some out-of-date but extensive tcsh completions so I'll dig those
out and get them fully working. For this reason, I suggest you
commit this under the name _texinfo so that we can put all the
texinfo commands in one function (as is our usual convention).
GNU distribute it all as one package named texinfo so it makes
sense to me.

> +local info=${words[1]}
and later:
> ... ${info} --output - ${(Q)words[1,CURRENT-1]} 2>/dev/null ...

This doesn't go too well when options like -f and -d are used
with info. _arguments is removing all the options from the words
array so they don't get passed on here (it does that in states).
I'd suggest setting $info to the full command before calling
_arguments.

I suppose you should also be using _call_program here too.

> +  '(-f --file -d --directory)'{-d,--directory=}'[add directory to infopath]:_files -/' \

You're missing the `directory' description on this line so it is
printing `_files -/' as a heading.

> +  '(: - -h --help)'{-h,--help}'[display usage]' \

Having specified `-' in the exclusion list, -h and --help are
superfluous. Not that they do any harm.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

* RE: PATCH: _info completion
  2002-05-14 16:20 ` Oliver Kiddle
@ 2002-05-14 16:37   ` Borsenkow Andrej
  2002-05-23 14:42   ` Borsenkow Andrej
  1 sibling, 0 replies; 6+ messages in thread
From: Borsenkow Andrej @ 2002-05-14 16:37 UTC (permalink / raw)
  To: 'Zsh hackers list'


 
> > 4 lines of parameter substitution is daunting but it tries to parse
> > three different line entry formats with on regexp and also account
for
> > subtle differences in formatting I have encountered. Suggestions how
to
> > simplify it are gratefully accepted :-)
> 
> I'm impressed. I thought about doing this some while ago and decided
> that it was just more hassle than it was worth, even with info -o.
> I haven't yet tried to understand the substitution yet either.
> 

Actually it is quite simple. It takes info -o - output, cuts off
evrything after "--- Detailed Node Listing ---" (which sometimes has
spaces around sometimes not) then gets all lines "* xxx" except "*
Menu:" and then tries to extract node names and descriptions, where
lines match one of

* Node: (file)section. Description   - top level dir
* Node:: Description                 - normal menu
* Node: section                      - index

(I think listing sections for index entries makes sense; if not it can
already be simplified :-) 

nothing really exciting.

-andrej


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

* RE: PATCH: _info completion
  2002-05-14 16:20 ` Oliver Kiddle
  2002-05-14 16:37   ` Borsenkow Andrej
@ 2002-05-23 14:42   ` Borsenkow Andrej
  2002-05-28 14:16     ` Oliver Kiddle
  1 sibling, 1 reply; 6+ messages in thread
From: Borsenkow Andrej @ 2002-05-23 14:42 UTC (permalink / raw)
  To: 'Zsh hackers list'


> I've got a few bits of other texinfo completions at home along with
> some out-of-date but extensive tcsh completions so I'll dig those
> out and get them fully working. For this reason, I suggest you
> commit this under the name _texinfo so that we can put all the
> texinfo commands in one function (as is our usual convention).
> GNU distribute it all as one package named texinfo so it makes
> sense to me.
> 

Commited as _texinfo. God knows I tried to simplify a pattern but could
not. Oliver, if you will add to this file you probably could polish it a
bit as well - thank you.

-andrej


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

* Re: PATCH: _info completion
  2002-05-23 14:42   ` Borsenkow Andrej
@ 2002-05-28 14:16     ` Oliver Kiddle
  0 siblings, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2002-05-28 14:16 UTC (permalink / raw)
  To: Borsenkow Andrej; +Cc: 'Zsh hackers list'

On 23 May, Andrej wrote:

> Commited as _texinfo. God knows I tried to simplify a pattern but could
> not. Oliver, if you will add to this file you probably could polish it a
> bit as well - thank you.

Below is an updated _texinfo with support for install-info, makeinfo,
texi2dvi and texindex added. I've not got around to look at polishing
the info stuff and in fact I still need to look over the rest of this 
more thoroughly. I also intended to add handling for tkinfo.

Being pedantic, info completion should also complete man pages because
the info reader will display man pages but I wouldn't worry unless
anyone claims to actually use it to read man pages.

Oliver

#compdef info install-info makeinfo texi2dvi texindex

local curcontext="$curcontext" state line ret=1

case $service in
  info)
    local -A opt_args
    local -a info
    info=(_call_program info ${words[1]})

    _arguments -C -s \
      '(: -)--apropos=[look up string in indices]:search string: ' \
      '(-f --file)'{\*-d,\*--directory=}'[add directory to infopath]:info dir:_files -/' \
      '--dribble=[record keystrokes]:file with keystrokes:_files' \
      '(-f --file -d --directory)'{-f,--file=}'[info file to show]:info file:_files -g "*.info(|.gz|.bz2)"' \
      '(: - -h --help)'{-h,--help}'[display usage]' \
      '(-o --output -O)--index-search=[go directly to node if found]:search string: ' \
      '(--index-search -o --output -O)'{-o,--output=}'[dump selected nodes to filename]:filename:_files -g "*(^/)"' \
      '(-R --raw-escapes)'{-R,--raw-escapes}'[do not remove ANSI escapes from man pages]' \
      '--restore=[read keystrokes from file]:filename:_files -g "*(^/)"' \
      '(--index-search -o --output -O --show-options --usage)'{-O,--show-options,--usage}'[go to command-line options node]' \
      '--subnodes[recursively output menu items]' \
      '--vi-keys[use Vi-like key bindings]' \
      '(: -)--version[display version information]' \
      '(--apropos -h --help -O --output --version)*::menu items:->item' && ret=0
  ;;
  install-info)
    if _pick_variant debian=Debian gnu --version; then
      _arguments -S \
        '(* -)--help[display help information]' \
        '(* -)--version[display version information]' \
        '(--maxwidth --align --calign)--remove[delete existing entries]' \
        '(--maxwidth --align --calign)--remove-exactly[delete existing entries taking exact entry name]' \
        '--section[specify section to add entry in]:regexp::title' \
        '--infodir=[specify directory containing dir file]:info directory:_files -/' \
        '--align=[specify minimum indentation for description]:indentation' \
        '--calign=[specify minimum indentation for continuation lines of description]:indentation' \
        '--maxwidth=[specify maximim width of dir file]:width' \
        '--quiet[suppress informational output]' \
        '--description=[specify description for menu entry]:description' \
        '--menuentry=[specify the menu entry for dir file]:menu entry' \
        '--keep-old=[inhibit replacement of existing entries/removal of empty sections]' \
        '--test[do not update dir file]' \
        '--debug[enable debugging]' \
        '*:info file:_files -g \*.info'
	return
    else
      _arguments \
        '(--delete --remove)'{--delete,--remove}'[delete existing entries]' \
        '(2)--dir-file=[specify dir file]:dir file:_files -g dir' \
        \*{--entry,--info}'[specify directory entry to add]:text' \
        '(- 1 2)--help[display help information]' \
        '(1)--info-file=[specify info file to install in the directory]:info file:_files -g *.info' \
        '(2)--info-dir=[specify directory containing dir file]:info directory:_files -/' \
        '--quiet[suppress warnings]' \
        '(--delete --remove)--section=[put new entries in specified section]' \
        '(- 1 2)--version[display version information]' \
        '1:info file:_files -g \*.info' \
        '2:dir file:_files -g dir'
	return
    fi
  ;;
  makeinfo)
    _arguments -s \
      '--error-limit=[specify number of errors to quit after]:number' \
      '--force[preserve output even if errors]' \
      '(* -)--help[display help]' \
      '--no-validate[suppress node cross-reference validation]' \
      '--no-warn[suppress warnings]' \
      '--reference-limit=[warn about at most specified number of references]:number' \
      '(-v --verbose)'{-v,--verbose}'[explain what is being done]' \
      '(* -)--version[display version info]' \
      '(--html --xml)--docbook[output in DocBook format]' \
      '(--docbook --xml)--html[output in HTML format]' \
      '--no-headers[suppress node separators and menus]' \
      '(--docbook --html)--xml[output in XML (TexinfoML) format]' \
      '(-E --macro-expand)'{-E,--macro-expand}'[output macro-expanded source to specified file]:file:_files' \
      '(--docbook --xml)--no-split[suppress splitting of output]' \
      '--number-sections[output chapter and section numbers]' \
      '(-o --output=)'{-o,--output}'[specify output file]:output file:_files' \
      '(--docbook --html --xml)--enable-encoding[output special characters]' \
      '(--docbook --html --xml)--fill-column=[specify width to break lines at]:width' \
      '(--docbook --html --xml)--footnote-style=[specify style for output of footnotes]:((separate\:in\ own\ node end\:at\ end\ of\ node))' \
      '(--docbook --html --xml)--paragraph-indent=[specify spaces to indent paragraphs by]' \
      '(--docbook --html --xml)--split-size=[split Info files at specified size]:size' \
      '--commands-in-node-names[allow @ commands in node names]' \
      '-D[define variable]:variable' \
      '-I[specify directory to append to @include search path]:directory:_files -/' \
      '-P[specify directory to prepend to @include search path]:directory:_files -/' \
      '-U[undefine variable]:variable' \
      '(--html --no-ifhtml)--ifhtml[process @ifhtml and @html when not generating HTML]' \
      '(--no-ifinfo)--ifinfo[process @ifinfo even when not generating Info]' \
      '(--no-iftex)--iftex[process @iftex and @tex text]' \
      '(--no-ifplaintext)--ifplaintext[process @ifplaintext even when not generating plain text]' \
      '(--ifhtml)--no-ifhtml[do not process @ifhtml and @html text]' \
      '(--ifinfo)--no-ifinfo[do not process @ifinfo text]' \
      '(--ifplaintext)--no-ifplaintext[do not process @ifplaintext text]' \
      '(--iftex)--no-iftex[do not process @iftex and @tex text]' \
      '*:texinfo file:_texi'
      return
  ;;
  texi2dvi)
    _arguments -s \
      '(-b --batch)'{-b,--batch}'[no interaction]' \
      '(-c --clean)'{-c,--clean}'[remove all auxiliary files]' \
      '(-D --debug)'{-D,--debug}'[turn on shell debugging (set -x)]' \
      '(- *)'{-h,--help}'[display help information]' \
      '(-o --output)'{-o,--output=}'[specify output file]:output file:_files' \
      '(-q -s --quiet --silent -V --verbose)'{-q,-s,--silent,--quiet}'[no output except errors]' \
      '(-q -s --quiet --silent -V --verbose)'{-V,--verbose}'[report on what is done]' \
      '(- *)'{-v,--version}'[display version information]' \
      '-@[use @input instead of \input; for preloaded Texinfo]' \
      '(-e --expand)'{-e,--expand}'[force macro expansion using makeinfo]' \
      '-I[specify search dir for texinfo files]:directory:_files -/' \
      '(-l --language)'{-l,--language}'[specify language of input file]:language:(LaTeX Texinfo)' \
      '(-p --pdf)'{-p,--pdf}'[use pdftex or pdflatex for processing]' \
      \*{-t,--texinfo}'[specify command to insert after @setfilename]:command' \
      '*:file:_texi'
      return
  ;;
  texindex)
    _arguments \
      '(* -)--help[display help]' \
      '(* -)--version[display version info]' \
      '(--no-keep)--keep[keep temporary files around after processing]' \
      '(--keep)--no-keep[do not keep temporary files (default)]' \
      '(-o --output)'{-o,--output=}'[specify output file]:file:_files' \
      '*:texinfo file:_texi'
      return
  ;;
esac

case $state in
  item )
    local -a items

    info=($info ${(kv)opt_args[(I)(-d|--directory|-f|--file)]})

    items=(${${(M)${${(f)"$(${info} --output - ${words[1,CURRENT-1]} 2>/dev/null)"}[1,(r)[[:space:]]#--- The Detailed Node Listing ---[[:space:]]#]}:#\* *~\* Menu:*}:/(#b)\*[[:space:]]##([^:]##):(#B)( \(?##\)[^.]#.|(:|))[[:space:]]#(#b)(*)[[:space:]]#/$match[1]${match[2]:+:}$match[2]})

    _describe -t items "menu items" items && ret=0
  ;;
esac

return ret

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

end of thread, other threads:[~2002-05-28 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-12  7:11 PATCH: _info completion Borsenkow Andrej
2002-05-14  7:51 ` Sven Wischnowsky
2002-05-14 16:20 ` Oliver Kiddle
2002-05-14 16:37   ` Borsenkow Andrej
2002-05-23 14:42   ` Borsenkow Andrej
2002-05-28 14:16     ` Oliver Kiddle

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