Function: neocaml-format-buffer
neocaml-format-buffer is an interactive and natively compiled function
defined in neocaml.el.
Signature
(neocaml-format-buffer)
Documentation
Format the current buffer using ocamlformat.
Pipes the buffer through neocaml-ocamlformat-program and replaces the
buffer text with the formatted output, preserving point. ocamlformat
formats whole compilation units, so there is no region/defun variant.
Key Bindings
neocaml-base-mode-map C-c C-f
Source Code
;; Defined in /nix/store/ahssdx4rwzyxhyhavpn0bkznk13xrggi-emacs-packages-deps/share/emacs/site-lisp/elpa/neocaml-20260907.2015/neocaml.el
(defun neocaml-format-buffer ()
"Format the current buffer using `ocamlformat'.
Pipes the buffer through `neocaml-ocamlformat-program' and replaces the
buffer text with the formatted output, preserving point. ocamlformat
formats whole compilation units, so there is no region/defun variant."
(interactive)
(let ((outbuf (generate-new-buffer " *neocaml-ocamlformat*"))
(errfile (make-temp-file "neocaml-ocamlformat-err"))
(orig-point (point))
(orig-window-start (window-start)))
(unwind-protect
(let ((exit-code (apply #'call-process-region
(point-min) (point-max)
neocaml-ocamlformat-program nil
(list outbuf errfile) nil
(neocaml--ocamlformat-args))))
(if (zerop exit-code)
(progn
(erase-buffer)
(insert-buffer-substring outbuf)
(goto-char (min orig-point (point-max)))
(set-window-start (selected-window) orig-window-start))
(user-error "Running ocamlformat failed: %s"
(with-temp-buffer
(insert-file-contents errfile)
(string-trim (buffer-string))))))
(kill-buffer outbuf)
(delete-file errfile))))