Skip to content

Commit

Permalink
refactor: tidy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Apr 9, 2024
1 parent 8309310 commit 8ad6a16
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions plugin/TodoReview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import sublime
import sublime_plugin

assert __package__

RESULT = Dict[str, Any]

PACKAGE_NAME = __package__.partition(".")[0]
Expand All @@ -23,13 +25,12 @@

def fn_to_regex(fn: str) -> str:
"""
@brief Convert fnmatch pattern into regex pattern (directory separator safe)
Convert fnmatch pattern into regex pattern (directory separator safe)
@param fn The fnmatch pattern
:param fn: The fnmatch pattern
@return The regex pattern
:returns: The regex pattern
"""

return (
fnmatch.translate(fn)
# match both UNIX/Windows directory separators
Expand All @@ -41,13 +42,12 @@ def fn_to_regex(fn: str) -> str:

def merge_regexes(regexes: Iterable[str]) -> str:
"""
@brief Merge regexes into a single one
Merge regexes into a single one
@param regexes The regexes
:param regexes: The regexes
@return The merged regex
:returns: The merged regex
"""

merged = "(?:" + ")|(?:".join(regexes) + ")"

return "" if merged == "(?:)" else merged
Expand Down Expand Up @@ -207,8 +207,8 @@ def run(self, edit: sublime.Edit, **args: Any) -> None:
sublime.message_dialog("TodoReview: File must be saved first")
return
else:
if not paths and settings.get("include_paths", False):
paths = settings.get("include_paths", False)
if not paths and settings.get("include_paths", []):
paths = settings.get("include_paths", [])
if args.get("open_files", False):
filepaths = [v.file_name() or "" for v in window.views() if v.file_name()]
if not args.get("open_files_only", False):
Expand Down Expand Up @@ -240,12 +240,14 @@ def get_or_create_view(self) -> sublime.View:
view.set_name("TodoReview")
view.assign_syntax(TODO_SYNTAX_FILE)
view.set_scratch(True)
view.settings().set("todo_results", True)
view.settings().set("line_padding_bottom", 2)
view.settings().set("line_padding_top", 2)
view.settings().set("word_wrap", False)
view.settings().set("command_mode", True)
view.settings().set("is_widget", True)
view.settings().update({
"todo_results": True,
"line_padding_bottom": 2,
"line_padding_top": 2,
"word_wrap": False,
"command_mode": True,
"is_widget": True,
})
return view


Expand Down

0 comments on commit 8ad6a16

Please sign in to comment.