zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: zsh and perl
@ 2000-11-15 10:56 Sven Wischnowsky
  2000-11-15 16:03 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2000-11-15 10:56 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> Any suggestions for how to avoid the chpwd problem?

I'm sure I'm missing something, but... why not just avoid the cd
altogether? Something like

  new_pms=( $libdir/{[a-Z]*/***/,}*.pm~*blib* )
  new_pms=( "${(@)new_pms#$libdir/}" )

probably testing if $libdir is non-empty before that...

Bye
 Sven


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


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

* Re: PATCH: zsh and perl
  2000-11-15 10:56 PATCH: zsh and perl Sven Wischnowsky
@ 2000-11-15 16:03 ` Bart Schaefer
  2000-11-16 12:18   ` Adam Spiers
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2000-11-15 16:03 UTC (permalink / raw)
  To: zsh-workers

On Nov 15, 11:56am, Sven Wischnowsky wrote:
}
} I'm sure I'm missing something, but... why not just avoid the cd
} altogether? Something like
} 
}   new_pms=( $libdir/{[a-Z]*/***/,}*.pm~*blib* )
}   new_pms=( "${(@)new_pms#$libdir/}" )

I wondered about that myself.

} probably testing if $libdir is non-empty before that...

We already have reasonably confidence that $libdir is non-empty because it
came either from perl's @INC array or from a previous glob which it's then
iterating over with `for'.  It also tests [[ -d $libdir && -x $libdir ]],
so I can't think of any reason for doing the cd.

(Does this recursive glob with *** potentially have the same automounting
problem that we hacked around in _path_files?)

I used $libdir/## for the pattern removed from each word, just in case
$libdir already had a trailing slash before we added another one.  The
other change is just in case `.' is not the last element of @INC, for
whatever odd reason.  It might make more sense to avoid the recursive
glob for `.', rather than skip it entirely.

Index: Completion/User/_perl_modules
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Completion/User/_perl_modules,v
retrieving revision 1.14
diff -u -r1.14 _perl_modules
--- _perl_modules	2000/11/15 15:39:37	1.14
+++ _perl_modules	2000/11/15 15:44:11
@@ -67,13 +67,12 @@
 
       for libdir in $inc; do
         # Ignore cwd - could be too expensive e.g. if we're near /
-        if [[ $libdir == '.' ]]; then break; fi
+        if [[ $libdir == '.' ]]; then continue; fi
 
         # Find all modules
         if [[ -d $libdir && -x $libdir ]]; then
-        builtin cd $libdir
-        new_pms=( {[A-Z]*/***/,}*.pm~*blib* )
-        builtin cd $OLDPWD
+          new_pms=( $libdir/{[A-Z]*/***/,}*.pm~*blib* )
+          new_pms=( "${(@)new_pms#$libdir/##}" )
         fi
 
         # Convert to Perl nomenclature

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: zsh and perl
  2000-11-15 16:03 ` Bart Schaefer
@ 2000-11-16 12:18   ` Adam Spiers
  0 siblings, 0 replies; 5+ messages in thread
From: Adam Spiers @ 2000-11-16 12:18 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer (schaefer@candle.brasslantern.com) wrote:
> On Nov 15, 11:56am, Sven Wischnowsky wrote:
> }
> } I'm sure I'm missing something, but... why not just avoid the cd
> } altogether? Something like
> } 
> }   new_pms=( $libdir/{[a-Z]*/***/,}*.pm~*blib* )
> }   new_pms=( "${(@)new_pms#$libdir/}" )
> 
> I wondered about that myself.
> 
> } probably testing if $libdir is non-empty before that...
> 
> We already have reasonably confidence that $libdir is non-empty because it
> came either from perl's @INC array or from a previous glob which it's then
> iterating over with `for'.  It also tests [[ -d $libdir && -x $libdir ]],
> so I can't think of any reason for doing the cd.

There probably isn't a good reason; I suspect I was struggling with
the expansions at the time and thought this would simplify things.


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

* Re: PATCH: zsh and perl
  2000-11-14 12:47 Paul Johnson
@ 2000-11-14 16:10 ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-11-14 16:10 UTC (permalink / raw)
  To: Paul Johnson, zsh-workers; +Cc: adam

On Nov 14,  1:47pm, Paul Johnson wrote:
}
} 1.  cd was used which called my cd function

I can see where this would be annoying, but somebody else could just as
easily have a function for chdir.  A somewhat better fix would be to use
`builtin cd', but even that is going to call peoples' chpwd functions.

} 2.  with multiple versions of perl around it's nice to complete modules
}     specific to the version of perldoc being used

Everything about this change looks OK except the call to _store_cache,
which I don't think should have the ${(P)...} in the second argument.
Just $perl_modules is needed.

An improvement would be for the first argument to both _retrieve_cache
and _store_cache to be ${perl_modules#_}, to continue using the same
cache name as the previous version of the function.

This patch goes on top of Paul's; I'll commit the end result soon.

Any suggestions for how to avoid the chpwd problem?

--- ../current/Completion/User/_perl_modules	Tue Nov 14 08:02:44 2000
+++ Completion/User/_perl_modules	Tue Nov 14 08:04:47 2000
@@ -42,7 +42,7 @@
   fi
 
   if ( [[ ${(P)+perl_modules} -eq 0 ]] || _cache_invalid $perl_modules ) &&
-     ! _retrieve_cache $perl_modules;
+     ! _retrieve_cache ${perl_modules#_};
   then
     if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst &&
        (( ${+commands[pminst]} ));
@@ -71,9 +71,9 @@
   
         # Find all modules
         if [[ -d $libdir && -x $libdir ]]; then
-        chdir $libdir
+        builtin cd $libdir
         new_pms=( {[A-Z]*/***/,}*.pm~*blib* )
-        chdir $OLDPWD
+        builtin cd $OLDPWD
         fi
   
         # Convert to Perl nomenclature
@@ -83,7 +83,7 @@
       done
     fi
   
-    _store_cache $perl_modules ${(P)perl_modules}
+    _store_cache ${perl_modules#_} $perl_modules
   fi
   
   local expl

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* PATCH: zsh and perl
@ 2000-11-14 12:47 Paul Johnson
  2000-11-14 16:10 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Johnson @ 2000-11-14 12:47 UTC (permalink / raw)
  To: zsh-workers; +Cc: adam

I use both zsh and perl heavily and there were a couple of things about
the perldoc completion that were annoying me.

1.  cd was used which called my cd function

2.  with multiple versions of perl around it's nice to complete modules
    specific to the version of perldoc being used

The following patch addresses these two issues.  I'd be grateful if you
would have a good look at it since my shell coding skills are not much
to shout about, and comment on it or include it if you feel it's
appropriate.



--- _perl_modules.org	Wed Oct 18 15:50:25 2000
+++ _perl_modules	Tue Nov 14 13:20:10 2000
@@ -29,18 +29,30 @@
     zstyle ":completion:${curcontext}:" cache-policy \
       _perl_modules_caching_policy
   fi
-  
-  if ( [[ ${+_perl_modules} -eq 0 ]] || _cache_invalid perl_modules ) &&
-     ! _retrieve_cache perl_modules;
+
+  local perl=${words[0]%doc} perl_modules
+  if [[ -f $perl && -x $perl ]]; then
+    perl_modules=${perl//\\//_}_modules
+  elif (( ${+commands[perl]} )); then
+    perl=perl
+    perl_modules=_perl_modules
+  else
+    perl=
+    perl_modules=_unknown_perl_modules
+  fi
+
+  if ( [[ ${(P)+perl_modules} -eq 0 ]] || _cache_invalid $perl_modules ) &&
+     ! _retrieve_cache $perl_modules;
   then
     if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst &&
        (( ${+commands[pminst]} ));
     then
-      _perl_modules=( $(pminst) )
+      set -A $perl_modules $(pminst)
     else
       local inc libdir new_pms
-      if (( ${+commands[perl]} )); then
-        inc=( $( perl -e 'print "@INC"' ) )
+
+      if [[ ${+perl} -eq 1 ]]; then
+        inc=( $( $perl -e 'print "@INC"' ) )
       else
         # If perl isn't there, one wonders why the user's trying to
         # complete Perl modules.  Maybe her $path is wrong?
@@ -50,8 +62,8 @@
               ${(s.:.)PERL5LIB} )
       fi
   
-      typeset -agU _perl_modules  # _perl_modules is global, no duplicates
-      _perl_modules=( )
+      typeset -agU $perl_modules  # $perl_modules is global, no duplicates
+      set -A $perl_modules
   
       for libdir in $inc; do
         # Ignore cwd - could be too expensive e.g. if we're near /
@@ -59,24 +71,24 @@
   
         # Find all modules
         if [[ -d $libdir && -x $libdir ]]; then
-        cd $libdir
+        chdir $libdir
         new_pms=( {[A-Z]*/***/,}*.pm~*blib* )
-        cd $OLDPWD
+        chdir $OLDPWD
         fi
   
         # Convert to Perl nomenclature
         new_pms=( ${new_pms:r:fs#/#::#} )
   
-        _perl_modules=( $new_pms $_perl_modules )
+        set -A $perl_modules $new_pms ${(P)perl_modules}
       done
     fi
   
-    _store_cache perl_modules _perl_modules
+    _store_cache $perl_modules ${(P)perl_modules}
   fi
   
   local expl
   
-  _wanted modules expl 'Perl modules' compadd "$opts[@]" -a _perl_modules
+  _wanted modules expl 'Perl modules' compadd "$opts[@]" -a $perl_modules
 }
 
 _perl_modules_caching_policy () {



-- 
Paul Johnson - paulj@olsen.ch


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

end of thread, other threads:[~2000-11-16 12:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-15 10:56 PATCH: zsh and perl Sven Wischnowsky
2000-11-15 16:03 ` Bart Schaefer
2000-11-16 12:18   ` Adam Spiers
  -- strict thread matches above, loose matches on Subject: below --
2000-11-14 12:47 Paul Johnson
2000-11-14 16:10 ` Bart Schaefer

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