Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add reload() and reload_then()

  • Loading branch information...
commit 81c7692f4b9ed22ee061584001a432578921ad80 1 parent 98af42a
@andrewtj andrewtj authored committed
Showing with 25 additions and 5 deletions.
  1. +9 −4 README.markdown
  2. +16 −1 user_default.erl
View
13 README.markdown
@@ -1,9 +1,14 @@
-These are just a collection of utilities and functions I like to have handy.
+My fork of Jon Gretar's Erlang User Utilities. Read [this blog post](http://medevyoujane.com/blog/2010/1/3/erlang-quick-tip-the-user_default-module.html) for background.
-Put it in ~/.ebin and add it to your code path by putting in ~/.erlang the line:
+ sync() % compiles all files in Emakefile and load into current shell
+ reload() % reload loaded modules
+ reload_then(Fun) % reload then exec a function
+ git(String) % run git command
- code:add_pathz("/Users/username/.ebin").
+
+Add the following to ~/.erlang to enable them:
+
+ code:load_abs("/Path/To/erlang_user_utilities/user_default").
-For info on user\_default and more read [this blog post](http://medevyoujane.com/blog/2010/1/3/erlang-quick-tip-the-user_default-module.html)
View
17 user_default.erl
@@ -1,5 +1,16 @@
-module (user_default).
--export ([sync/0,make/0,git/1]).
+-export ([sync/0,make/0,git/1,reload/0,reload_then/1]).
+
+%% Reload code
+reload() ->
+ LibExclude = base_lib_path(),
+ Modules = [M || {M, P} <- code:all_loaded(), is_list(P) andalso string:str(P, LibExclude) =:= 0],
+ [shell_default:l(M) || M <- Modules].
+
+%% Reload code then exec F
+reload_then(F) ->
+ reload(),
+ F().
%% Compiles all files in Emakefile and load into current shell.
sync() ->
@@ -20,3 +31,7 @@ git(Command) ->
run_command(CommandList) ->
Result = os:cmd(string:join(CommandList, " ")),
io:format("~s~n", [Result]).
+
+base_lib_path() ->
+ KernAppPath = code:where_is_file("kernel.app"),
+ string:substr(KernAppPath, 1, string:str(KernAppPath,"kernel") - 1).
Please sign in to comment.
Something went wrong with that request. Please try again.