zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: completion after ../
@ 2000-02-18  9:39 Sven Wischnowsky
  2000-02-20 12:17 ` Tanaka Akira
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 2000-02-18  9:39 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> > Or maybe we write a completer (a real, top-level completer) that
> > registers a post-completion function which checks if there are only
> > alternate matches (or only one alternate match) and no normal one and, 
> > if this is the case, makes a list be shown instead of the match(es) be 
> > used. That would be quite easy (set compstate[insert]='',
> > compstate[list]='list force'), , but I'm not sure if this is enough or 
> > the right thing at all.
> 
> I tried this and I found it's enough for me.  Of course, I agree that
> it's quite inconsistent behaviour and it shouldn't be default.
> 
> So I want to insert following fragment at last in _main_complete.
> 
> if zstyle -b ":completion:..." &&
>    [[ $compstate[old_list] != shown &&
>       $compstate[nmatches] = 0 &&
>       $compstate[alternate_nmatches] = 1 ]]; then
>   compstate[insert]=''
>   compstate[list]='list force'
> fi
> 
> What's a proper context and a style?  I couldn't find them.

(Btw. testing for the truth value of a style is done with -t (default
if style is unset: false) or -T (default: true).)

Well, I'd suggest the normal context with an empty tag as in
":completion:${curcontext}:". I have problems finding a good style
name myself (`show-only-list-if-only-one-alternate-match-and-no-normal-one'
is probably a tiny bit too long). Hm. Maybe something like
`show-single-alternate' or, probably better, `show-single-ignored'
(because they `come' from styles named like `ignored-patterns').

Or we name it `single-ignored' (yes, there must be a better name) and
enhace it: if it's set to `show' we use the above. If it's set to
`menu' we also add the string from the line in the alternate set (as
usual, with -S '', in it's own group, with a call to _description and
so on...) and start menu-completion (compstate[insert]=menu).

We should also do that before the test in line 83 which I changed some 
days ago so that the user-requested menu-style (especially if (s)he
selected menu-selection) is respected (and the test in line 83 should
be changed to make it be used if the style we are talking about is set 
to `menu' -- but not in normal completion if there is no or only one
match).


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: Re: completion after ../
  2000-02-18  9:39 PATCH: Re: completion after ../ Sven Wischnowsky
@ 2000-02-20 12:17 ` Tanaka Akira
  0 siblings, 0 replies; 7+ messages in thread
From: Tanaka Akira @ 2000-02-20 12:17 UTC (permalink / raw)
  To: zsh-workers

In article <200002180939.KAA30810@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Or we name it `single-ignored' (yes, there must be a better name) and
> enhace it: if it's set to `show' we use the above. If it's set to
> `menu' we also add the string from the line in the alternate set (as
> usual, with -S '', in it's own group, with a call to _description and
> so on...) and start menu-completion (compstate[insert]=menu).

I tried this.  I inserted the following fragment just before line 83
in _main_complete.

if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
   [[ $compstate[old_list] != shown &&
      $compstate[nmatches] = 0 &&
      $compstate[alternate_nmatches] = 1 ]]; then
  case "$tmp" in
  show) compstate[insert]='' compstate[list]='list force';;
  menu) compstate[insert]='menu';;
  esac
  tmp=false
  [[ $tmp = menu ]] && tmp=true
else
  tmp=false
fi

if [[ $compstate[nmatches] -gt 1 ]] || $tmp; then
...

But I couldn't find the way to get the string from the alternate set.
So, it completes a word with a following space and the next <TAB>
completes a next word.

How can we get the string?
-- 
Tanaka Akira


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

* Re: PATCH: Re: completion after ../
@ 2000-02-21  9:28 Sven Wischnowsky
  0 siblings, 0 replies; 7+ messages in thread
From: Sven Wischnowsky @ 2000-02-21  9:28 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> In article <200002180939.KAA30810@beta.informatik.hu-berlin.de>,
>   Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 
> > Or we name it `single-ignored' (yes, there must be a better name) and
> > enhace it: if it's set to `show' we use the above. If it's set to
> > `menu' we also add the string from the line in the alternate set (as
> > usual, with -S '', in it's own group, with a call to _description and
> > so on...) and start menu-completion (compstate[insert]=menu).
> 
> I tried this.  I inserted the following fragment just before line 83
> in _main_complete.
> 
> if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
>    [[ $compstate[old_list] != shown &&
>       $compstate[nmatches] = 0 &&
>       $compstate[alternate_nmatches] = 1 ]]; then
>   case "$tmp" in
>   show) compstate[insert]='' compstate[list]='list force';;
>   menu) compstate[insert]='menu';;
>   esac
>   tmp=false
>   [[ $tmp = menu ]] && tmp=true
> else
>   tmp=false
> fi
> 
> if [[ $compstate[nmatches] -gt 1 ]] || $tmp; then
> ...
> 
> But I couldn't find the way to get the string from the alternate set.
> So, it completes a word with a following space and the next <TAB>
> completes a next word.
> 
> How can we get the string?

I thought about something like the thing below, using the -a option to
compadd to put the original in the alternate set.

Note: no change to _zstyle and no doc, this is mostly Tanaka's code
turned into a patch for everybodys convenience. Also, I'm not sure how 
to write that in the manual -- it's certainly one of the more obscure
styles.


Bye
 Sven

diff -ru ../z.old/Completion/Core/_main_complete Completion/Core/_main_complete
--- ../z.old/Completion/Core/_main_complete	Fri Feb 18 15:42:41 2000
+++ Completion/Core/_main_complete	Mon Feb 21 10:24:49 2000
@@ -19,7 +19,7 @@
 setopt localoptions nullglob rcexpandparam extendedglob
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
 
-local comp post ret=1 _compskip format _comp_ignore \
+local comp post ret=1 tmp _compskip format _comp_ignore \
       _completers _completer _completer_num \
       _matchers _matcher _matcher_num \
       context state line opt_args val_args curcontext="$curcontext" \
@@ -80,7 +80,24 @@
   (( _completer_num++ ))
 done
 
-if [[ $compstate[nmatches] -gt 1 ]]; then
+if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
+   [[ $compstate[old_list] != shown &&
+      $compstate[nmatches] = 0 &&
+      $compstate[alternate_nmatches] = 1 ]]; then
+  case "$tmp" in
+  show) compstate[insert]='' compstate[list]='list force' tmp='' ;;
+  menu)
+    local expl
+
+    compstate[insert]='menu'
+    _description original expl original    
+    compadd "$expl[@]" -a -S '' - "$PREFIX$SUFFIX"
+    ;;
+  *) tmp='' ;;
+  esac
+fi
+
+if [[ -n "$tmp" || $compstate[nmatches] -gt 1 ]]; then
   [[ _last_nmatches -ge 0 && _last_nmatches -ne compstate[nmatches] ]] &&
       _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" )
 

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: Re: completion after ../
  2000-01-24  9:10 Sven Wischnowsky
@ 2000-02-17 23:33 ` Tanaka Akira
  0 siblings, 0 replies; 7+ messages in thread
From: Tanaka Akira @ 2000-02-17 23:33 UTC (permalink / raw)
  To: zsh-workers

In article <200001240910.KAA02702@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Or maybe we write a completer (a real, top-level completer) that
> registers a post-completion function which checks if there are only
> alternate matches (or only one alternate match) and no normal one and, 
> if this is the case, makes a list be shown instead of the match(es) be 
> used. That would be quite easy (set compstate[insert]='',
> compstate[list]='list force'), , but I'm not sure if this is enough or 
> the right thing at all.

I tried this and I found it's enough for me.  Of course, I agree that
it's quite inconsistent behaviour and it shouldn't be default.

So I want to insert following fragment at last in _main_complete.

if zstyle -b ":completion:..." &&
   [[ $compstate[old_list] != shown &&
      $compstate[nmatches] = 0 &&
      $compstate[alternate_nmatches] = 1 ]]; then
  compstate[insert]=''
  compstate[list]='list force'
fi

What's a proper context and a style?  I couldn't find them.
-- 
Tanaka Akira


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

* Re: PATCH: Re: completion after ../
@ 2000-01-24  9:10 Sven Wischnowsky
  2000-02-17 23:33 ` Tanaka Akira
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 2000-01-24  9:10 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> ...
> 
> The updated _comp_ignore is not used.

Ouch. The patch should fix this.

> > Note however, that there is no automatic switching to list-only and no 
> > way to get at the ignored directories on a second TAB or something
> > like this. The ignored names are put in the alternate set so that one
> > gets them if no other names match.
> > 
> > 
> > I think what sometimes irritated me can be fixed with `pwd' or maybe
> > `pwd ..' and Tanaka's with `parent' or `parent ..'. I hope.
> 
> Hm.  It's not enough for me.  Sometimes I hit <TAB> after a path which
> contains only one directory.  Suppose zsh-3.1.6-dev-15 is installed
> in its own prefix /app/zsh-3.1.6-dev-15 and the current working
> directory is /app/zsh-3.1.6-dev-15/share/zsh/3.1.6-dev-15/functions.
> When completion is tried as `cd ../../../<TAB>', the alternative set
> has only one entry `zsh' and non-alternative set is empty if I
> understand the style correctly and it works well.  So zsh completes
> the line as `cd ../../../zsh/'.  But it frustrates me because I must
> remove `zsh/' before adding `../'.

[ This should be quite easy using undo... but, see below. ]

>  I hope a style to automatic
> switching to list-only.  Although I tried to do it, I couldn't find a
> way.

I have several problems with this. First, at least for me, this is
probably quite irritating. Second: how to do it. It is possible, of
course, but we would have to set some flag when parent directories
have been ignored, and test that flag at the very end of completion
because only then do we know if there is only one match. I.e. the code 
for it would be scattered between _path_files and, say, _main_complete. 

Maybe it is enough if we add a special value to ignore_parents so that 
the special-dirs (`..' and `.' are added to the alternate set if there 
were ignored directories (we could also do that only if ignore-parents 
leaves the normal set empty and the alternate set with only one
string, but if _path_files is called more than once or any other
completion function is called, the result may again be not what one
wants).

Or maybe we write a completer (a real, top-level completer) that
registers a post-completion function which checks if there are only
alternate matches (or only one alternate match) and no normal one and, 
if this is the case, makes a list be shown instead of the match(es) be 
used. That would be quite easy (set compstate[insert]='',
compstate[list]='list force'), , but I'm not sure if this is enough or 
the right thing at all.

Bye
 Sven

diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files	Mon Jan 24 09:58:01 2000
+++ Completion/Core/_path_files	Mon Jan 24 09:59:14 2000
@@ -326,6 +326,8 @@
 	    [[ "$i" -ef "$PWD" ]] && _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" )
 	  done
         fi
+       (( $#_comp_ignore )) && (( $expl[(I)-F] )) ||
+           expl=( "$expl[@]" -F _comp_ignore )
       fi
       if [[ "$sopt" = *[/f]* && ( -o globdots || "$PREFIX" = .* ) ]] &&
 	  zstyle -s ":completion${curcontext}:paths" special-dirs atmp; then

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: Re: completion after ../
  2000-01-21 13:39 Sven Wischnowsky
@ 2000-01-21 18:11 ` Tanaka Akira
  0 siblings, 0 replies; 7+ messages in thread
From: Tanaka Akira @ 2000-01-21 18:11 UTC (permalink / raw)
  To: zsh-workers

In article <200001211339.OAA04917@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> Let's try it...

I tried it but it doesn't work for me even after one typo fix.

Z:akr@is27e1u11% Src/zsh -f
is27e1u11% bindkey -e; fpath=($PWD/Completion/*(/)); autoload -U compinit; compinit -D; compdef _tst tst
is27e1u11% mkdir -p tstdir/{foo,bar}
is27e1u11% cd tstdir
is27e1u11% ls
bar  foo
is27e1u11% zstyle '*' ignore-parents parent
is27e1u11% ls foo/../<TAB>
bar/  foo/

`foo/' shouldn't be listed, I think.

set -x says (after the patch in this message is applied):
is27e1u11% ls foo/../<TAB>
...
+_description:33> zstyle -a :completion:complete::ls::files ignored-patterns _comp_ignore
+_description:36> _comp_ignore=( ) 
...
+_path_files:344> compadd -D tmp1 -F _comp_ignore - bar foo
...
+_path_files:308> zstyle -s :completion:complete::ls::files ignore-parents rem
...
+_path_files:320> _comp_ignore=( foo/../foo ) 
...
+_path_files:474> compadd -Qf -p foo/../ -W foo/../ -M r:|/=* r:|=*  -J -default- - bar foo
...

The updated _comp_ignore is not used.

> Note however, that there is no automatic switching to list-only and no 
> way to get at the ignored directories on a second TAB or something
> like this. The ignored names are put in the alternate set so that one
> gets them if no other names match.
> 
> 
> I think what sometimes irritated me can be fixed with `pwd' or maybe
> `pwd ..' and Tanaka's with `parent' or `parent ..'. I hope.

Hm.  It's not enough for me.  Sometimes I hit <TAB> after a path which
contains only one directory.  Suppose zsh-3.1.6-dev-15 is installed
in its own prefix /app/zsh-3.1.6-dev-15 and the current working
directory is /app/zsh-3.1.6-dev-15/share/zsh/3.1.6-dev-15/functions.
When completion is tried as `cd ../../../<TAB>', the alternative set
has only one entry `zsh' and non-alternative set is empty if I
understand the style correctly and it works well.  So zsh completes
the line as `cd ../../../zsh/'.  But it frustrates me because I must
remove `zsh/' before adding `../'.  I hope a style to automatic
switching to list-only.  Although I tried to do it, I couldn't find a
way.

Index: Completion/Core/_path_files
===================================================================
RCS file: /projects/zsh/zsh/Completion/Core/_path_files,v
retrieving revision 1.1.1.61
diff -u -r1.1.1.61 _path_files
--- Completion/Core/_path_files	2000/01/21 16:33:49	1.1.1.61
+++ Completion/Core/_path_files	2000/01/21 17:28:33
@@ -311,7 +311,7 @@
         if [[ "$rem" = *parent* ]]; then
 	  for i in "$tmp2[@]"; do
 	    if [[ -d "$i" && "$i" = */* ]]; then
-	      remt="${i/*}"
+	      remt="${i%/*}"
 	      while [[ "$remt" = */* ]]; do
 		[[ "$remt" -ef "$i" ]] && break
 		remt="${remt%/*}"
-- 
Tanaka Akira


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

* PATCH: Re: completion after ../
@ 2000-01-21 13:39 Sven Wischnowsky
  2000-01-21 18:11 ` Tanaka Akira
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 2000-01-21 13:39 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> In article <rsqwvp5ucjx.fsf@crane.jaist.ac.jp>,
>   Tanaka Akira <akr@jaist.ac.jp> writes:
> 
> > Hm.  In general, I don't want to complete a directory which is already
> > described in the word, with first <TAB> at least.  Most frequently
> > happened example is X/../Z where X/../Z is X.
> 
> I rethought the problem and I found another idea to describe it: A
> directory which shouldn't complete with first <TAB> is the directory
> which go back path.  Of course, this is subset of previous idea but
> it's enough for me.  The directory X/Y/Z is a such directory iff [[ X
> -ef X/Y/Z ]] where Y and Z contains no `/'.  Note that if there is no
> symlinks and in completion context, this happens only when Y == `..'.

Let's try it...

The ignore-parents style may contain a list of the words `parent',
`pwd', `..' and `directory'.

`parent' makes it search for the name of a directory-to-be-completed
in the word from the line, working even with sym-links.

`pwd' is another test that might be useful: it makes the name of the
current working directory be ignored.

If `..' is given, theses tests are only performed if the word on the
line contains the string `../' (maybe this should be the pattern
`(|*/)../*' ?).

If `directory' is given, it does this only when completing with the
pattern `*(-/)' (and only this pattern).

Note however, that there is no automatic switching to list-only and no 
way to get at the ignored directories on a second TAB or something
like this. The ignored names are put in the alternate set so that one
gets them if no other names match.


I think what sometimes irritated me can be fixed with `pwd' or maybe
`pwd ..' and Tanaka's with `parent' or `parent ..'. I hope.


Bye
 Sven

P.S.: Does anyone see a better solution than the two nested loops for
      `parent'?

diff -ru ../z.old/Completion/Builtins/_zstyle Completion/Builtins/_zstyle
--- ../z.old/Completion/Builtins/_zstyle	Fri Jan 21 12:35:43 2000
+++ Completion/Builtins/_zstyle	Fri Jan 21 14:36:44 2000
@@ -28,6 +28,7 @@
   hosts			 c:_hosts
   hosts-ports		 c:host-port
   hosts-ports-users	 c:host-port-user
+  ignore-parents         c:ignorepar
   ignored-patterns	 c:
   insert-unambiguous	 c:bool
   last-prompt		 c:bool
@@ -165,6 +166,11 @@
       else
 	_users
       fi
+      ;;
+
+    ignorepar)
+      _wanted values expl 'which parents to ignore' &&
+        compadd "$expl[@]" parent pwd .. directory
       ;;
 
     _*)
diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files	Fri Jan 21 12:35:46 2000
+++ Completion/Core/_path_files	Fri Jan 21 14:31:41 2000
@@ -5,7 +5,7 @@
 
 local linepath realpath donepath prepath testpath exppath
 local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
-local pats haspats=no ignore group expl addpfx addsfx remsfx
+local pats haspats=no ignore group expl addpfx addsfx remsfx rem remt
 local nm=$compstate[nmatches] menu mspec matcher mopts atmp sort match
 
 typeset -U prepaths exppaths
@@ -300,8 +300,31 @@
       tmp2=( ${^tmp1}${^~pats} )
       [[ ! -o globdots && "$PREFIX" = .* ]] &&
           tmp2=( "$tmp2[@]" ${^tmp1}.${^~pats} )
+      if (( $#tmp2 )) &&
+         zstyle -s ":completion${curcontext}:files" ignore-parents rem &&
+	 [[ ( "$rem" != *dir* || "$pats" = '*(-/)' ) &&
+	    ( "$rem" != *..* || "$tmp1" = *../* ) ]]; then
+        if [[ "$rem" = *parent* ]]; then
+	  for i in "$tmp2[@]"; do
+	    if [[ -d "$i" && "$i" = */* ]]; then
+	      remt="${i/*}"
+	      while [[ "$remt" = */* ]]; do
+		[[ "$remt" -ef "$i" ]] && break
+		remt="${remt%/*}"
+	      done
+	      [[ "$remt" = */* || "$remt" -ef "$i" ]] &&
+	          _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" )
+	    fi
+	  done
+        fi
+        if [[ "$rem" = *pwd* ]]; then
+          for i in "$tmp2[@]"; do
+	    [[ "$i" -ef "$PWD" ]] && _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" )
+	  done
+        fi
+      fi
       if [[ "$sopt" = *[/f]* && ( -o globdots || "$PREFIX" = .* ) ]] &&
-	 zstyle -s ":completion${curcontext}:paths" special-dirs atmp; then
+	  zstyle -s ":completion${curcontext}:paths" special-dirs atmp; then
 	if [[ "$atmp" = (yes|true|1|on) ]]; then
 	  tmp2=( "$tmp2[@]" . .. )
 	elif [[ "$atmp" = .. ]]; then
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo	Fri Jan 21 12:35:26 2000
+++ Doc/Zsh/compsys.yo	Fri Jan 21 14:33:15 2000
@@ -876,6 +876,29 @@
 Like tt(hosts-ports) but used for commands like tt(telnet) and
 containing strings of the form `var(host)tt(:)var(port)tt(:)var(user)'.
 )
+item(tt(ignore-parents))(
+When completing files it is possible to make names of directories
+already mentioned on the line or the current working directory be
+ignored. The style is tested for the tt(files) tag and if its value
+contains the string tt(parent), then the name of any directory whose
+path is already contained in the word on the line is ignored. For
+example, when completing after tt(foo/../), the directory tt(foo) will
+not be considered a valid completion.
+
+If the style contains the string tt(pwd), then the name of the current 
+working directory will not be completed, so that, for example,
+completion after tt(../) will not use the name of the current
+directory.
+
+If the style contains the string tt(..) both tests will only be
+performed if the word on the line contains the substring tt(../) and
+if the value contains the string tt(directory), then the tests will
+only be performed if only names of directories are completed.
+
+Note that names of directories ignored because of one of the tests
+will be placed in the alternate set of completions so that they will
+be completed if there are no other possible completions.
+)
 item(tt(ignored-patterns))(
 This style is used with the tags used when adding matches and gives a
 number of patterns. All matches that are matched by any of these

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~2000-02-21  9:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-18  9:39 PATCH: Re: completion after ../ Sven Wischnowsky
2000-02-20 12:17 ` Tanaka Akira
  -- strict thread matches above, loose matches on Subject: below --
2000-02-21  9:28 Sven Wischnowsky
2000-01-24  9:10 Sven Wischnowsky
2000-02-17 23:33 ` Tanaka Akira
2000-01-21 13:39 Sven Wischnowsky
2000-01-21 18:11 ` Tanaka Akira

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