diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 66a67468..dcacdb5e 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -461,13 +461,14 @@ impl Document {
 
         // set the path and try detecting the language
         doc.set_path(&path)?;
-        doc.detect_indent_style();
-        doc.line_ending = line_ending;
-
         if let Some(loader) = config_loader {
             doc.detect_language(theme, loader);
         }
 
+        // Detect indentation style and set line ending.
+        doc.detect_indent_style();
+        doc.line_ending = line_ending;
+
         Ok(doc)
     }