From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24378 invoked by alias); 15 Jun 2018 13:59:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43018 Received: (qmail 25662 invoked by uid 1010); 15 Jun 2018 13:59:09 -0000 X-Qmail-Scanner-Diagnostics: from mail-io0-f196.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.223.196):SA:0(-1.9/5.0):. Processed in 1.673114 secs); 15 Jun 2018 13:59:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qRPvmumhY2fNUjTGOMQ90sOqPcwYEBIJhfB94F4dlz0=; b=UAAYgD9Pkh1tfHtz4FUkX3YQsdMcVFreHTWQk3rjaRoJ+bYKrRNtPGTTypzUBfkUJA /jy++m3fgnNEiBkHYZXBQcI1V7KphaGdKAmcCtualqwJtkXCSuTedhyODCGc/cZBdZ3v r3IiqYqPfBkarVeM9UYE2+sz/t3Dvjsud9F3ywNozSiTIaujm4+JpkGR6eI+uM1a75Tn kaYpAVtFsNxjw+e0XJg+vS5tm6+u7ZNY89z4Rb2Fz5O0bCnNb3pA7LjA8W+0enb+W0Uc bKkFP/WdlWu2XwW+NtNer6aii9mcChoT2mlPeAnxRMRO8ToRNRMBGBm/CDtjwK097mCY qC2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qRPvmumhY2fNUjTGOMQ90sOqPcwYEBIJhfB94F4dlz0=; b=Lcoq0DieJCqfRwjJovyMqcGPbY5uOLwhXUqQw66TWwvw/fMOcGG2+gPTh1RhqKseYo YDyLpfhlTmuInn+pfucSLrkhJ5eO978QgVKWw674pk85AeBIkW5AcexhT0sPnYWga0Zw QIgNqV8BVZPADt8bAV52KBaLqUL1skH5DdvHmMkE050zXdbe+NUCzLlsBgbFss5RopJy J8w2FjGT/LFI/CwZo24UveOBXjq7DcYnbnDqddVAmQTr7p5X02ZPuwBwu4HZqbjQFdPA x5UJcVeZ2bOc90wnsEfExvgop75Tgo696i9zf+7fG+xC6Se3ApLIGY8MWXUAPdLtrAkX x+gQ== X-Gm-Message-State: APt69E24DeRI9soOHa6mI2eybdhY6zjQfOsbg6oc5l5wOA+8Qsx7ytWR HwxVebKmmZa3EBRWDl4J8dfU7g== X-Google-Smtp-Source: ADUXVKJmkJ/lF7jCwnxP2qJHNb1eclWDnMaxFkscjJLQBUbL3ljyLew6G8JrfnJUveL04msK9Smvag== X-Received: by 2002:a5e:8806:: with SMTP id l6-v6mr1684135ioj.9.1529071144789; Fri, 15 Jun 2018 06:59:04 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: [PATCH] Completion: Improve _man (3) From: dana In-Reply-To: Date: Fri, 15 Jun 2018 08:59:03 -0500 Cc: Zsh workers Content-Transfer-Encoding: quoted-printable Message-Id: <53F42356-22E5-453F-9A61-25E71AFAC3BF@dana.is> References: <9B2A476B-3C9F-4757-9818-4815A9417253@dana.is> <17923.1528636054@thecus> <2BD8008C-D6F4-4B4A-AF05-7EE80ADB0E47@dana.is> <20180614095001.v33idyjczkouva6n@tarpaulin.shahaf.local2> To: Daniel Shahaf X-Mailer: Apple Mail (2.3445.6.18) Round 3, i suppose: * Re-add the partial section-name matching functionality that Daniel = mentioned * More accurately determine whether an initial operand could be a = section name * Support .z compression extension (per man-db) * Add some more documentation Daniel (or anyone), if you have time, could you see if this works as = you'd expect? dana diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man index 11c2fab7f..10395de0e 100644 --- a/Completion/Unix/Command/_man +++ b/Completion/Unix/Command/_man @@ -4,6 +4,11 @@ # - Solaris is seemingly the only OS that doesn't allow the `man n = page` syntax; # you must use `man -s n page` # - We assume that Linux distributions are using either man-db or = mandoc +# - @todo Would be nice to support completing the initial operand as a = section +# name (on non-Solaris systems) +# - @todo We don't support the man-db syntax .
(e.g., = `ls.1`) +# - @todo We don't support the man-db feature of 'sub-pages' =E2=80=94 = that is, treating +# pairs of operands like `git diff` as `git-diff` # - @todo Option exclusivity isn't super accurate # - @todo Solaris man accepts a single hyphen as the first option to = disable # paging (like AIX's -c); we don't support that @@ -220,7 +225,15 @@ _man() { elif [[ $variant =3D=3D (dragonfly|freebsd)* ]] && (( $+opt_args[-S] = )); then noinsert=3D1 sect=3D${opt_args[-S]//:/|} - elif (( CURRENT > 1 )) && [[ $variant !=3D solaris* ]]; then + # It's only a small help, but, per man-db, we can avoid treating an = initial + # operand like `8139too` as a section name by ensuring that only the = first + # character is a digit. This doesn't do much for stuff like `2to3`, = but we can + # at least special-case a few common patterns for now + elif + (( CURRENT > 1 )) && + [[ $variant !=3D solaris* ]] && + [[ ${${(Q)words[1]}##(2to3|7z)*} =3D=3D = ([0-9](|[^0-9[:punct:]]*)|[lnopx]) ]] + then noinsert=3D1 sect=3D$words[1] elif [[ -n ${sect:=3D$MANSECT} ]]; then @@ -231,8 +244,24 @@ _man() { sect=3D${(Q)sect} =20 if [[ $sect =3D (<->*|[lnopx]) || $sect =3D *\|* ]]; then - sects=3D( ${(s.|.)sect} ) - dirs=3D( $^_manpath/(sman|man|cat)${^sects}(|.*)/ ) + # Most man implementations support partial matching of a page's + # (sub-)section name =E2=80=94 e.g., `3per` for `3perl`. The = (sub-)section name may + # or may not correspond to the directory name (most systems combine + # sub-sections), but we'll assume that if it starts with a number = and we're + # not on Solaris (which doesn't support this feature at all) that = we can do + # a match against the leading number. This is irritating if you DO = want the + # exact sub-section specified, but unfortunately there's no way to = determine + # this programmatically =E2=80=94 i guess we could add a style to = control it + () for 1 { + if [[ $OSTYPE =3D=3D solaris* || $1 !=3D <->* ]]; then + sects+=3D( $1 ) + dirs+=3D( $^_manpath/(sman|man|cat)$1(|.*)/ ) + else + sects+=3D( ${1%%[^0-9]#} ) + dirs+=3D( $^_manpath/(sman|man|cat)${1%%[^0-9]#}*/ ) + fi + } ${(s.|.)sect} + sect=3D${(j<|>)sects} [[ $sect =3D=3D *'|'* ]] && sect=3D"($sect)" awk=3D"\$2 =3D=3D \"$sect\" {print \$1}" @@ -281,7 +310,7 @@ _man() { 8 'maintenance commands and procedures' 9 'kernel features' 9lua 'Lua kernel bindings' # NetBSD - l 'local documentation' # AIX, etc. + l 'local documentation' # AIX, etc. =E2=80=94 TCL on some = systems? n 'new documentation' # AIX, etc. o 'old documentation' # AIX, etc. p 'public documentation' # AIX, etc. @@ -380,14 +409,14 @@ _man_pages() { local pages sopt =20 # What files corresponding to manual pages can end in. - local suf=3D'.((?|<->*|ntcl)(|.gz|.bz2|.Z|.lzma))' + local suf=3D'.((?|<->*|ntcl)(|.gz|.bz2|.z|.Z|.lzma))' =20 if [[ $PREFIX$SUFFIX =3D */* ]]; then # Easy way to test for versions of man that allow file names. # This can't be a normal man page reference. # Try to complete by glob first. if [[ -n $sect_dirname ]]; then - _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.Z|.lzma)" "$expl[@]" + _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" = "$expl[@]" else _path_files -g "*$suf" "$expl[@]" && return _path_files "$expl[@]"