Ocp-Indent broken for Emacs (2023)?

I have tried to install ocp-indent via opam, and after a successful install the instruction provided at TypeRex: ocp-indent to run echo '(load-file "'"$(opam config var prefix)"'/share/typerex/ocp-indent/ocp-indent.el")' >>~/.emacs in order to setup tuareg-mode with ocp-indent resulted in my .emacs file not recognizing the ocp-indent.el, I went to the path provided and only a .vim file was in ocp-indent.

Has anyone else successfully installed and used ocp-indent recently? I checked the github repo and it hasn’t been touched in a few years.

I think that page is badly outdated. The ocp-indent.el file should be found in $(opam var share)/emacs/site-lisp, so this is the directory you should add to your load-path; once that is done, you should be able to load ocp-indent as usual: (require 'ocp-indent).

I have this in my .emacs:

(if (getenv "OPAM_SWITCH_PREFIX")
    (let ((opam-share (ignore-errors (car (process-lines "opam" "var" "share")))))
      (when (and opam-share (file-directory-p opam-share))
        (add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share))))

This code will add $(opam var share)/emacs/site-lisp to your load-path if you have an OPAM switch in your environment.

Cheers,
Nicolas

You should have also seen the right instructions after doing opam install ocp-indent:

$ opam install ocp-indent
The following actions will be performed:
  ∗ install ocp-indent 1.8.1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved ocp-indent.1.8.1  (cached)
∗ installed ocp-indent.1.8.1
Done.

<><> ocp-indent.1.8.1 installed successfully ><><><><><><><><><><><><><><><><><>
=> This package requires additional configuration for use in editors. Install package 'user-setup', or manually:

   * for Emacs, add these lines to ~/.emacs:
     (add-to-list 'load-path "/home/nojebar/.opam/4.14.1/share/emacs/site-lisp")
     (require 'ocp-indent)

   * for Vim, add this line to ~/.vimrc:
     set rtp^="/home/nojebar/.opam/4.14.1/share/ocp-indent/vim"
# Run eval $(opam env) to update the current shell environment

Cheers,
Nicolas

1 Like