[Teaching] Getting opam's user-setup working cleanly

Louis Gesbert louis.gesbert at ocamlpro.com
Sat Jan 24 03:02:02 GMT 2015


user-setup doesn't handle yet the Mac-specific issue of Emacs load-paths, so that's probably what is bitting you here; I'll port the related code from your .emacs; getting a means to test on these ASAP.


On hardcoding the paths, I'm still not certain it is the best option, but I had a few reasons for doing so (open for discussion, obviously, this is still a prototype):

* user-setup configures editors depending on what is installed in the current switch ; it may not make sense in other switches.

* some tools are generally useful (tuareg, ocp-indent) and installing them in one switch should be enough. There is a clear distinction though for compiler-version dependent tools (merlin, ocp-index).

* this is not focused on advanced users with multiple switches, etc. and it makes the configuration simpler to understand and edit.

* this approach is guaranteed to be available for all editors.

The alternatives would be (i) using packages supplied within the editor's ecosystems, when available (see the detailed discussion at [1]), which should clearly handle locations dynamically -- I think that best serves advanced users but has a purpose distinct enough to justify both approaches ; and (ii) dynamically generating configuration at editor run time (like ocp-edit does for emacs: it reads its own configuration and outputs elisp code that is evaluated at run time)

Note that we still hit a consistency issue with this approach if installing user-setup in multiple switches. This also raises the question of handling "global" or "multi-switch" packages in OPAM.


On the feature of dynamically adapting to the latest `opam switch` in emacs, it could be achieved by running all external commands through `opam config exec -- <command>`. It doesn't extend to running different elisp files depending on the switch though, and you'd still need to manually update PATH etc. if you're running builds within emacs, similar to `eval $(opam config env)`. I do this using:

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

opam-user-setup will set this statically, locally on caml/tuareg buffers, which may indeed not be the best idea.

Thanks for the feedback, it'll help make this usable quick
Louis

> - Yaron Minsky, 23/01/2015 20:48 -
> Hmm.  I'm still not able to get user-setup to work cleanly on my mac,
> though depext does install now, and I think correctly determines that
> there are no packages it needs to install.
> 
> But here are the messages I get from emacs:
> 
> Loading paren...done
> Loading tuareg-site-file...done
> For information about GNU Emacs and the GNU system, type C-h C-a.
> Making completion list...
> Starting merlin instance: default (binary=ocamlmerlin).
> File mode specification error: (file-error "Searching for program" "no
> such file or directory" "ocamlmerlin")
> 
> So it can't seem to find merlin.
> 
> I'm also a little troubled by the hard-coding of paths in the .emacs.
> Once nice thing about the dot-emacs file I shared with Greg is that it
> auto-updates where it points on every opam switch, without even
> needing to restart emacs, I believe.  It would be nice to have this
> for merlin, though I admit perhaps not with tuareg.
> 
> I tend to think that until we get this sorted, teachers should use
> manually put together dot-emacs files like the ones I emailed out.
> 
> y
> 
> On Fri, Jan 23, 2015 at 12:39 AM, Anil Madhavapeddy <anil at recoil.org> wrote:
> > Fixed; there was a minor typo in the `opam` file for the package;
> > https://github.com/ocaml/opam-repository/pull/3441
> >
> > -a
> >
> >> On 23 Jan 2015, at 04:33, Yaron Minsky <yminsky at janestreet.com> wrote:
> >>
> >> Also, I can't seem to install depext, but the reason doesn't make sense:
> >>
> >> Kalessin:~ yminsky2$ opam install depext
> >> [ERROR] depext is not available because your system doesn't comply
> >> with opam-version >= "4.02".
> >> Kalessin:~ yminsky2$ opam --version
> >> 1.2.0
> >>
> >> I'm running the latest opam available from homebrew.
> >>
> >> y
> >>
> >> On Thu, Jan 22, 2015 at 10:21 PM, Yaron Minsky <yminsky at janestreet.com> wrote:
> >>> Does depext do anything on a mac?  On redhat? Or is it Debian only?
> >>>
> >>> On Jan 22, 2015 10:03 PM, "Louis Gesbert" <louis.gesbert at ocamlpro.com>
> >>> wrote:
> >>>>
> >>>> Just released 0.2 which should fix both issues (opam tuareg mode and
> >>>> stalling with vim)
> >>>>
> >>>>> It would be good to know what we have there now.  It seems like a
> >>>>> minimum should be:
> >>>>>
> >>>>> - tuareg
> >>>>> - merlin
> >>>>> - ocp-indent
> >>>>> - utop
> >>>>>
> >>>>> all read to go in emacs.  Getting vim and sublime text support would
> >>>>> be lovely too, but I think less critical.  What does user-setup
> >>>>> already support?
> >>>>
> >>>> Needs more testing, but we do have those ; vim support also, but it's more
> >>>> lightly tested.
> >>>> I didn't figure how to configure Sublime yet.
> >>>>
> >>>>> Interesting. Concretely, what would would depext do in this context?
> >>>>> I did a fresh install of a number of packages on my mac, and I didn't
> >>>>> need much else, but I may have already had the dependencies in place
> >>>>> via brew.
> >>>>
> >>>> Not sure, but you can use `opam depext -l` to simply show the currently
> >>>> required external packages.
> >>>>
> >>>> The one that bites most often on .deb distributions is the lack of m4,
> >>>> which is required by ocamlfind. It gets much more complicated as soon as you
> >>>> want to install e.g. gtk stuff, of course (ocaml-top...).
> >>>>
> >>>> Best,
> >>>> Louis
> >>
> >


More information about the Teaching mailing list