From 91a9fff0d6175c24fef35f71f4053117124e67e8 Mon Sep 17 00:00:00 2001 From: Daniel Beckwith Date: Sun, 30 Sep 2018 20:04:07 -0400 Subject: [PATCH] Add auto folder render depth option (#166) Fixes #165 Makes the default `render_folder_depth` setting to be `auto`, which will render folders up to any open folders in the window. --- TodoReview.py | 12 ++++++++++-- readme.md | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/TodoReview.py b/TodoReview.py index fb8b3a3..388fa80 100644 --- a/TodoReview.py +++ b/TodoReview.py @@ -277,8 +277,16 @@ def draw_results(self): def draw_file(self, item): if settings.get('render_include_folder', False): depth = settings.get('render_folder_depth', 1) - f = os.path.dirname(item['file']).replace('\\', '/').split('/') - f = '/'.join(f[-depth:] + [os.path.basename(item['file'])]) + if depth == 'auto': + f = item['file'] + for folder in sublime.active_window().folders(): + if f.startswith(folder): + f = os.path.relpath(f, folder) + break + f = f.replace('\\', '/') + else: + f = os.path.dirname(item['file']).replace('\\', '/').split('/') + f = '/'.join(f[-depth:] + [os.path.basename(item['file'])]) else: f = os.path.basename(item['file']) return '%f:%l' \ diff --git a/readme.md b/readme.md index 77c370e..00f1109 100644 --- a/readme.md +++ b/readme.md @@ -169,6 +169,8 @@ Additionally, if you choose to include folders in your report, you may also spec "render_folder_depth": 5 ``` +If you are using Sublime in a project or have folders open, you may find it helpful to set `"render_folder_depth"` to `"auto"`, which will render folders in the report up to any folders you have open. For example, if you're working on a project rooted at `/home/user/code/project`, and you have a TODO in `/home/user/code/project/src/file.cpp`, the report would render the file as `src/file.cpp`. + ## Align results TodoReview now automatically aligns the comments for you, calculating the largest result and aligning the rest accordingly. The system default for maximum spaces is `50`, which prevents a single file with an abnormally long length completely ruining your results. You can change this setting by editing `render_maxspaces`