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

[PATCH] _man: Support subsection names such as '3p'



On my system I have a /usr/share/man/man3/memcpy.3posix.gz man page.  It can be
viewed by 'man 3p memcpy', where the section name argument can be any prefix of
the "3posix" segment.  (The Perl man pages on this system use a similar naming
convention, *.3perl.gz)

These patches make 'man 3p memcp<TAB>' work.

_man used $sect as a loop variable, stomping on its previous value.  The first
patch stops stomping on the previous value, but introduces no functional
change.  The second patch uses the unstomped value and fixes the issue.

Cheers,

Daniel

>From 5c9a3bbc1a380b45d0db340109ce5477984d43aa Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Jan 2016 15:34:57 +0000
Subject: [PATCH 1/2] _man: Disentangle a local variable that had two distinct semantics.  No functional change

---
 Completion/Unix/Command/_man | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 81ac40b..871af48 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -37,7 +37,10 @@ _man() {
 
   mrd=(${^_manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N))
 
-  local sect
+  # $sect is from the command line, the "3p" in "man 3p memcpy"
+  # $sect_dirname is from the filesystem, the "3" in "/usr/share/man/man3"
+  # These are used by _man_pages
+  local sect sect_dirname
   if [[ $OSTYPE = solaris* ]]; then
     sect=${${words[(R)-s*]#-s}:-$words[$words[(i)-s]+1]}
   elif [[ -n ${sect:=$words[$words[(i)-S]+1]} || -n ${sect:=$MANSECT} ]]; then
@@ -69,8 +72,8 @@ _man() {
 
     _tags manuals.${^sects}
     while _tags; do
-      for sect in $sects; do
-        _requested manuals.$sect expl "manual page, section $sect" _man_pages &&
+      for sect_dirname in $sects; do
+        _requested manuals.$sect_dirname expl "manual page, section $sect_dirname" _man_pages &&
             ret=0
       done
       (( ret )) || return 0
@@ -78,7 +81,7 @@ _man() {
 
     return 1
   else
-    sect=
+    sect_dirname=
     _wanted manuals expl 'manual page' _man_pages
   fi
 }
@@ -107,8 +110,8 @@ _man_pages() {
     matcher=
   fi
 
-  pages=( ${(M)dirs:#*$sect/} )
-  compfiles -p pages '' '' "$matcher" '' dummy '*'
+  pages=( ${(M)dirs:#*$sect_dirname/} )
+  compfiles -p pages '' '' "$matcher" '' dummy "*"
   pages=( ${^~pages}(N:t) )
 
   (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd))
@@ -119,11 +122,11 @@ _man_pages() {
 
   [[ $OSTYPE = solaris* ]] && sopt='-s '
   if ((CURRENT > 2)) ||
-      ! zstyle -t ":completion:${curcontext}:manuals.$sect" insert-sections
+      ! zstyle -t ":completion:${curcontext}:manuals.$sect_dirname" insert-sections
   then
     compadd "$@" - ${pages%$~suf}
   else
-    compadd "$@" -P "$sopt$sect " - ${pages%$~suf}
+    compadd "$@" -P "$sopt$sect_dirname " - ${pages%$~suf}
   fi
 }
 
-- 
2.1.4

>From 8200c0c736076f7aaed99a1b7102287a5af9de5a Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Jan 2016 15:37:43 +0000
Subject: [PATCH 2/2] _man: Support subsection names such as '3p'.

---
 Completion/Unix/Command/_man | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 871af48..0534db7 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -52,7 +52,7 @@ _man() {
   fi
 
   if [[ $sect = (<->*|1M|l|n) || $sect = \(*\|*\) ]]; then
-    dirs=( $^_manpath/(sman|man|cat)${~sect}/ )
+    dirs=( $^_manpath/(sman|man|cat)${~sect%%[^0-9]#}/ )
     awk="\$2 == \"$sect\" {print \$1}"
   else
     dirs=( $^_manpath/(sman|man|cat)*/ )
@@ -111,7 +111,7 @@ _man_pages() {
   fi
 
   pages=( ${(M)dirs:#*$sect_dirname/} )
-  compfiles -p pages '' '' "$matcher" '' dummy "*"
+  compfiles -p pages '' '' "$matcher" '' dummy "*${(b)sect}*"
   pages=( ${^~pages}(N:t) )
 
   (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd))
-- 
2.1.4



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