From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5520781792 for ; Wed, 19 Jun 2013 18:25:01 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=pra; client-ip=131.111.8.149; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.149; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@ppsw-42.csi.cam.ac.uk) identity=helo; client-ip=131.111.8.149; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="postmaster@ppsw-42.csi.cam.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhQBAA/awVGDbwiVnGdsb2JhbABagzqDS6l4kiGBFg4BAQEBAQYNCQkUKIIjAQEBAwEBAQEgSwsFCwsYAgIFBB0CAg8BBA0GAR0YExIJh2EDCQYMqhOIXQMKS4gHgSaLN4IyMweCTYEUA5R8XoMQineINA X-IPAS-Result: AhQBAA/awVGDbwiVnGdsb2JhbABagzqDS6l4kiGBFg4BAQEBAQYNCQkUKIIjAQEBAwEBAQEgSwsFCwsYAgIFBB0CAg8BBA0GAR0YExIJh2EDCQYMqhOIXQMKS4gHgSaLN4IyMweCTYEUA5R8XoMQineINA X-IronPort-AV: E=Sophos;i="4.87,898,1363129200"; d="scan'208";a="18323482" Received: from ppsw-mx-f.csi.cam.ac.uk (HELO ppsw-42.csi.cam.ac.uk) ([131.111.8.149]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Jun 2013 18:25:00 +0200 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from kingston.cl.cam.ac.uk ([128.232.64.15]:35422) by ppsw-42.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.159]:587) with esmtpsa (PLAIN:lpw25) (TLSv1.2:DHE-RSA-AES128-SHA:128) id 1UpLBr-00066p-73 (Exim 4.80_167-5a66dd3) (return-path ); Wed, 19 Jun 2013 17:24:59 +0100 From: Leo White To: Anil Madhavapeddy Cc: Gabriel Scherer , caml users , ivg@ieee.org, opam-devel@lists.ocaml.org, Christophe TROESTLER , Wojciech Meyer References: <87li6z8x0m.fsf@ieee.org> <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be> <878v2qj57l.fsf@kingston.cl.cam.ac.uk> X-Face: "XWxb[u_Z\PA_Y?9@|IA!!+jTb(/290-*ea/Un$I0B98.$n%eL.;2w*,z]WR#T:,p[ NBd++M7l]#7zj7!{~iw $W-"/=|dVjhT[D{4~gE}gK<2`.6fs!;uqqud]vs2N/3^m7{aS1V, Date: Wed, 19 Jun 2013 17:24:58 +0100 In-Reply-To: (Anil Madhavapeddy's message of "Sat, 15 Jun 2013 16:14:35 +0100") Message-ID: <87k3lqyso5.fsf@kingston.cl.cam.ac.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [opam-devel] [Caml-list] Setting up OPAM in emacs 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 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=20 > 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 wro= te: > >> 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? >>=20 >> (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.) >>=20 >> On Tue, Jun 4, 2013 at 4:55 PM, Leo White wrote: >>> My personal solution for Tuareg mode is to put: >>>=20 >>> ;; Use OPAM's ocaml >>> (setq tuareg-interactive-program "opam config exec ocaml") >>>=20 >>> in my .emacs. >>>=20 >>> Regards, >>>=20 >>> Leo >>>=20 >>> Wojciech Meyer writes: >>>=20 >>>> Christophe's function hook is probably much better and elegant solutio= n, >>>> but this works for me: >>>>=20 >>>>>>=20 >>>> (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-p= ath) exec-path)) >>>> (entry >>>> (replace-regexp-in-string >>>> "\n" "" >>>> (shell-command-to-string >>>> (format "opam switch --root %s %s > /dev/null && opam confi= g env | sed -n 's/^PATH=3D\\([^:]\\+\\):.*$/\\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=3D\\(.*\\)/\\1/= p'" opam-root))))) >>>> (setq exec-path (cons entry path)) >>>> (setenv "PATH" env-path))) >>>>=20 >>>> (defun dm-opam-switch (ocaml-version) >>>> (interactive "sOCaml version: ") >>>> (dm-opam-switch-root ocaml-version "~/.opam")) >>>> << >>>>=20 >>>> 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. >>>>=20 >>>> You just say M-x dm-opam-switch, and indicate which version you would >>>> like. >>>>=20 >>>> Best, >>>> Wojciech >>>>=20 >>>> Christophe TROESTLER writes: >>>>=20 >>>>> On Tue, 28 May 2013 09:59:53 +0400, Ivan Gotovchits wrote: >>>>>>=20 >>>>>> 2. Use =C2=ABeval `opam env config`=C2=BB in the begining of a compi= le-command. >>>>>> This works fine when you switch compiler, but other commands, such= as >>>>>> =C2=ABC-c C-s=C2=BB doesn't use new environment. >>>>>=20 >>>>> I use this for the compilation: >>>>>=20 >>>>> ;; OPAM compilation =E2=80=94 one must update to the current compi= ler >>>>> ;; 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))) >>>>> ))) >>>>>=20 >>>>> For the toplevel, I am afraid one needs to restart it. I guess a >>>>> similar trick is possible to automatically select the right one. >>>>>=20 >>>>> Hope it helps, >>>>> C. >>>=20 >>> -- >>> 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 >>=20