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

Re: man page completion (was Re: Few newbie questions..)



Ages ago, Oliver Kiddle wrote:

> ...
> 
> Having the section number visible is a useful idea which I'd also like.
> Putting it in the actual match is not ideal though. It would be better
> to have the section number in a description or to group different
> sections separately under different headings.
> 
> I expect some people would prefer not to have this separate grouping.
> `zstyle ':completion:*:man.*' group-name manual' might group them all
> together but you would then still get separate headings for each group
> and I'm not sure if it is possible to replace them with one. It would
> also allow other things like use of the tag-order style.

I seem to have missed this, otherwise I'd have implemented it.  Here
is a patch, using a new style `separate-sections' to select if the
sections should be added separately at all. Defaults to `false' for
backward compatibility. Hence I'm going to commit this.

Bye
  Sven

Index: Completion/Unix/Command/_man
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_man,v
retrieving revision 1.4
diff -u -r1.4 _man
--- Completion/Unix/Command/_man	2001/08/21 18:06:25	1.4
+++ Completion/Unix/Command/_man	2002/01/10 10:54:52
@@ -40,8 +40,28 @@
     dirs=( $^manpath/(sman|man|cat)*/ )
     awk='{print $1}'
   fi
+  if zstyle -t ":completion:${curcontext}:manuals" separate-sections; then
+    typeset -U sects
+    local ret=1
 
-  _wanted manuals expl 'manual page' _man_pages
+    sects=( ${(o)${dirs##*(man|cat)}%/} )
+
+    (( $#sects )) || return 1
+
+    _tags manuals.${^sects}
+    while _tags; do
+      for sect in $sects; do
+        _requested manuals.$sect expl "manual page, section $sect" _man_pages &&
+            ret=0
+      done
+      (( ret )) || return 0
+    done
+
+    return 1
+  else
+    sect=
+    _wanted manuals expl 'manual page' _man_pages
+  fi
 }
 
 _man_pages() {
@@ -56,7 +76,7 @@
     matcher=
   fi
 
-  pages=( $dirs )
+  pages=( ${(M)dirs:#*$sect/} )
   compfiles -p pages '' '' "$matcher" '' dummy '*'
   pages=( ${^~pages}(N:t:r) )
 
Index: Completion/Zsh/Command/_zstyle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v
retrieving revision 1.5
diff -u -r1.5 _zstyle
--- Completion/Zsh/Command/_zstyle	2002/01/04 12:09:31	1.5
+++ Completion/Zsh/Command/_zstyle	2002/01/10 10:54:53
@@ -100,6 +100,7 @@
   remove-all-dups	 c:bool
   select-prompt          c:
   select-scroll          c:
+  separate-sections      c:bool
   single-ignored         c:single-ignored
   sort			 c:bool
   special-dirs		 c:sdirs
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.138
diff -u -r1.138 compsys.yo
--- Doc/Zsh/compsys.yo	2002/01/04 12:09:31	1.138
+++ Doc/Zsh/compsys.yo	2002/01/10 10:54:53
@@ -1971,6 +1971,15 @@
 that number (or plus the number, since it is negative).  The default is to
 scroll by single lines.
 )
+kindex(separate-sections, completion style)
+item(tt(separate-sections))(
+This style is used with the tt(manuals) tag when completing names of
+manual pages.  If it is `true', entries for different sections are
+added separately using tag names of the form `tt(manual.)var(X)',
+where var(X) is the section number.  This means that it is possible to
+make pages from different sections be listed separately by setting the
+tt(group-name) style.  The default for this style is `false'.
+)
 kindex(single-ignored, completion style)
 item(tt(single-ignored))(
 This is used by the tt(_ignored) completer.  It specifies what

-- 
Sven Wischnowsky                           wischnow@xxxxxxxxx



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