From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17664 invoked from network); 21 Jan 2000 13:39:24 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 21 Jan 2000 13:39:24 -0000 Received: (qmail 19322 invoked by alias); 21 Jan 2000 13:39:17 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9402 Received: (qmail 19315 invoked from network); 21 Jan 2000 13:39:16 -0000 Date: Fri, 21 Jan 2000 14:39:14 +0100 (MET) Message-Id: <200001211339.OAA04917@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Tanaka Akira's message of 20 Jan 2000 13:34:32 +0900 Subject: PATCH: Re: completion after ../ Tanaka Akira wrote: > In article , > Tanaka Akira writes: > > > Hm. In general, I don't want to complete a directory which is already > > described in the word, with first 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 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