@@ -456,14 +456,16 @@ impl Document {
456456 theme: Option<&Theme>,
457457 config_loader: Option<&syntax::Loader>,
458458 ) -> Result<Self, Error> {
459− if !path.exists() {
460− return Ok(Self::default());
461− }
459+ let (mut rope, encoding) = if path.exists() {
460+ let mut file =
461+ std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
462+ from_reader(&mut file, encoding)?
463+ } else {
464+ let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
465+ (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
466+ };
462467
463− let mut file = std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
464− let (mut rope, encoding) = from_reader(&mut file, encoding)?;
465468 let line_ending = with_line_ending(&mut rope);
466−
467469 let mut doc = Self::from(rope, Some(encoding));
468470
469471 // set the path and try detecting the language