caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [request] look for .ocamlinit also in home dir
@ 2002-10-24 16:07 Stefano Zacchiroli
  0 siblings, 0 replies; only message in thread
From: Stefano Zacchiroli @ 2002-10-24 16:07 UTC (permalink / raw)
  To: Inria Ocaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 541 bytes --]

It would be nice if the ocaml toplevel look for .ocamlinit not only in
the current directory but also in the home directory of the user, is it
possible to add such a feature?

Attched there is a patch for toplevel/toploop.ml that implements it.

Cheers.

-- 
Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy
zack@cs.unibo.it | ICQ# 33538863 | http://www.cs.unibo.it/~zacchiro
"I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!" -- G.Romney

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 813 bytes --]

--- toploop.ml.orig	2002-10-24 17:29:41.000000000 +0200
+++ toploop.ml	2002-10-24 17:38:20.000000000 +0200
@@ -347,7 +347,25 @@
   Compile.init_path()
 
 let load_ocamlinit ppf =
-  if Sys.file_exists ".ocamlinit" then ignore(use_silently ppf ".ocamlinit")
+  let homedir =
+    try Some (Sys.getenv "HOME")
+    with Not_found -> None
+  in
+  let initfile =
+    if Sys.file_exists ".ocamlinit" then
+      Some ".ocamlinit"
+    else
+      (match homedir with
+      | Some d ->
+          if Sys.file_exists (d ^ "/.ocamlinit") then
+            Some (d ^ "/.ocamlinit")
+          else
+            None
+      | None -> None)
+  in
+  match initfile with
+  | Some f -> ignore(use_silently ppf f)
+  | None -> ()
 
 let set_paths () =
   (* Add whatever -I options have been specified on the command line,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-24 16:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 16:07 [Caml-list] [request] look for .ocamlinit also in home dir Stefano Zacchiroli

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