zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Improve _man file-path completion
@ 2020-01-04  0:12 dana
  2020-01-04  0:39 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: dana @ 2020-01-04  0:12 UTC (permalink / raw)
  To: Zsh hackers list

This has been annoying me for a little while. Since we glob for man pages with
_path_files, it's not possible to navigate through sub-directories when
completing file paths. Just using _files fixes that, but then when you have
separate-sections on you get like:

  % man /usr/local/l<TAB>
  completing manual page, section 1:
  lib/  libexec/  local/
  completing manual page, section 2:
  lib/  libexec/  local/
  completing manual page, section 3:
  lib/  libexec/  local/
  ...

Separating by-path pages into sections is nice, but the only way i can think
of to make it work well with directory navigation is to do the globbing
'manually' first and decide what to insert based on that, and that's a bigger
job. (But let me know if you have any better ideas)

dana


diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 41ae85a1f..d4cbbb9ba 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -376,7 +376,13 @@ _man() {
     return
   }
 
-  if zstyle -t ":completion:${curcontext}:manuals" separate-sections; then
+  # Don't separate sections when we're completing a file path. Otherwise, the
+  # user may see directories repeated a million times (once for each section)
+  # when navigating through the file system
+  if
+    [[ $PREFIX$SUFFIX != */* ]] &&
+    zstyle -t ":completion:${curcontext}:manuals" separate-sections
+  then
     local d ret=1
 
     (( $#sects )) || return 1
@@ -392,15 +398,9 @@ _man() {
       done
       (( ret )) || return 0
     done
-    ## To fall back to other sections' manpages when completing filenames, like
-    ## the 'else' codepath does:
-    #
-    # if (( ret )) && [[ $PREFIX$SUFFIX == */* ]]; then
-    #   sect_dirname=
-    #   _wanted manuals expl 'manual page' _man_pages && return
-    # fi
 
     return 1
+
   else
     sect_dirname=
     _wanted manuals expl 'manual page' _man_pages
@@ -414,14 +414,14 @@ _man_pages() {
   local suf='.((?|<->*|ntcl)(|.gz|.bz2|.z|.Z|.lzma))'
 
   if [[ $PREFIX$SUFFIX = */* ]]; 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.
+    # This can be used to glob for an individual section's pages, which is
+    # useful for separate-sections. But the effect is irritating when navigating
+    # through sub-directories; see above
     if [[ -n $sect_dirname ]]; then
-      _path_files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" "$expl[@]"
+      _files -g "*.*$sect_dirname*(|.gz|.bz2|.z|.Z|.lzma)" "$expl[@]"
     else
-      _path_files -g "*$suf" "$expl[@]" && return
-      _path_files "$expl[@]"
+      _files -g "*$suf" "$expl[@]" && return
+      _files "$expl[@]"
     fi
     return $?
   fi


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

end of thread, other threads:[~2020-01-04 12:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04  0:12 [PATCH] Improve _man file-path completion dana
2020-01-04  0:39 ` Daniel Shahaf
2020-01-04  1:17   ` dana
2020-01-04  1:46     ` Bart Schaefer
2020-01-04 12:46     ` Daniel Shahaf

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