From 47d9f52b6f43ccef4a4743126d9f27af439405b5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 12 Apr 2021 20:18:49 -0700 Subject: [PATCH] ocamlforamt hook: buffers without a file name The behavior before this PR would cause an error if a buffer not backed by a file was opened. This can be trivially reproduced by opening a merge/rebase conflict using ediff inside an .ml file. Signed-off-by: Rudi Grinberg --- modules/lang/ocaml/config.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 60c19ade3..696aa9822 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -111,9 +111,10 @@ (setq +format-with 'ocp-indent) (when (and (executable-find "ocamlformat") (locate-dominating-file default-directory ".ocamlformat")) - (let ((ext (file-name-extension buffer-file-name t))) - (cond ((equal ext ".eliom") - (setq-local ocamlformat-file-kind 'implementation)) - ((equal ext ".eliomi") - (setq-local ocamlformat-file-kind 'interface)))) + (when buffer-file-name + (let ((ext (file-name-extension buffer-file-name t))) + (cond ((equal ext ".eliom") + (setq-local ocamlformat-file-kind 'implementation)) + ((equal ext ".eliomi") + (setq-local ocamlformat-file-kind 'interface))))) (setq +format-with 'ocamlformat))))