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

* Re: [PATCH] Improve _man file-path completion
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2020-01-04  0:39 UTC (permalink / raw)
  To: dana; +Cc: Zsh hackers list

dana wrote on Fri, Jan 03, 2020 at 18:12:28 -0600:
> 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)

How about this (relative to master)?  It fixes your original problem but
retains the separate-sections behaviour for man pages specified by filename.

diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 41ae85a1f..bee7be410 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -381,8 +381,9 @@ _man() {
 
     (( $#sects )) || return 1
 
-    _tags manuals.${^sects}
+    _tags files manuals.${^sects}
     while _tags; do
+      _requested files expl "subdirectories" _files -/ && ret=0
       for sect_dirname in $sects; do
         d=$sect_dirname
         (( $+sect_descs[$d] )) && d+=" (${sect_descs[$d]})"

Aside:

    % compdef _f f
    % _f() _files -/
    % f Util/<TAB>
.
offers files, rather than nothing.  Bug?

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

* Re: [PATCH] Improve _man file-path completion
  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
  0 siblings, 2 replies; 5+ messages in thread
From: dana @ 2020-01-04  1:17 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh hackers list

On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> How about this (relative to master)?  It fixes your original problem but
> retains the separate-sections behaviour for man pages specified by filename.

Oh, that's much smarter, thank you.

I do see some minor issues with it:

* It creates a confusing inconsistency where it will automatically complete
  directories in the CWD, but not files (because files still need a / in the
  argument)

* It offers directories first, which i think will be annoying in the more
  common case of trying to complete a man page from the database/MANPATH

* It offers to complete paths unconditionally, which isn't actually supported
  by some man implementations/modes (OpenBSD requires -l for example). We were
  just assuming that the user knew what they were doing if they had a / in the
  argument, which i think is probably still sufficient

* Plural description

How about something like the following, then?

On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Aside:
>
>    % compdef _f f
>    % _f() _files -/
>    % f Util/<TAB>
> .
> offers files, rather than nothing.  Bug?

I seem to recall this being discussed before, and it isn't really a bug, but
we could change it if we decided to. Someone was complaining about it on IRC
just the other day. I think we'd simply need to remove *:all-files from
pats=(...)

dana


diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 41ae85a1f..7d55201e3 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -381,7 +381,12 @@ _man() {
 
     (( $#sects )) || return 1
 
-    _tags manuals.${^sects}
+    if [[ $PREFIX$SUFFIX == */* ]]; then
+      _tags manuals.${^sects} files
+    else
+      _tags manuals.${^sects}
+    fi
+
     while _tags; do
       for sect_dirname in $sects; do
         d=$sect_dirname
@@ -390,6 +395,8 @@ _man() {
         _requested manuals.$sect_dirname expl "manual page, section $d" _man_pages &&
             ret=0
       done
+      [[ $PREFIX$SUFFIX == */* ]] &&
+      _requested files expl directory _files -/ && ret=0
       (( ret )) || return 0
     done
     ## To fall back to other sections' manpages when completing filenames, like


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

* Re: [PATCH] Improve _man file-path completion
  2020-01-04  1:17   ` dana
@ 2020-01-04  1:46     ` Bart Schaefer
  2020-01-04 12:46     ` Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2020-01-04  1:46 UTC (permalink / raw)
  To: dana; +Cc: Daniel Shahaf, Zsh hackers list

On Fri, Jan 3, 2020 at 5:16 PM dana <dana@dana.is> wrote:
>
> On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > Aside:
> >
> >    % compdef _f f
> >    % _f() _files -/
> >    % f Util/<TAB>
> > .
> > offers files, rather than nothing.  Bug?
>
> I seem to recall this being discussed before, and it isn't really a bug, but
> we could change it if we decided to.

Yes, this was a design decision.  As I recall the conversation ended
up with something along the lines of "if the user has completed all
the way down the directory hierarchy, he probably expects to see
something at the end, rather than nothing."

I suspect this does make it somewhat more difficult than it should be
to create zstyles that display files and directories in separate
groups in a completion listing.

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

* Re: [PATCH] Improve _man file-path completion
  2020-01-04  1:17   ` dana
  2020-01-04  1:46     ` Bart Schaefer
@ 2020-01-04 12:46     ` Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2020-01-04 12:46 UTC (permalink / raw)
  To: zsh-workers

dana wrote on Fri, Jan 03, 2020 at 19:17:56 -0600:
> How about something like the following, then?

+1, thanks.

> On 3 Jan 2020, at 18:39, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > Aside:
> >
> >    % compdef _f f
> >    % _f() _files -/
> >    % f Util/<TAB>
> > .
> > offers files, rather than nothing.  Bug?
> 
> I seem to recall this being discussed before, and it isn't really a bug, but
> we could change it if we decided to. Someone was complaining about it on IRC
> just the other day. I think we'd simply need to remove *:all-files from
> pats=(...)

Well, it seems like a bug to me, given that -/ "specifies that only directories
should be completed".  If the completion function had wanted files to be
offered, it wouldn't have passed -/ in the first place.

*shrug*


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