[PATCH] Add environment variable to specify .guile location
wreed <[email protected]> Sat, 23 Aug 2025 18:07:51 +0200
| Newsgroups | gmane.lisp.guile.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I sent in a patch last month adding an environment variable as a
facility to change the location of `~/.guile'. I have revised the patch
to reflect the addition in the manpage and texinfo manual. Since then I
have also completed the copyright assignment process, proof of which
will be attached to this email.
diff --git a/doc/guile.1 b/doc/guile.1
index 77c8639..84276b6 100644
--- a/doc/guile.1
+++ b/doc/guile.1
@@ -212,6 +212,16 @@ Scheme files (.go files) when loading.
It should be a colon-separated list of directories,
which will be prefixed to the default
.B %load-compiled-path.
+.TP
+.B GUILE_INIT_FILE
+If
+.RB $ GUILE_INIT_FILE
+is set before
+.B guile
+is started and points to a file,
+its contents are executed before any other processing occurs.
+If not set, the default is
+.I ~/.guile
.
.SH FILES
.TP
diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
index b08c85c..f85e7b2 100644
--- a/doc/ref/scheme-using.texi
+++ b/doc/ref/scheme-using.texi
@@ -46,12 +46,18 @@ support for languages other than Scheme.
@node Init File
@subsection The Init File, @file{~/.guile}
+@subsection The Init File, @env{GUILE_INIT_FILE}
@cindex .guile
When run interactively, Guile will load a local initialization file
from
@file{~/.guile}. This file should contain Scheme expressions for
evaluation.
+@cindex GUILE_INIT_FILE
+Alternatively to @file{~/.guile}, you may define the environment
variable
+@env{GUILE_INIT_FILE}. This variable should be a valid file path with
+similar contents to that of what @file{~/.guile} would contain.
+
This facility lets the user customize their interactive Guile
environment, pulling in extra modules or parameterizing the REPL
implementation.
@@ -59,7 +65,6 @@ implementation.
To run Guile without loading the init file, use the @code{-q}
command-line option.
-
@node Readline
@subsection Readline
@@ -75,8 +80,8 @@ scheme@@(guile-user)> (activate-readline)
@end lisp
It's a good idea to put these two lines (without the
-@code{scheme@@(guile-user)>} prompts) in your @file{.guile} file.
-@xref{Init File}, for more on @file{.guile}.
+@code{scheme@@(guile-user)>} prompts) in your @file{.guile} or
@env{GUILE_INIT_FILE} file.
+@xref{Init File}, for more on @file{.guile} and @env{GUILE_INIT_FILE}.
@node Value History
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index aaa9987..3e114e6 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -2200,12 +2200,17 @@ not already present. This helps create file
names."
;; scm_compile_shell_switches.
(define (load-user-init)
- (let* ((home (or (getenv "HOME")
- (false-if-exception (passwd:dir (getpwuid
(getuid))))
- file-name-separator-string)) ;; fallback for cygwin
etc.
- (init-file (in-vicinity home ".guile")))
- (if (file-exists? init-file)
- (primitive-load init-file))))
+ (let ((env-init-path (getenv "GUILE_INIT_FILE")))
+ (if env-init-path
+ (if (file-exists? env-init-path)
+ (primitive-load env-init-path)
+ (error "file specified by GUILE_INIT_FILE was not found."))
+ (let* ((home (or (getenv "HOME")
+ (false-if-exception (passwd:dir (getpwuid
(getuid))))
+ file-name-separator-string)) ;; fallback for
cygwin etc.
+ (init-file (in-vicinity home ".guile")))
+ (if (file-exists? init-file)
+ (primitive-load init-file))))))
Thank you,
Will Reed
[email protected]
copright-assignment-guile.pdf
(application/pdf, 603.5 KB) - not displayed