Permalink
Browse files

add .erlang user defaults

  • Loading branch information...
martinrehfeld committed Jul 9, 2012
1 parent 726c117 commit dc51bcd4421c597516f171568e5a998fa4bdd498
Showing with 58 additions and 0 deletions.
  1. +2 −0 erlang
  2. +56 −0 erlang-src/user_default.erl
View
2 erlang
@@ -0,0 +1,2 @@
+HomeDir = string:strip(os:cmd("echo $HOME"), right, $\n).
+code:load_abs(HomeDir ++ "/.erlang-ebin/user_default").
@@ -0,0 +1,56 @@
+%%% Pulled from wings3d
+
+-module(user_default).
+-export([lm/0, mm/0, module_modified/1]).
+
+
+%%%
+%%% Load or show modified modules. (Thanks to Vladimir Sekissov.)
+%%%
+lm() ->
+ [c:l(M) || M <- mm()].
+
+mm() ->
+ modified_modules().
+
+modified_modules() ->
+ [M || {M, _} <- code:all_loaded(), module_modified(M) == true].
+
+module_modified(Module) ->
+ case code:is_loaded(Module) of
+ {file, preloaded} ->
+ false;
+ {file, Path} ->
+ CompileOpts = proplists:get_value(compile, Module:module_info()),
+ CompileTime = proplists:get_value(time, CompileOpts),
+ Src = proplists:get_value(source, CompileOpts),
+ module_modified(Path, CompileTime, Src);
+ _ ->
+ false
+ end.
+
+module_modified(Path, PrevCompileTime, PrevSrc) ->
+ case find_module_file(Path) of
+ false ->
+ false;
+ ModPath ->
+ {ok, {_, [{_, CB}]}} = beam_lib:chunks(ModPath, ["CInf"]),
+ CompileOpts = binary_to_term(CB),
+ CompileTime = proplists:get_value(time, CompileOpts),
+ Src = proplists:get_value(source, CompileOpts),
+ not (CompileTime == PrevCompileTime) and (Src == PrevSrc)
+ end.
+
+find_module_file(Path) ->
+ case file:read_file_info(Path) of
+ {ok, _} ->
+ Path;
+ _ ->
+ %% may be the path was changed?
+ case code:where_is_file(filename:basename(Path)) of
+ non_existing ->
+ false;
+ NewPath ->
+ NewPath
+ end
+ end.

0 comments on commit dc51bcd

Please sign in to comment.