diff --git a/dotfiles/.py3.vimrc b/dotfiles/.py3.vimrc index b798dd3..033685e 100644 --- a/dotfiles/.py3.vimrc +++ b/dotfiles/.py3.vimrc @@ -187,10 +187,18 @@ class EditorConfigModeline: @classmethod def find_entry( cls, - config: dict[str, str], - file_path: pathlib.Path + file_path: pathlib.Path, + config: Optional[dict[str, str]] = None, ) -> Optional[str]: - rel_path = file_path.relative_to(pathlib.Path.cwd()) + if config is None: + return None + + project_root = pathlib.Path.cwd() + + if file_path.is_relative_to(project_root): + rel_path = file_path.relative_to(pathlib.Path.cwd()) + else: + rel_path = file_path for pattern, modeline in config.items(): if fnmatch.fnmatch(str(rel_path), pattern): @@ -206,7 +214,7 @@ class EditorConfigModeline: buf_name = vim.current.buffer.name file_path = pathlib.Path(buf_name).resolve() - entry = self.find_entry(config, file_path) + entry = self.find_entry(file_path, config=config) logger.info(dict(modeline=entry))