@@ -456,14 +456,16 @@ impl Document {
456 theme: Option<&Theme>,
456 theme: Option<&Theme>,
457 config_loader: Option<&syntax::Loader>,
457 config_loader: Option<&syntax::Loader>,
458 ) -> Result<Self, Error> {
458 ) -> Result<Self, Error> {
459− if !path.exists() {
459+ let (mut rope, encoding) = if path.exists() {
460− return Ok(Self::default());
460+ let mut file =
461+ std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
462+ from_reader(&mut file, encoding)?
464+ let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
465+ (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
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)?;
465 let line_ending = with_line_ending(&mut rope);
468 let line_ending = with_line_ending(&mut rope);
467 let mut doc = Self::from(rope, Some(encoding));
469 let mut doc = Self::from(rope, Some(encoding));
469 // set the path and try detecting the language
471 // set the path and try detecting the language