caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Setting up OPAM in emacs
@ 2013-05-28  5:59 Ivan Gotovchits
  2013-05-28  8:05 ` Daniel Bünzli
       [not found] ` <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be>
  0 siblings, 2 replies; 13+ messages in thread
From: Ivan Gotovchits @ 2013-05-28  5:59 UTC (permalink / raw)
  To: caml-list


I've failed to find a good solution for using emacs and opam together (in linux). 

Several options were considered:

1. Start emacs from a properly set up shell. 
   This works fine until you start using «opam swith» oftenly. Restarting emacs
   is not an option for me, because I use it in a daemon mode.

2. Use «eval `opam env config`» in the begining of a compile-command.
   This works fine when you switch compiler, but other commands, such as
   «C-c C-s» doesn't use new environment.


Has anybody solved this problems? I think there should be an easy
solution, but I cannot find it myself, due to lack of good knowledge of
both opam and emacs-lisp. 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-05-28  5:59 [Caml-list] Setting up OPAM in emacs Ivan Gotovchits
@ 2013-05-28  8:05 ` Daniel Bünzli
       [not found] ` <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be>
  1 sibling, 0 replies; 13+ messages in thread
From: Daniel Bünzli @ 2013-05-28  8:05 UTC (permalink / raw)
  To: Ivan Gotovchits; +Cc: caml-list

Le mardi, 28 mai 2013 à 06:59, Ivan Gotovchits a écrit :
> Has anybody solved this problems? I think there should be an easy
> solution, but I cannot find it myself, due to lack of good knowledge of
> both opam and emacs-lisp.

I'm not sure this will solve your problem as I don't really use opam switch. But the instructions for osx may be useful, basically make sure that emacs' shells are invoked as login shells:

https://github.com/OCamlPro/opam/wiki/Setup-Emacs.app-on-macosx-for-opam-usage

Best,

Daniel



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
       [not found] ` <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be>
@ 2013-05-29 21:39   ` Wojciech Meyer
  2013-06-04 14:55     ` Leo White
  0 siblings, 1 reply; 13+ messages in thread
From: Wojciech Meyer @ 2013-05-29 21:39 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: ivg, caml-list

Christophe's function hook is probably much better and elegant solution,
but this works for me:

>>
(defun dm-opam-switch-root (ocaml-version opam-root)
  (interactive "sOCaml version: \nsOPAM root: ")
  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
         (entry
          (replace-regexp-in-string
           "\n" ""
           (shell-command-to-string
            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
    (setq exec-path (cons entry path))
    (setenv "PATH" env-path)))

(defun dm-opam-switch (ocaml-version)
  (interactive "sOCaml version: ")
  (dm-opam-switch-root ocaml-version "~/.opam"))
<<

I wouldn't say myself it's a perfect script, but it works. Note that I
use a lot of shell trickery instead of Emacs buffers, which is probably
not a good idea.

You just say M-x dm-opam-switch, and indicate which version you would
like.

Best,
Wojciech

Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:

> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>
>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>    This works fine when you switch compiler, but other commands, such as
>>    «C-c C-s» doesn't use new environment.
>
> I use this for the compilation:
>
>     ;; OPAM compilation — one must update to the current compiler
>     ;; before launching the compilation.
>     (defadvice compile (before compile-opam activate)
>       "Run opam to update environment variables"
>       (set (make-local-variable 'compilation-environment)
> 	   (with-temp-buffer
> 	     (ignore-errors (call-process "opam" nil t nil "config" "-env"))
> 	     (goto-char (point-min))
> 	     (while (re-search-forward "; *export.*$" nil t)
> 	       (replace-match "" nil nil))
> 	     (split-string (buffer-substring 1 (point-max)))
> 	     )))
>
> For the toplevel, I am afraid one needs to restart it.  I guess a
> similar trick is possible to automatically select the right one.
>
> Hope it helps,
> C.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-05-29 21:39   ` Wojciech Meyer
@ 2013-06-04 14:55     ` Leo White
  2013-06-15 12:07       ` Gabriel Scherer
  2013-06-19 16:06       ` Ivan Gotovchits
  0 siblings, 2 replies; 13+ messages in thread
From: Leo White @ 2013-06-04 14:55 UTC (permalink / raw)
  To: Wojciech Meyer; +Cc: Christophe TROESTLER, ivg, caml-list

My personal solution for Tuareg mode is to put:

  ;; Use OPAM's ocaml
  (setq tuareg-interactive-program "opam config exec ocaml")

in my .emacs.

Regards,

Leo

Wojciech Meyer <wojciech.meyer@gmail.com> writes:

> Christophe's function hook is probably much better and elegant solution,
> but this works for me:
>
>>>
> (defun dm-opam-switch-root (ocaml-version opam-root)
>   (interactive "sOCaml version: \nsOPAM root: ")
>   (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>          (entry
>           (replace-regexp-in-string
>            "\n" ""
>            (shell-command-to-string
>             (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>          (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>     (setq exec-path (cons entry path))
>     (setenv "PATH" env-path)))
>
> (defun dm-opam-switch (ocaml-version)
>   (interactive "sOCaml version: ")
>   (dm-opam-switch-root ocaml-version "~/.opam"))
> <<
>
> I wouldn't say myself it's a perfect script, but it works. Note that I
> use a lot of shell trickery instead of Emacs buffers, which is probably
> not a good idea.
>
> You just say M-x dm-opam-switch, and indicate which version you would
> like.
>
> Best,
> Wojciech
>
> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>
>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>
>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>    This works fine when you switch compiler, but other commands, such as
>>>    «C-c C-s» doesn't use new environment.
>>
>> I use this for the compilation:
>>
>>     ;; OPAM compilation — one must update to the current compiler
>>     ;; before launching the compilation.
>>     (defadvice compile (before compile-opam activate)
>>       "Run opam to update environment variables"
>>       (set (make-local-variable 'compilation-environment)
>> 	   (with-temp-buffer
>> 	     (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>> 	     (goto-char (point-min))
>> 	     (while (re-search-forward "; *export.*$" nil t)
>> 	       (replace-match "" nil nil))
>> 	     (split-string (buffer-substring 1 (point-max)))
>> 	     )))
>>
>> For the toplevel, I am afraid one needs to restart it.  I guess a
>> similar trick is possible to automatically select the right one.
>>
>> Hope it helps,
>> C.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-04 14:55     ` Leo White
@ 2013-06-15 12:07       ` Gabriel Scherer
  2013-06-15 15:14         ` [opam-devel] " Anil Madhavapeddy
                           ` (3 more replies)
  2013-06-19 16:06       ` Ivan Gotovchits
  1 sibling, 4 replies; 13+ messages in thread
From: Gabriel Scherer @ 2013-06-15 12:07 UTC (permalink / raw)
  To: caml users
  Cc: Wojciech Meyer, Christophe TROESTLER, ivg, Leo White, opam-devel

I don't (want to) understand the details of why opam switches don't
work well with Emacs right now, or of any of the proposed solutions.
Is there a solution integrated in OPAM by now? If not, is there a
consensus on what simple users like me should use to solve the
problem? Could you (the thread participants) decide on something, and
send that to the OPAM upstream, so that future versions solve this
issue?

(The immediate problem I observe is that compile-command does not use
the OCaml versions I would expect it to, in general defaulting to my
system OCaml -- that may depend on the way Emacs is launched. More
sophisticated things such as being able to call "opam switch" from
inside Emacs are probably secondary needs, and I would be fine with a
basic integration not supporting that, and letting people hone their
emacs-lisp skills for that.)

On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
> My personal solution for Tuareg mode is to put:
>
>   ;; Use OPAM's ocaml
>   (setq tuareg-interactive-program "opam config exec ocaml")
>
> in my .emacs.
>
> Regards,
>
> Leo
>
> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>
>> Christophe's function hook is probably much better and elegant solution,
>> but this works for me:
>>
>>>>
>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>   (interactive "sOCaml version: \nsOPAM root: ")
>>   (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>          (entry
>>           (replace-regexp-in-string
>>            "\n" ""
>>            (shell-command-to-string
>>             (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>          (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>     (setq exec-path (cons entry path))
>>     (setenv "PATH" env-path)))
>>
>> (defun dm-opam-switch (ocaml-version)
>>   (interactive "sOCaml version: ")
>>   (dm-opam-switch-root ocaml-version "~/.opam"))
>> <<
>>
>> I wouldn't say myself it's a perfect script, but it works. Note that I
>> use a lot of shell trickery instead of Emacs buffers, which is probably
>> not a good idea.
>>
>> You just say M-x dm-opam-switch, and indicate which version you would
>> like.
>>
>> Best,
>> Wojciech
>>
>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>
>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>
>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>    This works fine when you switch compiler, but other commands, such as
>>>>    «C-c C-s» doesn't use new environment.
>>>
>>> I use this for the compilation:
>>>
>>>     ;; OPAM compilation — one must update to the current compiler
>>>     ;; before launching the compilation.
>>>     (defadvice compile (before compile-opam activate)
>>>       "Run opam to update environment variables"
>>>       (set (make-local-variable 'compilation-environment)
>>>         (with-temp-buffer
>>>           (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>           (goto-char (point-min))
>>>           (while (re-search-forward "; *export.*$" nil t)
>>>             (replace-match "" nil nil))
>>>           (split-string (buffer-substring 1 (point-max)))
>>>           )))
>>>
>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>> similar trick is possible to automatically select the right one.
>>>
>>> Hope it helps,
>>> C.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [opam-devel] [Caml-list] Setting up OPAM in emacs
  2013-06-15 12:07       ` Gabriel Scherer
@ 2013-06-15 15:14         ` Anil Madhavapeddy
  2013-06-19 16:24           ` Leo White
  2013-06-19 16:05         ` Ivan Gotovchits
                           ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Anil Madhavapeddy @ 2013-06-15 15:14 UTC (permalink / raw)
  To: Gabriel Scherer
  Cc: caml users, Leo White, ivg, opam-devel, Christophe TROESTLER,
	Wojciech Meyer

I don't use Emacs, but OPAM has several global command-line options that
may make your OS^H^Heditor integration easier.

* --root will set the home directory of OPAM (~/.opam by default)

* --switch will explicitly run the command under a compiler switch that
  isn't the default one, but without performing a global switch.

* "opam config exec" will run the sub-command with the right environment
  variables set to the selected switch.  So:

    $ opam config exec "ocamlc -version"

  will get the version of the current OPAM switch ocaml, irrespective
  of your PATH settings. (This is what Leo is doing for his interactive
  shell below, but I'm not sure how this interacts with the rest of 
  Tuareg).

I would appreciate an Emacs user summarising best practises here and
letting me know so that I can include a short summary in Real World OCaml.

best,
Anil

On 15 Jun 2013, at 13:07, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:

> I don't (want to) understand the details of why opam switches don't
> work well with Emacs right now, or of any of the proposed solutions.
> Is there a solution integrated in OPAM by now? If not, is there a
> consensus on what simple users like me should use to solve the
> problem? Could you (the thread participants) decide on something, and
> send that to the OPAM upstream, so that future versions solve this
> issue?
> 
> (The immediate problem I observe is that compile-command does not use
> the OCaml versions I would expect it to, in general defaulting to my
> system OCaml -- that may depend on the way Emacs is launched. More
> sophisticated things such as being able to call "opam switch" from
> inside Emacs are probably secondary needs, and I would be fine with a
> basic integration not supporting that, and letting people hone their
> emacs-lisp skills for that.)
> 
> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>> My personal solution for Tuareg mode is to put:
>> 
>>  ;; Use OPAM's ocaml
>>  (setq tuareg-interactive-program "opam config exec ocaml")
>> 
>> in my .emacs.
>> 
>> Regards,
>> 
>> Leo
>> 
>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>> 
>>> Christophe's function hook is probably much better and elegant solution,
>>> but this works for me:
>>> 
>>>>> 
>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>>  (interactive "sOCaml version: \nsOPAM root: ")
>>>  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>         (entry
>>>          (replace-regexp-in-string
>>>           "\n" ""
>>>           (shell-command-to-string
>>>            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>    (setq exec-path (cons entry path))
>>>    (setenv "PATH" env-path)))
>>> 
>>> (defun dm-opam-switch (ocaml-version)
>>>  (interactive "sOCaml version: ")
>>>  (dm-opam-switch-root ocaml-version "~/.opam"))
>>> <<
>>> 
>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>> not a good idea.
>>> 
>>> You just say M-x dm-opam-switch, and indicate which version you would
>>> like.
>>> 
>>> Best,
>>> Wojciech
>>> 
>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>> 
>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>> 
>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>   This works fine when you switch compiler, but other commands, such as
>>>>>   «C-c C-s» doesn't use new environment.
>>>> 
>>>> I use this for the compilation:
>>>> 
>>>>    ;; OPAM compilation — one must update to the current compiler
>>>>    ;; before launching the compilation.
>>>>    (defadvice compile (before compile-opam activate)
>>>>      "Run opam to update environment variables"
>>>>      (set (make-local-variable 'compilation-environment)
>>>>        (with-temp-buffer
>>>>          (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>          (goto-char (point-min))
>>>>          (while (re-search-forward "; *export.*$" nil t)
>>>>            (replace-match "" nil nil))
>>>>          (split-string (buffer-substring 1 (point-max)))
>>>>          )))
>>>> 
>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>> similar trick is possible to automatically select the right one.
>>>> 
>>>> Hope it helps,
>>>> C.
>> 
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
> _______________________________________________
> opam-devel mailing list
> opam-devel@lists.ocaml.org
> http://lists.ocaml.org/listinfo/opam-devel
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-15 12:07       ` Gabriel Scherer
  2013-06-15 15:14         ` [opam-devel] " Anil Madhavapeddy
@ 2013-06-19 16:05         ` Ivan Gotovchits
  2013-06-19 16:06         ` [opam-devel] " Ivan Gotovchits
  2013-06-19 16:49         ` Ivan Gotovchits
  3 siblings, 0 replies; 13+ messages in thread
From: Ivan Gotovchits @ 2013-06-19 16:05 UTC (permalink / raw)
  To: Gabriel Scherer
  Cc: caml users, Wojciech Meyer, Christophe TROESTLER, Leo White, opam-devel

I've chosen  the simplest solution, that is not very versatile, but it works.

Though there were provided some elegant solutions, I cannot found one that would mix well 
with a typerex 2.0, which enforces its own rules.

So, my working scheme (works on linux and mac (with issues on the later)

0. clean up the system (remove old typerex, tuareg and whatever you've tried…)
1.  

On Jun 15, 2013, at 16:07, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:

> I don't (want to) understand the details of why opam switches don't
> work well with Emacs right now, or of any of the proposed solutions.
> Is there a solution integrated in OPAM by now? If not, is there a
> consensus on what simple users like me should use to solve the
> problem? Could you (the thread participants) decide on something, and
> send that to the OPAM upstream, so that future versions solve this
> issue?
> 
> (The immediate problem I observe is that compile-command does not use
> the OCaml versions I would expect it to, in general defaulting to my
> system OCaml -- that may depend on the way Emacs is launched. More
> sophisticated things such as being able to call "opam switch" from
> inside Emacs are probably secondary needs, and I would be fine with a
> basic integration not supporting that, and letting people hone their
> emacs-lisp skills for that.)
> 
> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>> My personal solution for Tuareg mode is to put:
>> 
>>  ;; Use OPAM's ocaml
>>  (setq tuareg-interactive-program "opam config exec ocaml")
>> 
>> in my .emacs.
>> 
>> Regards,
>> 
>> Leo
>> 
>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>> 
>>> Christophe's function hook is probably much better and elegant solution,
>>> but this works for me:
>>> 
>>>>> 
>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>>  (interactive "sOCaml version: \nsOPAM root: ")
>>>  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>         (entry
>>>          (replace-regexp-in-string
>>>           "\n" ""
>>>           (shell-command-to-string
>>>            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>    (setq exec-path (cons entry path))
>>>    (setenv "PATH" env-path)))
>>> 
>>> (defun dm-opam-switch (ocaml-version)
>>>  (interactive "sOCaml version: ")
>>>  (dm-opam-switch-root ocaml-version "~/.opam"))
>>> <<
>>> 
>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>> not a good idea.
>>> 
>>> You just say M-x dm-opam-switch, and indicate which version you would
>>> like.
>>> 
>>> Best,
>>> Wojciech
>>> 
>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>> 
>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>> 
>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>   This works fine when you switch compiler, but other commands, such as
>>>>>   «C-c C-s» doesn't use new environment.
>>>> 
>>>> I use this for the compilation:
>>>> 
>>>>    ;; OPAM compilation — one must update to the current compiler
>>>>    ;; before launching the compilation.
>>>>    (defadvice compile (before compile-opam activate)
>>>>      "Run opam to update environment variables"
>>>>      (set (make-local-variable 'compilation-environment)
>>>>        (with-temp-buffer
>>>>          (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>          (goto-char (point-min))
>>>>          (while (re-search-forward "; *export.*$" nil t)
>>>>            (replace-match "" nil nil))
>>>>          (split-string (buffer-substring 1 (point-max)))
>>>>          )))
>>>> 
>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>> similar trick is possible to automatically select the right one.
>>>> 
>>>> Hope it helps,
>>>> C.
>> 
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [opam-devel] [Caml-list] Setting up OPAM in emacs
  2013-06-15 12:07       ` Gabriel Scherer
  2013-06-15 15:14         ` [opam-devel] " Anil Madhavapeddy
  2013-06-19 16:05         ` Ivan Gotovchits
@ 2013-06-19 16:06         ` Ivan Gotovchits
  2013-06-19 16:49         ` Ivan Gotovchits
  3 siblings, 0 replies; 13+ messages in thread
From: Ivan Gotovchits @ 2013-06-19 16:06 UTC (permalink / raw)
  To: Gabriel Scherer
  Cc: caml users, Leo White, ivg, opam-devel, Christophe TROESTLER,
	Wojciech Meyer

I don't use Emacs, but OPAM has several global command-line options that
may make your OS^H^Heditor integration easier.

* --root will set the home directory of OPAM (~/.opam by default)

* --switch will explicitly run the command under a compiler switch that
 isn't the default one, but without performing a global switch.

* "opam config exec" will run the sub-command with the right environment
 variables set to the selected switch.  So:

   $ opam config exec "ocamlc -version"

 will get the version of the current OPAM switch ocaml, irrespective
 of your PATH settings. (This is what Leo is doing for his interactive
 shell below, but I'm not sure how this interacts with the rest of 
 Tuareg).

I would appreciate an Emacs user summarising best practises here and
letting me know so that I can include a short summary in Real World OCaml.

best,
Anil

On 15 Jun 2013, at 13:07, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:

> I don't (want to) understand the details of why opam switches don't
> work well with Emacs right now, or of any of the proposed solutions.
> Is there a solution integrated in OPAM by now? If not, is there a
> consensus on what simple users like me should use to solve the
> problem? Could you (the thread participants) decide on something, and
> send that to the OPAM upstream, so that future versions solve this
> issue?
> 
> (The immediate problem I observe is that compile-command does not use
> the OCaml versions I would expect it to, in general defaulting to my
> system OCaml -- that may depend on the way Emacs is launched. More
> sophisticated things such as being able to call "opam switch" from
> inside Emacs are probably secondary needs, and I would be fine with a
> basic integration not supporting that, and letting people hone their
> emacs-lisp skills for that.)
> 
> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>> My personal solution for Tuareg mode is to put:
>> 
>> ;; Use OPAM's ocaml
>> (setq tuareg-interactive-program "opam config exec ocaml")
>> 
>> in my .emacs.
>> 
>> Regards,
>> 
>> Leo
>> 
>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>> 
>>> Christophe's function hook is probably much better and elegant solution,
>>> but this works for me:
>>> 
>>>>> 
>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>> (interactive "sOCaml version: \nsOPAM root: ")
>>> (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>        (entry
>>>         (replace-regexp-in-string
>>>          "\n" ""
>>>          (shell-command-to-string
>>>           (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>        (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>   (setq exec-path (cons entry path))
>>>   (setenv "PATH" env-path)))
>>> 
>>> (defun dm-opam-switch (ocaml-version)
>>> (interactive "sOCaml version: ")
>>> (dm-opam-switch-root ocaml-version "~/.opam"))
>>> <<
>>> 
>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>> not a good idea.
>>> 
>>> You just say M-x dm-opam-switch, and indicate which version you would
>>> like.
>>> 
>>> Best,
>>> Wojciech
>>> 
>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>> 
>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>> 
>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>  This works fine when you switch compiler, but other commands, such as
>>>>>  «C-c C-s» doesn't use new environment.
>>>> 
>>>> I use this for the compilation:
>>>> 
>>>>   ;; OPAM compilation — one must update to the current compiler
>>>>   ;; before launching the compilation.
>>>>   (defadvice compile (before compile-opam activate)
>>>>     "Run opam to update environment variables"
>>>>     (set (make-local-variable 'compilation-environment)
>>>>       (with-temp-buffer
>>>>         (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>         (goto-char (point-min))
>>>>         (while (re-search-forward "; *export.*$" nil t)
>>>>           (replace-match "" nil nil))
>>>>         (split-string (buffer-substring 1 (point-max)))
>>>>         )))
>>>> 
>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>> similar trick is possible to automatically select the right one.
>>>> 
>>>> Hope it helps,
>>>> C.
>> 
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
> _______________________________________________
> opam-devel mailing list
> opam-devel@lists.ocaml.org
> http://lists.ocaml.org/listinfo/opam-devel
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-04 14:55     ` Leo White
  2013-06-15 12:07       ` Gabriel Scherer
@ 2013-06-19 16:06       ` Ivan Gotovchits
  2013-06-20  1:10         ` Francois Berenger
  1 sibling, 1 reply; 13+ messages in thread
From: Ivan Gotovchits @ 2013-06-19 16:06 UTC (permalink / raw)
  To: caml users
  Cc: Wojciech Meyer, Christophe TROESTLER, ivg, Leo White, opam-devel

I don't (want to) understand the details of why opam switches don't
work well with Emacs right now, or of any of the proposed solutions.
Is there a solution integrated in OPAM by now? If not, is there a
consensus on what simple users like me should use to solve the
problem? Could you (the thread participants) decide on something, and
send that to the OPAM upstream, so that future versions solve this
issue?

(The immediate problem I observe is that compile-command does not use
the OCaml versions I would expect it to, in general defaulting to my
system OCaml -- that may depend on the way Emacs is launched. More
sophisticated things such as being able to call "opam switch" from
inside Emacs are probably secondary needs, and I would be fine with a
basic integration not supporting that, and letting people hone their
emacs-lisp skills for that.)

On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
> My personal solution for Tuareg mode is to put:
> 
>  ;; Use OPAM's ocaml
>  (setq tuareg-interactive-program "opam config exec ocaml")
> 
> in my .emacs.
> 
> Regards,
> 
> Leo
> 
> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
> 
>> Christophe's function hook is probably much better and elegant solution,
>> but this works for me:
>> 
>>>> 
>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>  (interactive "sOCaml version: \nsOPAM root: ")
>>  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>         (entry
>>          (replace-regexp-in-string
>>           "\n" ""
>>           (shell-command-to-string
>>            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>    (setq exec-path (cons entry path))
>>    (setenv "PATH" env-path)))
>> 
>> (defun dm-opam-switch (ocaml-version)
>>  (interactive "sOCaml version: ")
>>  (dm-opam-switch-root ocaml-version "~/.opam"))
>> <<
>> 
>> I wouldn't say myself it's a perfect script, but it works. Note that I
>> use a lot of shell trickery instead of Emacs buffers, which is probably
>> not a good idea.
>> 
>> You just say M-x dm-opam-switch, and indicate which version you would
>> like.
>> 
>> Best,
>> Wojciech
>> 
>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>> 
>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>> 
>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>   This works fine when you switch compiler, but other commands, such as
>>>>   «C-c C-s» doesn't use new environment.
>>> 
>>> I use this for the compilation:
>>> 
>>>    ;; OPAM compilation — one must update to the current compiler
>>>    ;; before launching the compilation.
>>>    (defadvice compile (before compile-opam activate)
>>>      "Run opam to update environment variables"
>>>      (set (make-local-variable 'compilation-environment)
>>>        (with-temp-buffer
>>>          (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>          (goto-char (point-min))
>>>          (while (re-search-forward "; *export.*$" nil t)
>>>            (replace-match "" nil nil))
>>>          (split-string (buffer-substring 1 (point-max)))
>>>          )))
>>> 
>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>> similar trick is possible to automatically select the right one.
>>> 
>>> Hope it helps,
>>> C.
> 
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [opam-devel] [Caml-list] Setting up OPAM in emacs
  2013-06-15 15:14         ` [opam-devel] " Anil Madhavapeddy
@ 2013-06-19 16:24           ` Leo White
  0 siblings, 0 replies; 13+ messages in thread
From: Leo White @ 2013-06-19 16:24 UTC (permalink / raw)
  To: Anil Madhavapeddy
  Cc: Gabriel Scherer, caml users, ivg, opam-devel,
	Christophe TROESTLER, Wojciech Meyer


The development version of OPAM now has a "--sexp" option for "opam
config env". So after the next release putting the following in your
".emacs" file should be sufficient for most users:

  ; Set OPAM environment variables
  (dolist (var (car (read-from-string (shell-command-to-string "opam config env --sexp"))))
    (setenv (car var) (cadr var)))

Regards,

Leo

Anil Madhavapeddy <anil@recoil.org> writes:

> I don't use Emacs, but OPAM has several global command-line options that
> may make your OS^H^Heditor integration easier.
>
> * --root will set the home directory of OPAM (~/.opam by default)
>
> * --switch will explicitly run the command under a compiler switch that
>   isn't the default one, but without performing a global switch.
>
> * "opam config exec" will run the sub-command with the right environment
>   variables set to the selected switch.  So:
>
>     $ opam config exec "ocamlc -version"
>
>   will get the version of the current OPAM switch ocaml, irrespective
>   of your PATH settings. (This is what Leo is doing for his interactive
>   shell below, but I'm not sure how this interacts with the rest of 
>   Tuareg).
>
> I would appreciate an Emacs user summarising best practises here and
> letting me know so that I can include a short summary in Real World OCaml.
>
> best,
> Anil
>
> On 15 Jun 2013, at 13:07, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:
>
>> I don't (want to) understand the details of why opam switches don't
>> work well with Emacs right now, or of any of the proposed solutions.
>> Is there a solution integrated in OPAM by now? If not, is there a
>> consensus on what simple users like me should use to solve the
>> problem? Could you (the thread participants) decide on something, and
>> send that to the OPAM upstream, so that future versions solve this
>> issue?
>> 
>> (The immediate problem I observe is that compile-command does not use
>> the OCaml versions I would expect it to, in general defaulting to my
>> system OCaml -- that may depend on the way Emacs is launched. More
>> sophisticated things such as being able to call "opam switch" from
>> inside Emacs are probably secondary needs, and I would be fine with a
>> basic integration not supporting that, and letting people hone their
>> emacs-lisp skills for that.)
>> 
>> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>>> My personal solution for Tuareg mode is to put:
>>> 
>>>  ;; Use OPAM's ocaml
>>>  (setq tuareg-interactive-program "opam config exec ocaml")
>>> 
>>> in my .emacs.
>>> 
>>> Regards,
>>> 
>>> Leo
>>> 
>>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>>> 
>>>> Christophe's function hook is probably much better and elegant solution,
>>>> but this works for me:
>>>> 
>>>>>> 
>>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>>>  (interactive "sOCaml version: \nsOPAM root: ")
>>>>  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>>         (entry
>>>>          (replace-regexp-in-string
>>>>           "\n" ""
>>>>           (shell-command-to-string
>>>>            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>>         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>>    (setq exec-path (cons entry path))
>>>>    (setenv "PATH" env-path)))
>>>> 
>>>> (defun dm-opam-switch (ocaml-version)
>>>>  (interactive "sOCaml version: ")
>>>>  (dm-opam-switch-root ocaml-version "~/.opam"))
>>>> <<
>>>> 
>>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>>> not a good idea.
>>>> 
>>>> You just say M-x dm-opam-switch, and indicate which version you would
>>>> like.
>>>> 
>>>> Best,
>>>> Wojciech
>>>> 
>>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>>> 
>>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>>> 
>>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>>   This works fine when you switch compiler, but other commands, such as
>>>>>>   «C-c C-s» doesn't use new environment.
>>>>> 
>>>>> I use this for the compilation:
>>>>> 
>>>>>    ;; OPAM compilation — one must update to the current compiler
>>>>>    ;; before launching the compilation.
>>>>>    (defadvice compile (before compile-opam activate)
>>>>>      "Run opam to update environment variables"
>>>>>      (set (make-local-variable 'compilation-environment)
>>>>>        (with-temp-buffer
>>>>>          (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>>          (goto-char (point-min))
>>>>>          (while (re-search-forward "; *export.*$" nil t)
>>>>>            (replace-match "" nil nil))
>>>>>          (split-string (buffer-substring 1 (point-max)))
>>>>>          )))
>>>>> 
>>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>>> similar trick is possible to automatically select the right one.
>>>>> 
>>>>> Hope it helps,
>>>>> C.
>>> 
>>> --
>>> Caml-list mailing list.  Subscription management and archives:
>>> https://sympa.inria.fr/sympa/arc/caml-list
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>> _______________________________________________
>> opam-devel mailing list
>> opam-devel@lists.ocaml.org
>> http://lists.ocaml.org/listinfo/opam-devel
>> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-15 12:07       ` Gabriel Scherer
                           ` (2 preceding siblings ...)
  2013-06-19 16:06         ` [opam-devel] " Ivan Gotovchits
@ 2013-06-19 16:49         ` Ivan Gotovchits
  2013-06-19 16:54           ` Ivan Gotovchits
  3 siblings, 1 reply; 13+ messages in thread
From: Ivan Gotovchits @ 2013-06-19 16:49 UTC (permalink / raw)
  To: Gabriel Scherer
  Cc: caml users, Wojciech Meyer, Christophe TROESTLER, Leo White

I've chosen  the simplest solution, that is not very versatile, but it works.

Though there were provided some elegant solutions, I cannot found one that would mix well 
with a typerex 2.0, which enforces its own rules.

So, my working scheme (works on linux and mac (with issues on the later))

0. clean up the system (remove old typerex, tuareg and whatever you've tried…)

1. install typerex from opam:
    `$ opam install typerex`

2. setup the environment   
    `$ opam config setup -a`

3.  setup the typerex
   `$ ocp-edit-mode install -emacs` 

4.  relogin (or reboot)


Then start emacs in such way, that it can benefit from the configured setup.

In linux I just start emacs as a server:

   `$ emacs --daemon`

and start frames with
    `$ emacsclient -c`

All commands works fine. Though after switching compilers it is needed to restart emacs server.

On mac os I've installed Emacs.App from ports. All of the opam setup works fine, when I start from Terminal with:
   `$ open -a Emacs`

Nothing works if emacs is started from finder or dock.


P.S. I hope that this will help, and I've not missed anything.
P.P.S. For full experience one should use ocp-build. I'm experimenting with it. It looks very nice, 
but I still can't find how to enable syntax preprocessing. May be some clues? 
   

On Jun 15, 2013, at 16:07, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:

> I don't (want to) understand the details of why opam switches don't
> work well with Emacs right now, or of any of the proposed solutions.
> Is there a solution integrated in OPAM by now? If not, is there a
> consensus on what simple users like me should use to solve the
> problem? Could you (the thread participants) decide on something, and
> send that to the OPAM upstream, so that future versions solve this
> issue?
> 
> (The immediate problem I observe is that compile-command does not use
> the OCaml versions I would expect it to, in general defaulting to my
> system OCaml -- that may depend on the way Emacs is launched. More
> sophisticated things such as being able to call "opam switch" from
> inside Emacs are probably secondary needs, and I would be fine with a
> basic integration not supporting that, and letting people hone their
> emacs-lisp skills for that.)
> 
> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>> My personal solution for Tuareg mode is to put:
>> 
>>  ;; Use OPAM's ocaml
>>  (setq tuareg-interactive-program "opam config exec ocaml")
>> 
>> in my .emacs.
>> 
>> Regards,
>> 
>> Leo
>> 
>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>> 
>>> Christophe's function hook is probably much better and elegant solution,
>>> but this works for me:
>>> 
>>>>> 
>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>>  (interactive "sOCaml version: \nsOPAM root: ")
>>>  (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>         (entry
>>>          (replace-regexp-in-string
>>>           "\n" ""
>>>           (shell-command-to-string
>>>            (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>         (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>    (setq exec-path (cons entry path))
>>>    (setenv "PATH" env-path)))
>>> 
>>> (defun dm-opam-switch (ocaml-version)
>>>  (interactive "sOCaml version: ")
>>>  (dm-opam-switch-root ocaml-version "~/.opam"))
>>> <<
>>> 
>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>> not a good idea.
>>> 
>>> You just say M-x dm-opam-switch, and indicate which version you would
>>> like.
>>> 
>>> Best,
>>> Wojciech
>>> 
>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>> 
>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>> 
>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>   This works fine when you switch compiler, but other commands, such as
>>>>>   «C-c C-s» doesn't use new environment.
>>>> 
>>>> I use this for the compilation:
>>>> 
>>>>    ;; OPAM compilation — one must update to the current compiler
>>>>    ;; before launching the compilation.
>>>>    (defadvice compile (before compile-opam activate)
>>>>      "Run opam to update environment variables"
>>>>      (set (make-local-variable 'compilation-environment)
>>>>        (with-temp-buffer
>>>>          (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>          (goto-char (point-min))
>>>>          (while (re-search-forward "; *export.*$" nil t)
>>>>            (replace-match "" nil nil))
>>>>          (split-string (buffer-substring 1 (point-max)))
>>>>          )))
>>>> 
>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>> similar trick is possible to automatically select the right one.
>>>> 
>>>> Hope it helps,
>>>> C.
>> 
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-19 16:49         ` Ivan Gotovchits
@ 2013-06-19 16:54           ` Ivan Gotovchits
  0 siblings, 0 replies; 13+ messages in thread
From: Ivan Gotovchits @ 2013-06-19 16:54 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml users

I beg my pardons for this strange flood of messages, that I've accidentally reposted. It seems that my fingers have found a new shortcut, that I've not knew before :-[ Sorry about that.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Caml-list] Setting up OPAM in emacs
  2013-06-19 16:06       ` Ivan Gotovchits
@ 2013-06-20  1:10         ` Francois Berenger
  0 siblings, 0 replies; 13+ messages in thread
From: Francois Berenger @ 2013-06-20  1:10 UTC (permalink / raw)
  To: caml-list

On 06/20/2013 01:06 AM, Ivan Gotovchits wrote:
> I don't (want to) understand the details of why opam switches don't
> work well with Emacs right now,

My guess is that it is because OPAM sets up env. variables
and emacs keep using the ones it knew once it was launched.

 > or of any of the proposed solutions.
> Is there a solution integrated in OPAM by now? If not, is there a
> consensus on what simple users like me should use to solve the
> problem? Could you (the thread participants) decide on something, and
> send that to the OPAM upstream, so that future versions solve this
> issue?
>
> (The immediate problem I observe is that compile-command does not use
> the OCaml versions I would expect it to, in general defaulting to my
> system OCaml -- that may depend on the way Emacs is launched. More
> sophisticated things such as being able to call "opam switch" from
> inside Emacs are probably secondary needs, and I would be fine with a
> basic integration not supporting that, and letting people hone their
> emacs-lisp skills for that.)
>
> On Tue, Jun 4, 2013 at 4:55 PM, Leo White <lpw25@cam.ac.uk> wrote:
>> My personal solution for Tuareg mode is to put:
>>
>>   ;; Use OPAM's ocaml
>>   (setq tuareg-interactive-program "opam config exec ocaml")
>>
>> in my .emacs.
>>
>> Regards,
>>
>> Leo
>>
>> Wojciech Meyer <wojciech.meyer@gmail.com> writes:
>>
>>> Christophe's function hook is probably much better and elegant solution,
>>> but this works for me:
>>>
>>>>>
>>> (defun dm-opam-switch-root (ocaml-version opam-root)
>>>   (interactive "sOCaml version: \nsOPAM root: ")
>>>   (let* ((path (if (string-match "\\.opam" (car exec-path)) (cdr exec-path) exec-path))
>>>          (entry
>>>           (replace-regexp-in-string
>>>            "\n" ""
>>>            (shell-command-to-string
>>>             (format "opam switch --root %s %s > /dev/null && opam config env | sed -n 's/^PATH=\\([^:]\\+\\):.*$/\\1/p'" opam-root ocaml-version))))
>>>          (env-path (replace-regexp-in-string "\n" "" (shell-command-to-string (format "opam config env --root %s | sed -n 's/^PATH=\\(.*\\)/\\1/p'" opam-root)))))
>>>     (setq exec-path (cons entry path))
>>>     (setenv "PATH" env-path)))
>>>
>>> (defun dm-opam-switch (ocaml-version)
>>>   (interactive "sOCaml version: ")
>>>   (dm-opam-switch-root ocaml-version "~/.opam"))
>>> <<
>>>
>>> I wouldn't say myself it's a perfect script, but it works. Note that I
>>> use a lot of shell trickery instead of Emacs buffers, which is probably
>>> not a good idea.
>>>
>>> You just say M-x dm-opam-switch, and indicate which version you would
>>> like.
>>>
>>> Best,
>>> Wojciech
>>>
>>> Christophe TROESTLER <Christophe.Troestler@umons.ac.be> writes:
>>>
>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote:
>>>>>
>>>>> 2. Use «eval `opam env config`» in the begining of a compile-command.
>>>>>    This works fine when you switch compiler, but other commands, such as
>>>>>    «C-c C-s» doesn't use new environment.
>>>>
>>>> I use this for the compilation:
>>>>
>>>>     ;; OPAM compilation — one must update to the current compiler
>>>>     ;; before launching the compilation.
>>>>     (defadvice compile (before compile-opam activate)
>>>>       "Run opam to update environment variables"
>>>>       (set (make-local-variable 'compilation-environment)
>>>>         (with-temp-buffer
>>>>           (ignore-errors (call-process "opam" nil t nil "config" "-env"))
>>>>           (goto-char (point-min))
>>>>           (while (re-search-forward "; *export.*$" nil t)
>>>>             (replace-match "" nil nil))
>>>>           (split-string (buffer-substring 1 (point-max)))
>>>>           )))
>>>>
>>>> For the toplevel, I am afraid one needs to restart it.  I guess a
>>>> similar trick is possible to automatically select the right one.
>>>>
>>>> Hope it helps,
>>>> C.
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-06-20  1:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-28  5:59 [Caml-list] Setting up OPAM in emacs Ivan Gotovchits
2013-05-28  8:05 ` Daniel Bünzli
     [not found] ` <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be>
2013-05-29 21:39   ` Wojciech Meyer
2013-06-04 14:55     ` Leo White
2013-06-15 12:07       ` Gabriel Scherer
2013-06-15 15:14         ` [opam-devel] " Anil Madhavapeddy
2013-06-19 16:24           ` Leo White
2013-06-19 16:05         ` Ivan Gotovchits
2013-06-19 16:06         ` [opam-devel] " Ivan Gotovchits
2013-06-19 16:49         ` Ivan Gotovchits
2013-06-19 16:54           ` Ivan Gotovchits
2013-06-19 16:06       ` Ivan Gotovchits
2013-06-20  1:10         ` Francois Berenger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).