🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.caml
Article #59

Re: [Caml-list] Setting up OPAM in emacs

#59
From: Leo White
Date: Tue, 04 Jun 2013 14:55
78 lines
5638 bytes
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
Technical Details
Message-ID: <fa.4U+TtWeOLKJEwjRh0ZnBtm2L2XE@ifi.uio.no>
Path: arc1-ca.pugleaf.net!bp1ni1297pbd.1!nntp.google.com!news.glorb.com!uio.no!nntp.uio.no!.POSTED!not-for-mail
References: <fa.XC9uc4idVEjxaJMnEfN13P8hfkw@ifi.uio.no> <fa.IrXymIrsuGoUiuSbZhQeVuX1nkw@ifi.uio.no> <fa.FA5t9u4Q8GoNRPGiZMfgQ+KO//0@ifi.uio.no>

Show Full Headers
Complete Article Headers
X-Google-Thread: c0fe4b917e,3f6fc1af30fadf02
X-Google-Attributes: gidc0fe4b917e,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,UTF8
X-Received: by 10.66.155.227 with SMTP id vz3mr337397pab.13.1370357739646;
        Tue, 04 Jun 2013 07:55:39 -0700 (PDT)
Path: arc1-ca.pugleaf.net!bp1ni1297pbd.1!nntp.google.com!news.glorb.com!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Leo White <lpw25@cam.ac.uk>
Newsgroups: fa.caml
Subject: Re: [Caml-list] Setting up OPAM in emacs
Date: Tue, 04 Jun 2013 14:55:39 UTC
Organization: Internet mailing list
Lines: 78
Sender: caml-list-request@inria.fr
Message-ID: <fa.4U+TtWeOLKJEwjRh0ZnBtm2L2XE@ifi.uio.no>
References: <fa.XC9uc4idVEjxaJMnEfN13P8hfkw@ifi.uio.no> <fa.IrXymIrsuGoUiuSbZhQeVuX1nkw@ifi.uio.no> <fa.FA5t9u4Q8GoNRPGiZMfgQ+KO//0@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1370357739 28533 129.240.7.9 (4 Jun 2013 14:55:39 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Tue, 4 Jun 2013 14:55:39 +0000 (UTC)
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)
Cc: Christophe TROESTLER <Christophe.Troestler@umons.ac.be>,  <ivg@ieee.org>,  <caml-list@inria.fr>
To: Wojciech Meyer <wojciech.meyer@gmail.com>
X-IronPort-AV: E=Sophos;i="4.87,800,1363129200"; 
   d="scan'208";a="20276472"
X-Original-To: caml-list@sympa.inria.fr
Delivered-To: caml-list@sympa.inria.fr
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AskAAIz+rVGDbwiFlGdsb2JhbABahnW7XHoWDgEBAQEHDQkJFAUjgiMBAQEDASNWBQsLGAICBSECAg8BBA08ExuHYAMJBqtJiR8NS4gXgSaLI4IoMweCR4EUA5VYjgSIMw
X-IPAS-Result: AskAAIz+rVGDbwiFlGdsb2JhbABahnW7XHoWDgEBAQEHDQkJFAUjgiMBAQEDASNWBQsLGAICBSECAg8BBA08ExuHYAMJBqtJiR8NS4gXgSaLI4IoMweCR4EUA5VYjgSIMw
X-IronPort-AV: E=Sophos;i="4.87,800,1363129200"; 
   d="scan'208";a="16734177"
X-Cam-AntiVirus: no malware found
X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/
In-Reply-To: <wf4ndlsbxh.fsf@gmail.com> (Wojciech Meyer's message of "Wed, 29
 May 2013 22:39:38 +0100")
X-Sequence: 6890
X-no-archive: yes
List-Id: <caml-list.inria.fr>
List-Archive: <http://sympa.inria.fr/sympa/arc/caml-list>
List-Help: <mailto:sympa_inria@inria.fr?subject=help>
List-Owner: <mailto:caml-list-request@inria.fr>
List-Post: <mailto:caml-list@inria.fr>
List-Subscribe: <mailto:sympa_inria@inria.fr?subject=subscribe%20caml-list>
List-Unsubscribe: <mailto:sympa_inria@inria.fr?subject=unsubscribe%20caml-list>
Original-Date: Tue, 04 Jun 2013 15:55:26 +0100
Original-Message-Id: <878v2qj57l.fsf@kingston.cl.cam.ac.uk>
Original-References: <87li6z8x0m.fsf@ieee.org>
 <20130528.102112.1182989008075506917.Christophe.Troestler@umons.ac.be>
 <wf4ndlsbxh.fsf@gmail.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit