# Introducing Gopcaml mode - structural OCaml editing

**URL:** <https://discuss.ocaml.org/t/introducing-gopcaml-mode-structural-ocaml-editing/5310>\
**Category:** Community\
**Tags:** emacs\
**Created:** [March 14, 2020, 5:11am UTC](https://discuss.ocaml.org/t/introducing-gopcaml-mode-structural-ocaml-editing/5310 "2020-03-14T05:11:35Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Gopiandcode](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gopiandcode/32/5346_2.png) [@Gopiandcode](https://discuss.ocaml.org/u/Gopiandcode)\
**Post date:** [March 14, 2020, 5:11am UTC](https://discuss.ocaml.org/t/introducing-gopcaml-mode-structural-ocaml-editing/5310/1 "2020-03-14T05:11:35Z")

</div>

Hi all, I am pleased to announce the first release of Gopcaml-mode, a new emacs library that aims to extend the existing OCaml editing experience with structural editing capabilities.

A picture is worth a thousand words, so I’ll cut to the chase, and start with a few demonstrations:

## Examples

- AST-based code navigation - `C-M-n, C-M-p, C-M-u, C-M-d, C-M-f, C-M-b`

 ![ast-code-navigation](https://gitlab.com/gopiandcode/gopcaml-mode/-/raw/master/images/gopcaml_move_expression_example.gif?inline=false)

- AST-based code transformation -`C-M-N, C-M-P, C-M-F, C-M-B`

 ![ast-code-transform](https://gitlab.com/gopiandcode/gopcaml-mode/-/raw/master/images/gopcaml_move_function_example.gif?inline=false)

- Mark exp - `C-M-SPC`

 ![mark-sexp](https://gitlab.com/gopiandcode/gopcaml-mode/-/raw/master/images/gopcaml_mark_sexp.gif?inline=false)

- Extract expression into letdef - `C-c C-e`

 ![extract-expression](https://gitlab.com/gopiandcode/gopcaml-mode/-/raw/master/images/gopcaml_extraction_expressions.gif?inline=false)

This is just a small sample of the features - a full listing is provided at the project readme, which can be found at the [project page](https://gitlab.com/gopiandcode/gopcaml-mode).

## Notes

This plugin is quite faithful to the OCaml specification and doesn’t reimplement a separate OCaml parser as some other plugins do - instead I use the Ecaml package (which allows interfacing with Emacs from OCaml code) to allow delegating to the OCaml parser (from Ocaml-compiler-libs) directly.

It’s in the process of being published to opam, and should be available to download soon.

Edit: It has now been merged into the opam-repositories and can be installed via opam:

## Installation

- Install the package from opam

```auto
opam install gopcaml-mode

```

- load the package in your init.el

```auto
 (let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var" "share")))))
	   (when (and opam-share (file-directory-p opam-share))
	     ;; Register Gopcaml mode
	     (add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share))
         (autoload 'gopcaml-mode "gopcaml-mode" nil t nil)
	     ;; Automatically start it in OCaml buffers
	     (setq auto-mode-alist
		   (append '(("\\.ml[ily]?$" . gopcaml-mode)
			     ("\\.topml$" . gopcaml-mode))
			   auto-mode-alist))
	     ))

```

- (Optional) install `multiple-cursors` to enable extraction and `smartparens` for better handling of parenthesis.

---

_[View the full topic](https://discuss.ocaml.org/t/introducing-gopcaml-mode-structural-ocaml-editing/5310)._
