Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utop command in emacs #4

Closed
newsomc opened this issue Mar 8, 2013 · 17 comments
Closed

utop command in emacs #4

newsomc opened this issue Mar 8, 2013 · 17 comments

Comments

@newsomc
Copy link

newsomc commented Mar 8, 2013

Thank you for providing Emacs support! But I'm not sure I understand the instructions...what do you mean by executing "utop" in emacs? Do you mean M-x utop? If so that doesn't seem to work for me.

I installed utop via opam like this:

$ opam init $ opam switch 4.00.1+short-types $ opam install utop core_extended $ eval `opam config -env`

I have an .omalinit that looks like this:

# use "topfind" # camlp4o # thread # require "core.top"

When I run M-x utop I get

Cannot open load file: utop

Thanks for your help,

C

@ghost ghost self-assigned this Mar 8, 2013
@ghost
Copy link

ghost commented Mar 8, 2013

Do you mean M-x utop?

Yes.

opam install utop will install utop.el into the opam prefix, so by default the file will be ~/.opam/system/share/emacs/site-lisp/utop.el. You need to ensure that this path is your emacs load path. You can add this to your .emacs:

(push "~/.opam/system/share/emacs/site-lisp" load-path)

In your case replace system by 4.00.1+short-types. I'll add a note about this in the readme.

@ghost
Copy link

ghost commented Mar 8, 2013

And to dynamically find the right location:

(let ((opam-prefix
       (replace-regexp-in-string
        "[ \r\n\t]*$" ""
        (with-output-to-string
          (with-current-buffer
              standard-output
            (call-process "opam" nil t nil "config" "var" "prefix"))))))
  (push (concat opam-prefix "/share/emacs/site-lisp") load-path))

@newsomc
Copy link
Author

newsomc commented Mar 8, 2013

Thanks a bunch for your help with this. I'm not quite there yet. This is my current Ocaml config for emacs:

(push "~/.opam/4.00.1+short-types/share/emacs/site-lisp/" load-path)
(let ((opam-prefix
       (replace-regexp-in-string
        "[ \r\n\t]*$" ""
        (with-output-to-string
          (with-current-buffer
              standard-output
            (call-process "opam" nil t nil "config" "var" "prefix"))))))
  (push (concat opam-prefix "/share/emacs/site-lisp") load-path))
(autoload 'utop "utop" "Toplevel for OCaml" t)
(autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)

The error I get when attempting to eval the let statement is this:

Debugger entered--Lisp error: (file-error "Searching for program" "No such file or directory" "opam") call-process("opam" nil t nil "config" "var" "prefix") (save-current-buffer (set-buffer standard-output) (call-process "opam" nil t nil "config" "var" "prefix")) (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix")) (let ((standard-output standard-output)) (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix"))) (progn (let ((standard-output standard-output)) (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix"))) (with-current-buffer standard-output (buffer-string))) (unwind-protect (progn (let ((standard-output standard-output)) (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix"))) (with-current-buffer standard-output (buffer-string))) (kill-buffer standard-output)) (let ((standard-output (get-buffer-create (generate-new-buffer-name " _string-output_")))) (unwind-protect (progn (let ((standard-output standard-output)) (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix"))) (with-current-buffer standard-output (buffer-string))) (kill-buffer standard-output))) (with-output-to-string (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix"))) (replace-regexp-in-string "[ \n ]_$" "" (with-output-to-string (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix")))) (let ((opam-prefix (replace-regexp-in-string "[ \n ]_$" "" (with-output-to-string (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix")))))) (push (concat opam-prefix "/share/emacs/site-lisp") load-path)) eval((let ((opam-prefix (replace-regexp-in-string "[ \n ]*$" "" (with-output-to-string (with-current-buffer standard-output (call-process "opam" nil t nil "config" "var" "prefix")))))) (push (concat opam-prefix "/share/emacs/site-lisp") load-path)) nil) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp nil nil)

@ghost
Copy link

ghost commented Mar 8, 2013

Note that you only need one of the two expressions. The second one is if you are using several prefixes and want to automatically find the right one. Regarding the error it seems that "opam" is not in your PATH.

@f6m6
Copy link

f6m6 commented Jun 7, 2013

I'm in basically the same situation - did this get resolved? opam is in my PATH I think as when I run opam from a terminal it works

@newsomc
Copy link
Author

newsomc commented Jun 7, 2013

I wasn't able to resolve.

On Jun 7, 2013, at 9:37 AM, Farhan Mannan notifications@github.com wrote:

I'm in basically the same situation - did this get resolved? opam is in my PATH I think as when I run opam from a terminal it works


Reply to this email directly or view it on GitHub.

@ghost
Copy link

ghost commented Jun 7, 2013

Unfortunately there is nothing that can be done in utop. You have to add this line in your ~/.emacs:

(push "~/.opam/system/share/emacs/site-lisp" load-path)

utop installs the utop.el file into the prefix specified at configuration time.

@f6m6
Copy link

f6m6 commented Jun 23, 2013

I already have that (well actually I have (push "~/.opam/4.01.0dev+trunk/share/emacs/site-lisp" load-path)) but I am getting the same error. Oh well

@ghost
Copy link

ghost commented Jun 24, 2013

Can you check that utop.el is indeed present in this directory? If yes then this is probably an emacs problem not related to utop. You cal also try to load the file by hand with M-x load-file to see if it works.

@newsomc
Copy link
Author

newsomc commented Jun 24, 2013

What version of emacs are you using Jeremie? On what OS?

On Jun 24, 2013, at 1:34 AM, Jérémie Dimino notifications@github.com wrote:

Can you check that utop.el is indeed present in this directory? If yes then this is probably an emacs problem not related to utop. You cal also try to load the file by hand with M-x load-file to see if it works.


Reply to this email directly or view it on GitHub.

@ghost
Copy link

ghost commented Jun 24, 2013

I am using different ones:

  • on my old linux laptop: debian + emacs 24
  • on my MacBook: OS X Mountain Lion + emacs 24

@samebchase
Copy link

I'm having similar problems too. I have been manually able to M-x load-file utop.el.

I was not able to run utop in zsh until OPAM added this line to my .zshrc

. /home/samuel/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true

It seems that script modifies the environment variables necessary for utop to be run.

Attempting to run utop in say M-x eshell gives me the error:
Searching for program: no such file or directory, utop

I think the problem is that the path to utop isn't in the $PATH in the shell emacs uses. How do I do the equivalent of the .zshrc configuration as pasted above, but for the shell emacs uses.

@ghost
Copy link

ghost commented Jul 11, 2013

With a recent opam version you can add in your ~/.emacs:

(dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
  (setenv (car var) (cadr var)))

@samebchase
Copy link

Hello @diml, thanks for the suggestion,

The relevant lines in my .emacs are as follows:

(add-to-list 'load-path "/home/samuel/.opam/4.01.0dev+trunk/share/emacs/site-lisp/")
(autoload 'utop "utop" "Toplevel for OCaml" t)
(autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)

(dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
  (setenv (car var) (cadr var)))

Does that look right?

The utop command runs in eshell now, but as usual, doing an M-x utop gives me the error: Searching for program: no such file or directory.

@ghost
Copy link

ghost commented Jul 11, 2013

Does that look right?

Yes.

The utop command runs in eshell now, but as usual, doing an M-x utop gives me the error: Searching for program: no such file or directory.

Ah yes, that's because emacs parses PATH only once at startup. You can try to add this at the end:

(setq exec-path (split-string (getenv "PATH") path-separator))

@samebchase
Copy link

Yay. It works now. Thanks a lot @diml. :-)

I'll paste the following as a minimal utop configuration for .emacs that others may find useful:

(add-to-list 'load-path "/home/samuel/.opam/4.01.0dev+trunk/share/emacs/site-lisp/")
(autoload 'utop "utop" "Toplevel for OCaml" t)
(autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)

(dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
  (setenv (car var) (cadr var)))

(setq exec-path (split-string (getenv "PATH") path-separator))

@ghost
Copy link

ghost commented Nov 20, 2013

With the new intrusctions in the README it should now be easier to make utop work with emacs: https://github.com/diml/utop#integration-with-emacs

@ghost ghost closed this as completed Nov 20, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants