xfwduke / ob-erlang

Org-Babel support for evaluating erlang source code.
12 stars 4 forks source link

Documentation for setting erlang executable #1

Open ZelphirKaltstahl opened 4 years ago

ZelphirKaltstahl commented 4 years ago

How do you set the executable used by org-mode for running the source blocks?

I think this would be a good thing to add to the readme file. For example I installed Erlang through Guix package manager, but org-mode seems unable to find it, probably because it is not the kind of installation it expects. It would be good to have a configuration to simply set a path to the executable, which runs the code.

Apteryks commented 4 years ago

As I mentioned on the guix-help mailing list, the problems lies with the PATH environment that your Emacs is using. Your erlang binary was installed in a different profile than Emacs so Emacs doesn't see it unless you "help" it.

I don't think ob-erlang is doing anything wrong here, but perhaps it could allow defining the path of the erlang executables with defcustom.

ZelphirKaltstahl commented 4 years ago

That would be great!

ZelphirKaltstahl commented 3 weeks ago

Huh, how funny: Today I searched for running erlang in org source blocks again and had the same thought: "But how can I set the erlc it is supposed to use?". Clicked on the issues list in the repo and see this issue. Then I see, that I myself created the issue :D

ZelphirKaltstahl commented 3 weeks ago

If one starts Emacs using guix shell as I am doing, then the directory of executables installed via Guix is not so predictable:

#!/usr/bin/env bash

set -Eeuxo pipefail

if [ -z "${1:-}" ] ; then 
    ADDITIONAL_EMACS_ARGS=""
else
    ADDITIONAL_EMACS_ARGS="${1:-}"
fi

EMACS_ARGS="--maximized --debug-init"

GUIX_ENV_DIR="${GUIX_EXTRA_PROFILES}/emacs-env"

guix time-machine \
     --channels="${GUIX_ENV_DIR}/channels.scm" -- \
     shell \
     --manifest="${GUIX_ENV_DIR}/manifest.scm" \
     --cores=8 -- \
     emacs ${EMACS_ARGS} ${ADDITIONAL_EMACS_ARGS}

I guess I would have to use a guix profile instead, so that I can predict where the executables land and add that to PATH when starting emacs. :thinking:

ZelphirKaltstahl commented 2 weeks ago

So, I learned about using guix profiles and managed to create a profile containing emacs and erlang. Then I managed to set the PATH environment variable to contain an additional bin/ directory of a guix profile, which has the erlc executable, before emacs starts. However, trying to run erlang source blocks still does not work and emacs reports not finding erlc, even though it is on the PATH.

I think I will need to investigate how emacs handles the PATH when starting.

ZelphirKaltstahl commented 2 weeks ago

Emacs according to what I read online populates the variable exec-path using the PATH variable. In my project I have a guix profile stored in the project directory (to keep all things local to the project) at guix-profile. I activate that profile:

GUIX_PROFILE="guix-profile" ; . "${GUIX_PROFILE}/etc/profile"

When I then check, where the executables are, all seems well:

$ command -v emacs
guix-profile/bin/emacs
$ command -v erlc
guix-profile/bin/erlc

So I start Emacs from that shell, with activated/sourced guix profile. However, when I try to run an erlang source block, I still get the error:

/usr/bin/bash: line 1: erlc: command not found
[ Babel evaluation exited with code 127 ]
/usr/bin/bash: line 1: erl: command not found
[ Babel evaluation exited with code 127 ]

Seems buggy then. Which environment is the running of a source block acting in? Shouldn't Emacs now be able to find the executables?

Even when I explicitly set the PATH to contain this bin directory:

PATH="guix-profile/bin:${PATH}" ; \
emacs \
    --init-directory emacs \
    --maximized \
    --debug-init \
    --no-site-lisp \
    --no-splash \
    --no-desktop \
    --chdir "."

it does not find the erlc executable. The directory is also listed in the value of exec-path:

exec-path is a variable defined in ‘C source code’.

Its value is
("guix-profile/bin" ... )
...