Quicky: User_default

Serge Aleynikov <>
Fri Jan 20 23:20:24 CET 2006


Try to specify it without ".erl" extension:

code:load_abs("/home/danx/user_default").

I suggest that you also add a help function to your user_default.erl, so 
that the new command can be shown in the help/0 call within the shell:

help() ->
     shell_default:help(),
     format("** user extended commands **~n"),
     format("mm()   -- DESCRIBE THE COMMAND HERE\n"),
     true.

Regards,

Serge

Chris Campbell wrote:
> Hi,
> 
> How do you load user_default?  The advice in the manual doesn't seem
> to work.  .erlang is read (confirmed with io:format), but it doesn't
> load the user defaults file.  Actually, it may load it but mm(), etc
> don't become available.  This worked before, but I reinstalled
> everything and can't remember the fix.
> 
> 
> Cheers,
> Chris
> 
> ~/.erlang
> 
> code:load_abs("/home/danx/user_default.erl").
> 
> ~/user_default.erl
> 
> -module(user_default).
> -export([mm/0, modified_modules/0, lm/0]).
> 
> 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.
> 
> lm() ->
>     [c:l(M) || M <- mm()].
> 

-- 
Serge Aleynikov
R&D Telecom, IDT Corp.
Tel: (973) 438-3436
Fax: (973) 438-1464




More information about the erlang-questions mailing list