docs: def open_document(self, path, encoding=None, replace_tabs_by_spaces=True,
                        clean_trailing_whitespaces=True, safe_save=True,
                        restore_cursor_position=True, preferred_eol=0,
                        autodetect_eol=True, show_whitespaces=False, **kwargs):
          """
          Opens a document.
  
          :param path: Path of the document to open
          :param encoding: The encoding to use to open the file. Default is
              locale.getpreferredencoding().
          :param replace_tabs_by_spaces: Enable/Disable replace tabs by spaces.
              Default is true.
          :param clean_trailing_whitespaces: Enable/Disable clean trailing
              whitespaces (on save). Default is True.
          :param safe_save: If True, the file is saved to a temporary file first.
              If the save went fine, the temporary file is renamed to the final
              filename.
          :param restore_cursor_position: If true, last cursor position will be
              restored. Default is True.
          :param preferred_eol: Preferred EOL convention. This setting will be
              used for saving the document unless autodetect_eol is True.
          :param autodetect_eol: If true, automatically detects file EOL and
              use it instead of the preferred EOL when saving files.
          :param show_whitespaces: True to show white spaces.
          :param kwargs: addtional keyword args to pass to the widget
                         constructor.
          :return: The created code editor
          """
          original_path = os.path.normpath(path)
          path = os.path.normcase(original_path)
          paths = []
          widgets = []
          for w in self.widgets(include_clones=False):
              if os.path.exists(w.file.path):
                  # skip new docs
                  widgets.append(w)
                  paths.append(os.path.normcase(w.file.path))
          if path in paths:
              i = paths.index(path)
              w = widgets[i]
              tw = w.parent_tab_widget
              tw.setCurrentIndex(tw.indexOf(w))
              return w
          else:
              assert os.path.exists(original_path)
              name = os.path.split(original_path)[1]
  
              use_parent_dir = False
              for tab in self.widgets():
                  title = QtCore.QFileInfo(tab.file.path).fileName()
                  if title == name:
                      tw = tab.parent_tab_widget
                      new_name = os.path.join(os.path.split(os.path.dirname(
                          tab.file.path))[1], title)
                      tw.setTabText(tw.indexOf(tab), new_name)
                      use_parent_dir = True
  
              if use_parent_dir:
                  name = os.path.join(
                      os.path.split(os.path.dirname(path))[1], name)
                  use_parent_dir = False
  
              tab = self._create_code_edit(self.guess_mimetype(path), **kwargs)
              self.editor_created.emit(tab)
  
              tab.open_parameters = {
                  'encoding': encoding,
                  'replace_tabs_by_spaces': replace_tabs_by_spaces,
                  'clean_trailing_whitespaces': clean_trailing_whitespaces,
                  'safe_save': safe_save,
                  'restore_cursor_position': restore_cursor_position,
                  'preferred_eol': preferred_eol,
                  'autodetect_eol': autodetect_eol,
                  'show_whitespaces': show_whitespaces,
                  'kwargs': kwargs
              }
              tab.file.clean_trailing_whitespaces = clean_trailing_whitespaces
              tab.file.safe_save = safe_save
              tab.file.restore_cursor = restore_cursor_position
              tab.file.replace_tabs_by_spaces = replace_tabs_by_spaces
              tab.file.autodetect_eol = autodetect_eol
              tab.file.preferred_eol = preferred_eol
              tab.show_whitespaces = show_whitespaces
              try:
                  tab.file.open(original_path, encoding=encoding)
              except Exception as e:
                  _logger().exception('exception while opening file')
                  tab.close()
                  tab.setParent(None)
                  tab.deleteLater()
                  raise e
              else:
                  tab.setDocumentTitle(name)
                  tab.file._path = original_path
                  icon = self._icon(path)
                  self.add_tab(tab, title=name, icon=icon)
                  self.document_opened.emit(tab)
  
                  for action in self.closed_tabs_menu.actions():
                      if action.toolTip() == original_path:
                          self.closed_tabs_menu.removeAction(action)
                          break
                  self.closed_tabs_history_btn.setEnabled(
                      len(self.closed_tabs_menu.actions()) > 0)
  
                  return tab