Skip to content

Commit

Permalink
Address @dra27's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuenzli committed Jul 30, 2019
1 parent d06482d commit 71ca21e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 42 deletions.
5 changes: 2 additions & 3 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ Working version
* #8833, `ocaml`: adhere to the XDG base directory specification to
lookup an `.ocamlinit` file. Reads an `$XDG_CONFIG_HOME/ocaml/init.ml`
file before trying to lookup `~/.ocamlinit`. On Windows: `%LOCALAPPDATA%`
is also consulted if the `XDG_CONFIG_HOME` variable is undefined or empty
and an appropriate fallback is implemented to lookup a HOME variable if
undefined and needed by the lookup procedure.
or %APPDATA% is also consulted if the `XDG_CONFIG_HOME` variable is
undefined.
(Daniel C. Bünzli, review by David Allsopp, Armaël Guéneau and
Nicolás Ojeda Bär)

Expand Down
8 changes: 5 additions & 3 deletions man/ocaml.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,16 @@ use heuristics to enable colors only if the output supports them (an
.B XDG_CONFIG_HOME/ocaml/init.ml
according to the XDG base directory specification lookup if it exists (on
Windows
.B %LOCALAPPDATA%
.B LOCALAPPDATA
or
.B APPDATA
is consulted if
.B XDG_CONFIG_HOME
is empty or undefined), otherwise
.B .ocamlinit
in the user's home directory (
.B HOME
variable or if undefined on Windows, an appropriate fallback).
variable).
You can specify a different initialization file
by using the
.BI \-init \ file
Expand All @@ -338,7 +340,7 @@ according to the XDG base directory specification lookup if it exists (on
consults the TERM variable to determines the type of output terminal
and look up its capabilities in the terminal database.
.TP
.B XDG_CONFIG_HOME HOME %LOCALAPPDATA% (Windows)
.B XDG_CONFIG_HOME HOME LOCALAPPDATA (Windows) APPDATA (Windows)
.B .ocamlinit
lookup procedure (see above).
.SH SEE ALSO
Expand Down
8 changes: 4 additions & 4 deletions manual/manual/cmds/top.etex
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ The evaluation outcode for each phrase are not displayed.
If the current directory does not contain an ".ocamlinit" file,
the file "XDG_CONFIG_HOME/ocaml/init.ml" is looked up according
to the XDG base directory specification and used instead (on Windows
"%LOCALAPPDATA%" is consulted if "XDG_CONFIG_HOME" is empty or undefined).
If that file doesn't exist then an [.ocamlinit] file in the
users' home directory (determined via environment variable "HOME" or,
if undefined on Windows, an appropriate fallback) is used if existing.
"LOCALAPPDATA" or "APPDATA" is consulted if "XDG_CONFIG_HOME" is empty or
undefined). If that file doesn't exist then an [.ocamlinit] file in the
users' home directory (determined via environment variable "HOME") is
used if existing.

The toplevel system does not perform line editing, but it can
easily be used in conjunction with an external line editor such as
Expand Down
22 changes: 6 additions & 16 deletions toplevel/opttoploop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -556,24 +556,14 @@ let find_ocamlinit () =
let getenv var = match Sys.getenv var with
| exception Not_found -> None | "" -> None | v -> Some v
in
let home_dir () = match getenv "HOME" with
let home_dir () = getenv "HOME" in
let config_dir () = match getenv "XDG_CONFIG_HOME" with
| Some _ as v -> v
| None when not Sys.win32 -> None
| None ->
let userprofile () = getenv "USERPROFILE" in
match getenv "HOMEDRIVE" with
| None -> userprofile ()
| Some homedrive ->
match getenv "HOMEPATH" with
| None -> userprofile ()
| Some homepath ->
let dir = Filename.concat homedrive homepath in
if Sys.file_exists dir then Some dir else userprofile ()
in
let config_dir () = match getenv "XDG_CONFIG_HOME" with
| Some dir -> Some dir
| None when Sys.win32 -> getenv "%LOCALAPPDATA%"
| None -> None
if not Sys.win32 then None else
match getenv "LOCALAPPDATA" with
| Some _ as v -> v
| None -> get_env "APPDATA"
in
let init_ml = Filename.concat "ocaml" "init.ml" in
match exists_in_dir (config_dir ()) init_ml with
Expand Down
22 changes: 6 additions & 16 deletions toplevel/toploop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -504,24 +504,14 @@ let find_ocamlinit () =
let getenv var = match Sys.getenv var with
| exception Not_found -> None | "" -> None | v -> Some v
in
let home_dir () = match getenv "HOME" with
let home_dir () = getenv "HOME" in
let config_dir () = match getenv "XDG_CONFIG_HOME" with
| Some _ as v -> v
| None when not Sys.win32 -> None
| None ->
let userprofile () = getenv "USERPROFILE" in
match getenv "HOMEDRIVE" with
| None -> userprofile ()
| Some homedrive ->
match getenv "HOMEPATH" with
| None -> userprofile ()
| Some homepath ->
let dir = Filename.concat homedrive homepath in
if Sys.file_exists dir then Some dir else userprofile ()
in
let config_dir () = match getenv "XDG_CONFIG_HOME" with
| Some dir -> Some dir
| None when Sys.win32 -> getenv "%LOCALAPPDATA%"
| None -> None
if not Sys.win32 then None else
match getenv "LOCALAPPDATA" with
| Some _ as v -> v
| None -> get_env "APPDATA"
in
let init_ml = Filename.concat "ocaml" "init.ml" in
match exists_in_dir (config_dir ()) init_ml with
Expand Down

0 comments on commit 71ca21e

Please sign in to comment.