Skip to content

Commit 35aa693

Browse files
committed
Cosmetic (delimit better what are overrides)
1 parent 3fc81f6 commit 35aa693

File tree

3 files changed

+60
-51
lines changed

3 files changed

+60
-51
lines changed

src/blame.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class Blame(BaseBlame, sublime_plugin.TextCommand):
1414

15-
# Overrides --------------------------------------------------
15+
# Overrides begin ------------------------------------------------------------------
1616

1717
def __init__(self, view):
1818
super().__init__(view)
@@ -126,15 +126,15 @@ def extra_cli_args(self, line_num, sha_skip_list):
126126
args.extend(["--ignore-rev", skipped_sha])
127127
return args
128128

129-
# ------------------------------------------------------------
129+
# Overrides end --------------------------------------------------------------------
130130

131131
def phantom_exists_for_region(self, region):
132132
return any(p.region == region for p in self.phantom_set.phantoms)
133133

134134

135135
class BlameInsertCommitDescription(sublime_plugin.TextCommand):
136136

137-
# Overrides --------------------------------------------------
137+
# Overrides begin ------------------------------------------------------------------
138138

139139
def run(self, edit, desc, scratch_view_name):
140140
view = self.view
@@ -143,3 +143,5 @@ def run(self, edit, desc, scratch_view_name):
143143
view.insert(edit, 0, desc)
144144
view.set_name(scratch_view_name)
145145
view.set_read_only(True)
146+
147+
# Overrides end --------------------------------------------------------------------

src/blame_all.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BlameShowAll(BaseBlame, sublime_plugin.TextCommand):
1616

1717
HORIZONTAL_SCROLL_DELAY_MS = 100
1818

19-
# Overrides --------------------------------------------------
19+
# Overrides begin ------------------------------------------------------------------
2020

2121
def __init__(self, view):
2222
super().__init__(view)
@@ -88,11 +88,11 @@ def _view(self):
8888
def extra_cli_args(self, **kwargs):
8989
return []
9090

91-
# ------------------------------------------------------------
92-
9391
def handle_phantom_close_button(self):
9492
self.view.run_command("blame_erase_all")
9593

94+
# Overrides end --------------------------------------------------------------------
95+
9696
def phantom_region(self, line_number):
9797
line_begins_pt = self.view.text_point(line_number - 1, 0)
9898
return sublime.Region(line_begins_pt)
@@ -116,36 +116,39 @@ def horizontal_scroll_to_limit(self, *, left):
116116

117117
class BlameEraseAll(sublime_plugin.TextCommand):
118118

119-
# Overrides --------------------------------------------------
119+
# Overrides begin ------------------------------------------------------------------
120120

121121
def run(self, edit):
122-
"""Erases the blame results."""
123122
sublime.status_message("The git blame result is cleared.")
124123
self.view.erase_phantoms(PHANTOM_KEY_ALL)
125124
self.view.settings().erase(VIEW_SETTING_PHANTOM_ALL_DISPLAYED)
126125
self.view.run_command("blame_restore_rulers")
127126

127+
# Overrides end --------------------------------------------------------------------
128+
128129

129130
class BlameEraseAllListener(sublime_plugin.ViewEventListener):
130131

131-
# Overrides --------------------------------------------------
132+
# Overrides begin ------------------------------------------------------------------
132133

133134
@classmethod
134135
def is_applicable(cls, settings):
135-
"""Checks if the blame_erase_all command is applicable."""
136136
return settings.get(VIEW_SETTING_PHANTOM_ALL_DISPLAYED, False)
137137

138138
def on_modified_async(self):
139-
"""Automatically erases the blame results to prevent mismatches."""
140139
self.view.run_command("blame_erase_all")
141140

141+
# Overrides end --------------------------------------------------------------------
142+
142143

143144
class BlameRestoreRulers(sublime_plugin.TextCommand):
144145

145-
# Overrides --------------------------------------------------
146+
# Overrides begin ------------------------------------------------------------------
146147

147148
def run(self, edit):
148149
self.view.settings().set(
149150
VIEW_SETTING_RULERS,
150151
self.view.settings().get(VIEW_SETTING_RULERS_PREV),
151152
)
153+
154+
# Overrides end --------------------------------------------------------------------

src/blame_inline.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ class BlameInlineListener(BaseBlame, sublime_plugin.ViewEventListener):
1818

1919
pkg_setting_callback_added = False
2020

21+
# Overrides begin ------------------------------------------------------------------
22+
23+
def __init__(self, view):
24+
super().__init__(view)
25+
self.phantom_set = sublime.PhantomSet(view, INLINE_BLAME_PHANTOM_SET_KEY)
26+
self.timer = None
27+
self.delay_seconds = (
28+
pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_DELAY) / 1000
29+
)
30+
# Show it immediately for the initially selected line.
31+
self.show_inline_blame()
32+
33+
def run(self, edit):
34+
# Unlike the other BaseBlame subclasses, we are reactive, not a sublime_plugin.Command
35+
pass
36+
2137
@classmethod
2238
def is_applicable(cls, view_settings):
2339
if not cls.pkg_setting_callback_added:
@@ -29,6 +45,27 @@ def is_applicable(cls, view_settings):
2945

3046
return cls.determine_enablement(view_settings)
3147

48+
def on_selection_modified_async(self):
49+
self.show_inline_blame_handler()
50+
51+
def on_post_save_async(self):
52+
# Redisplay the blame after the file is saved, because there will be
53+
# no call to on_selection_modified_async after save.
54+
self.show_inline_blame_handler()
55+
56+
def extra_cli_args(self, line_num):
57+
args = ["-L", "{0},{0}".format(line_num), "--date=relative"]
58+
return args
59+
60+
def _view(self):
61+
return self.view
62+
63+
def handle_phantom_close_button(self):
64+
# Inline Blame phantoms close automatically when appropriate.
65+
pass
66+
67+
# Overrides end --------------------------------------------------------------------
68+
3269
@classmethod
3370
def determine_enablement(cls, view_settings):
3471
enabled = view_settings.get(
@@ -61,30 +98,12 @@ def on_pkg_setting_changed(cls):
6198
view.settings().set(cls.__name__, "")
6299
view.settings().erase(cls.__name__)
63100

64-
def __init__(self, view):
65-
super().__init__(view)
66-
self.phantom_set = sublime.PhantomSet(view, INLINE_BLAME_PHANTOM_SET_KEY)
67-
self.timer = None
68-
self.delay_seconds = (
69-
pkg_settings().get(PKG_SETTINGS_KEY_INLINE_BLAME_DELAY) / 1000
70-
)
71-
# Show it immediately for the initially selected line.
72-
self.show_inline_blame()
73-
74-
def extra_cli_args(self, line_num):
75-
args = ["-L", "{0},{0}".format(line_num), "--date=relative"]
76-
return args
77-
78-
def _view(self):
79-
return self.view
80-
81-
def handle_phantom_close_button(self):
82-
# Inline Blame phantoms close automatically when appropriate.
83-
pass
84-
85-
def run(self, edit):
86-
# Unlike the other BaseBlame subclasses, we are reactive, not a sublime_plugin.Command
87-
pass
101+
def show_inline_blame_handler(self):
102+
self.view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
103+
if self.timer:
104+
self.timer.cancel()
105+
self.timer = threading.Timer(self.delay_seconds, self.show_inline_blame)
106+
self.timer.start()
88107

89108
def show_inline_blame(self):
90109
if self.view.is_dirty():
@@ -145,21 +164,6 @@ def maybe_insert_phantoms(self, phantoms):
145164
if not self.view.is_dirty():
146165
self.phantom_set.update(phantoms)
147166

148-
def show_inline_blame_handler(self):
149-
self.view.erase_phantoms(INLINE_BLAME_PHANTOM_SET_KEY)
150-
if self.timer:
151-
self.timer.cancel()
152-
self.timer = threading.Timer(self.delay_seconds, self.show_inline_blame)
153-
self.timer.start()
154-
155-
def on_selection_modified_async(self):
156-
self.show_inline_blame_handler()
157-
158-
def on_post_save_async(self):
159-
# Redisplay the blame after the file is saved, because there will be
160-
# no call to on_selection_modified_async after save.
161-
self.show_inline_blame_handler()
162-
163167

164168
class ToggleInlineGitBlame(sublime_plugin.TextCommand):
165169

0 commit comments

Comments
 (0)