Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

What about to compile and load code directly from source file we edit? #38

Closed
davidqo opened this Issue Mar 3, 2014 · 11 comments

Comments

Projects
None yet
3 participants

davidqo commented Mar 3, 2014

src/distel.erl

- reload_module(Mod, File) ->
-    case c:l(to_atom(Mod)) of
-        {error,R} ->
-            case Mod == basename(File,".erl") of
-                true ->
-                    Beams = [join([dirname(File),Mod]),
-                             join([dirname(dirname(File)),ebin,Mod])],
-                        case filter(fun is_beam/1, Beams) of
-                            [] -> {error, R};
-                            [Beam|_] ->
-                                code:add_patha(dirname(Beam)),
-                                c:l(to_atom(Mod))
-                        end;
-                false ->
-                    {error,modname_and_filename_differs}
-            end;
-        R -> R
-    end.
+    c:c(File, [debug_info, {outdir, dirname(File)}]).

Maybe there is another way to do what i want?
It is useful for me. What about to add this functionality in distel?

Owner

massemanet commented Mar 4, 2014

Are you familiar with C-c C-d L ?

"erl-reload-module is an interactive Lisp function in `erl-service.el'.

It is bound to C-c C-d L,
.

(erl-reload-module NODE MODULE)

Reload a module."

On Mon, Mar 3, 2014 at 11:17 AM, davidqo notifications@github.com wrote:

src/distel.erl

  • reload_module(Mod, File) ->
  • case c:l(to_atom(Mod)) of
  • {error,R} ->
  • case Mod == basename(File,".erl") of
  • true ->
  • Beams = [join([dirname(File),Mod]),
  • join([dirname(dirname(File)),ebin,Mod])],
  • case filter(fun is_beam/1, Beams) of
  • [] -> {error, R};
  • [Beam|_] ->
  • code:add_patha(dirname(Beam)),
  • c:l(to_atom(Mod))
  • end;
  • false ->
  • {error,modname_and_filename_differs}
  • end;
  • R -> R
  • end.
  • c:c(File, [debug_info, {outdir, dirname(File)}]). Maybe there is
    another way to do what i want? It is useful for me. What about to add this
    functionality in distel?

Reply to this email directly or view it on GitHubhttps://github.com/massemanet/distel/issues/38
.

davidqo commented Mar 5, 2014

Yes, but as I can understand it reloads module from code path or ebin directory and not recompile it. Am I right? I had some problems with reloading module due non-standard directory of beam files (it builds to separate folder, not in OTP project stucture). What about to compile and load module that is edited currently i.e. like that c:c(File, [debug_info, {outdir, dirname(File)}])? I think it is very useful: change one code line, press some hotkey and voila! - we see result on launched system. Is it possible to do so in distel?

Owner

massemanet commented Mar 5, 2014

so, just to be clear;
you want to ship the code in the emacs buffer to erl, compile and load,
potentially overwriting beam code that was loaded from the load path?

On Wed, Mar 5, 2014 at 3:35 AM, davidqo notifications@github.com wrote:

Yes, but as I can understand it reloads module from code path or ebin
directory and not recompile it. Am I right? I had some problems with
reloading module due non-standard directory of beam files (it builds to
separate folder, not in OTP project stucture). What about to compile and
load module that is editing currently i.e. like that c:c(File, [debug_info,
{outdir, dirname(File)}])? I think it is very useful: change one code line,
press some hotkey and voila! - we see result on launched system. Is it
possible to do so in distel?

Reply to this email directly or view it on GitHubhttps://github.com/massemanet/distel/issues/38#issuecomment-36704398
.

davidqo commented Mar 6, 2014

Yes or compile and load file associated with buffer I edit from filesystem, not directly from buffer - not a big difference. I write many commands for CLI and I need frequently load my code to check it. Or another case - I suspect a bug in some library, and I want to fix it quickly and load changed code, to check how it works after my changes. Whith this feature i could do it very quickly. If I can load code directly from buffer - not from file on filesystem, it would be even cooler, because it is not neccessary to worry about write permissions on file (e.g. it located in /usr/local/lib/blabla...).

dLuna commented Mar 7, 2014

I use http://erlang.org/pipermail/erlang-questions/2004-November/013577.html to load changes in code. (With the addition of lm() -> [l(M) || M <- mm()].)

I then have a makefile target that calls this from the outside. If you use rebar the following should work from make:

escript rel/files/nodetool $$nodename $$cookie rpcterms user_default lm ""

So not an emacs solution but works well for me. (I would call this from emacs using M-x compile)

dLuna commented Mar 7, 2014

Btw. I'm usually loading the current buffer into my system using C-c C-k, but I have no idea if this is a default config of distel, or because I've done some magical configuration somewhere (can't find anything in my .emacs, so probably built into distel).

davidqo commented Mar 7, 2014

I just looked C-h k C-c C-k in emacs and as I can see it is erlang-compile from erlang.el which is part of tools/emacs. I don't know why but it not works for me - it compiles module but not loads it into my system. So as seen in first message, I have added some changes in src/distel.erl and distel began to do what I need (with some additional manipulations in *.el files). Is it proper way? My patch looks ugly due I'm not have proper skills in lisp =)

davidqo commented Mar 7, 2014

massemanet, what are you mean when tell "overwrite beam code"? Overwrite on filesystem? No I don't) I just want to do hot code loading. That's why I compile module at the same folder where associated with emacs buffer source file located.

davidqo commented Mar 7, 2014

c:c(File, [debug_info, {outdir, dirname(File)}]). - loads code from the same folder where source file located - it is not need to overwrite code in load path.

dLuna commented Mar 7, 2014

If you run your system inside emacs it will also load the now code. If you run it outside I recommend the abovementioned solution or something similar.

davidqo commented Mar 8, 2014

dLuna, ok) I'll try to load my system inside emacs.

@davidqo davidqo closed this Sep 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment