zsh-users
 help / color / mirror / code / Atom feed
* Suggestion: Allow whence to report path(s) for autoloaded functions
@ 2009-04-21 21:14 Ian Tegebo
  2009-04-22  8:29 ` Peter Stephenson
  2009-04-25 19:55 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Ian Tegebo @ 2009-04-21 21:14 UTC (permalink / raw)
  To: zsh-users

Given a function name, I'm finding it useful to know where it's
located within fpath:

for p in $fpath; do
  [[ -e $p/_MYFUNC ]] && echo $p/_MYFUNC && break
done

(where fpath is something like ( /blah/path_one/  /blah/path_two/ ) )

It seems like 'whence -v _MYFUNC' is the intuitive place to look for
this behavior.  I'd imagine it working like:

$ whence -v _MYFUNC
_MYFUNC is a shell function defined in /blah/path/_MYFUNC

Consequently, removing the '&& break' provides the expected result for
'whence -a':

$ whence -av _MYFUNC
_MYFUNC is a shell function defined in /blah/path_one/_MYFUNC
_MYFUNC is a shell function defined in /blah/path_two/_MYFUNC

(BTW, is zsh-workers@ more appropriate for discussing changes to builtins?)
-- 
Ian Tegebo


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

* Re: Suggestion: Allow whence to report path(s) for autoloaded functions
  2009-04-21 21:14 Suggestion: Allow whence to report path(s) for autoloaded functions Ian Tegebo
@ 2009-04-22  8:29 ` Peter Stephenson
  2009-04-25 19:55 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2009-04-22  8:29 UTC (permalink / raw)
  To: zsh-users

On Tue, 21 Apr 2009 14:14:09 -0700
Ian Tegebo <ian.tegebo@gmail.com> wrote:
> Given a function name, I'm finding it useful to know where it's
> located within fpath:

There's a standard trick for this:

print $^fpath/_MYFUNC(N)

> (BTW, is zsh-workers@ more appropriate for discussing changes to builtins?)

Probably, although it's often borderline.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: Suggestion: Allow whence to report path(s) for autoloaded functions
  2009-04-21 21:14 Suggestion: Allow whence to report path(s) for autoloaded functions Ian Tegebo
  2009-04-22  8:29 ` Peter Stephenson
@ 2009-04-25 19:55 ` Bart Schaefer
  2009-04-26  1:38   ` Ian Tegebo
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2009-04-25 19:55 UTC (permalink / raw)
  To: zsh-users

I had something of an afterthought on this one ...

On Apr 21,  2:14pm, Ian Tegebo wrote:
}
} It seems like 'whence -v _MYFUNC' is the intuitive place to look for
} this behavior.  I'd imagine it working like:
} 
} $ whence -v _MYFUNC
} _MYFUNC is a shell function defined in /blah/path/_MYFUNC

This information could be misleading.  Functions are not always loaded
from $fpath; they can be defined in init files, edited and/or hand-
entered on the command line, etc.  To make whence useful, the shfunc
structure would have to record where the function came from, or whence
must only report the above if the function has NOT YET been loaded.

There's also the question of what to do about files that are found in
the $fpath directories but are not marked for autoloading.
 
} Consequently, removing the '&& break' provides the expected result for
} 'whence -a':
} 
} $ whence -av _MYFUNC
} _MYFUNC is a shell function defined in /blah/path_one/_MYFUNC
} _MYFUNC is a shell function defined in /blah/path_two/_MYFUNC

That's also misleading.  If _MYFUNC were an executable located in two
directories, it would be possible to explicitly choose which to run
by typing the full path name as reported by whence.  For a function,
there's no [straightforward] way to bypass the fpath search order.

(The non-straightforward way is to run
    FPATH=/blah/path_two:"$FPATH" _MYFUNC
but that can produce unexpected results if _MYFUNC calls autoloaded
functions that should come from /blah/path_one instead.)


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

* Re: Suggestion: Allow whence to report path(s) for autoloaded  functions
  2009-04-25 19:55 ` Bart Schaefer
@ 2009-04-26  1:38   ` Ian Tegebo
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Tegebo @ 2009-04-26  1:38 UTC (permalink / raw)
  To: zsh-users

On Sat, Apr 25, 2009 at 12:55 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> I had something of an afterthought on this one ...
>
> On Apr 21,  2:14pm, Ian Tegebo wrote:
> }
> } It seems like 'whence -v _MYFUNC' is the intuitive place to look for
> } this behavior.  I'd imagine it working like:
> }
> } $ whence -v _MYFUNC
> } _MYFUNC is a shell function defined in /blah/path/_MYFUNC
>
> This information could be misleading.  Functions are not always loaded
> from $fpath; they can be defined in init files, edited and/or hand-
> entered on the command line, etc.  To make whence useful, the shfunc
> structure would have to record where the function came from, or whence
> must only report the above if the function has NOT YET been loaded.
>
> There's also the question of what to do about files that are found in
> the $fpath directories but are not marked for autoloading.
>
> } Consequently, removing the '&& break' provides the expected result for
> } 'whence -a':
> }
> } $ whence -av _MYFUNC
> } _MYFUNC is a shell function defined in /blah/path_one/_MYFUNC
> } _MYFUNC is a shell function defined in /blah/path_two/_MYFUNC
>
> That's also misleading.  If _MYFUNC were an executable located in two
> directories, it would be possible to explicitly choose which to run
> by typing the full path name as reported by whence.  For a function,
> there's no [straightforward] way to bypass the fpath search order.
>
> (The non-straightforward way is to run
>    FPATH=/blah/path_two:"$FPATH" _MYFUNC
> but that can produce unexpected results if _MYFUNC calls autoloaded
> functions that should come from /blah/path_one instead.)
>
Thanks for that.

Obviously, I didn't fully appreciate how specific my use case was (nor
did I know about the idiom Peter suggested).  Now I realize I only
wanted a quick way to resolve a named file within a PATH-like
structure, and not the more general case about functions that my
suggestion implied.


-- 
Ian Tegebo


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

end of thread, other threads:[~2009-04-26  1:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-21 21:14 Suggestion: Allow whence to report path(s) for autoloaded functions Ian Tegebo
2009-04-22  8:29 ` Peter Stephenson
2009-04-25 19:55 ` Bart Schaefer
2009-04-26  1:38   ` Ian Tegebo

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