From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Subject: `include' relative to current file
Date: Sun, 20 Jan 2013 20:28:21 +0100 [thread overview]
Message-ID: <87txqbac2y.fsf@pobox.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 195 bytes --]
Thoughts on this patch? It fixes SLIB in CVS, which now does an
(include "guile-2.init") in the Guile 2.x case.
To test, check out Slib from CVS, then (load
"/path/to/slib/guile.init").
Andy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-include-relative-paths-relative-to-including-file.patch --]
[-- Type: text/x-diff, Size: 2200 bytes --]
From 856d0ef6e7a5236da36c2fae13271e643580507d Mon Sep 17 00:00:00 2001
From: Andy Wingo <wingo@pobox.com>
Date: Sun, 20 Jan 2013 20:26:59 +0100
Subject: [PATCH] `include' relative paths relative to including file
* module/ice-9/psyntax.scm (include): Like `load', interpret relative
paths as being relative to the file that does the `include'.
---
module/ice-9/psyntax.scm | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
index 6c264a6..d41a0eb 100644
--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -1,7 +1,7 @@
;;;; -*-scheme-*-
;;;;
;;;; Copyright (C) 2001, 2003, 2006, 2009, 2010, 2011,
-;;;; 2012 Free Software Foundation, Inc.
+;;;; 2012, 2013 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -2935,9 +2935,15 @@
(define-syntax include
(lambda (x)
+ (define (absolute-path? path)
+ (string-prefix? "/" path))
+
(define read-file
- (lambda (fn k)
- (let ((p (open-input-file fn)))
+ (lambda (fn dir k)
+ (let ((p (open-input-file
+ (if (absolute-path? fn)
+ fn
+ (in-vicinity dir fn)))))
(let f ((x (read p))
(result '()))
(if (eof-object? x)
@@ -2946,11 +2952,14 @@
(reverse result))
(f (read p)
(cons (datum->syntax k x) result)))))))
- (syntax-case x ()
- ((k filename)
- (let ((fn (syntax->datum #'filename)))
- (with-syntax (((exp ...) (read-file fn #'filename)))
- #'(begin exp ...)))))))
+ (let* ((src (syntax-source x))
+ (file (and src (assq-ref src 'filename)))
+ (dir (and (string? file) (dirname file))))
+ (syntax-case x ()
+ ((k filename)
+ (let ((fn (syntax->datum #'filename)))
+ (with-syntax (((exp ...) (read-file fn dir #'filename)))
+ #'(begin exp ...))))))))
(define-syntax include-from-path
(lambda (x)
--
1.7.10.4
[-- Attachment #3: Type: text/plain, Size: 26 bytes --]
--
http://wingolog.org/
next reply other threads:[~2013-01-20 19:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-20 19:28 Andy Wingo [this message]
2013-01-20 19:57 ` `include' relative to current file Jay Sulzberger
2013-01-21 6:08 ` Jay Sulzberger
2013-01-21 9:01 ` Andy Wingo
2013-01-22 5:54 ` Jay Sulzberger
2013-01-22 10:16 ` Ludovic Courtès
2013-01-22 11:09 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txqbac2y.fsf@pobox.com \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).