Andy Wingo <wi...@pobox.com> writes: > Hi Neil, > > On Sat 14 Jan 2012 22:48, Neil Jerram <n...@ossau.homelinux.net> writes: > >> Andy Wingo <wi...@pobox.com> writes: >> >> Of the possibilities above, I think I prefer >> >>> (add-to-load-path (dirname (current-source-filename))) > > Done. Actually I called it "current-filename", so it would be: > > (add-to-load-path (dirname (current-filename))) > > Feedback is very welcome -- especially timely feedback; it would be nice > to release on Monday or so. I'm attaching the patch (already committed) > to make it easy for you :)
Thanks! The patch works for me, although there are a couple of points that still make it a bit fiddly to use in practice. It might be possible to improve the first of those points, but I don't think anything can be done about the second. Thing 1 is that (current-filename) can return a relative filename, or a filename with a "./" in its middle: 1.1: With a script called "affiche", with "#! /usr/bin/guile -s" and which I invoke from the shell as "./affiche", (current-filename) gives "/home/neil/q/SW/ossaulib/scripts/./affiche". So if I do (dirname (dirname (current-filename)), intending to get the parent directory "/home/neil/q/SW/ossaulib", I actually get "/home/neil/q/SW/ossaulib/scripts". 1.2: If I encapsulate the load-path logic in a separate file called "setup-load-path.scm", and take advantage of the fact that (include "setup-load-path.scm") will find that file in the same directory as "affiche", (current-filename) gives just "setup-load-path.scm", and (dirname ...) on that won't give a useful result. Both problems are solved by adding in a canonicalize-path call. Would there be any downside from putting that inside current-filename, so that current-filename always returns a canonical file name? Alternatively, I think the use of canonicalize-path should be added into the example in the manual. Thing 2 is that it remains slightly inelegant to cater for both 1.8 and 2.0. I think the minimal complete solution is to write (cond-expand (guile-2 (include "setup-load-path.scm")) (else (load "setup-load-path.scm"))) at top level in every uninstalled script, and then something like (cond-expand (guile-2 (add-to-load-path (dirname (dirname (canonicalize-path (current-filename)))))) (else ;; Less elegant code for 1.8... (let* ((bindir (dirname (car (command-line)))) (absdir (cond ((string=? bindir ".") (getcwd)) ((string-match "^/" bindir) bindir) (else (in-vicinity (getcwd) bindir))))) (set! %load-path (cons (in-vicinity absdir "..") %load-path))))) in setup-load-path.scm. But without a time machine I don't think anything can be done to make either of those fragments more concise. I also had just one comment on the doc: > @@ -814,9 +780,9 @@ change occurs at the right time. > @defvar %load-hook > A procedure to be called @code{(%load-hook @var{filename})} whenever a > file is loaded, or @code{#f} for no such call. @code{%load-hook} is > -used by all of the above loading functions (@code{load}, > -@code{load-path}, @code{primitive-load} and > -@code{primitive-load-path}). > +used by all of the loading functions (@code{load} and > +@code{primitive-load}, and @code{load-path} and > +@code{primitive-load-path} documented in the next section). [...] > +@deffn {Scheme Procedure} load-from-path filename Is it 'load-path' or 'load-from-path'? Regards, Neil