Skip to content

Commit

Permalink
Merge branch 'st3'
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 20, 2025
2 parents 82d488b + a5b8c6e commit 62af315
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 509 deletions.
5 changes: 3 additions & 2 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,11 @@ LaTeX Package keymap for Linux

{
"keys": ["tab"],
"command": "latextools_confirm_quickpanel",
"command": "select",
"context": [
{ "key": "overlay_visible" },
{ "key": "latextools.input_overlay_visible" },
{ "key": "setting.auto_complete_commit_on_tab" },
{ "key": "latextools.input_overlay_visible" }
],
},

Expand Down
5 changes: 3 additions & 2 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,11 @@ LaTeX Package keymap for OS X

{
"keys": ["tab"],
"command": "latextools_confirm_quickpanel",
"command": "select",
"context": [
{ "key": "overlay_visible" },
{ "key": "latextools.input_overlay_visible" },
{ "key": "setting.auto_complete_commit_on_tab" },
{ "key": "latextools.input_overlay_visible" }
],
},

Expand Down
5 changes: 3 additions & 2 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,11 @@ LaTeX Package keymap for Linux

{
"keys": ["tab"],
"command": "latextools_confirm_quickpanel",
"command": "select",
"context": [
{ "key": "overlay_visible" },
{ "key": "latextools.input_overlay_visible" },
{ "key": "setting.auto_complete_commit_on_tab" },
{ "key": "latextools.input_overlay_visible" }
],
},

Expand Down
20 changes: 9 additions & 11 deletions LaTeXTools.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@

// Ends of the names of temporary files to be deleted
"temp_files_exts": [
".blg",".bbl",".aux",".log",".brf",".nlo",".out",".dvi",".ps",
".lof",".toc",".fls",".fdb_latexmk",".pdfsync",".synctex.gz",
".ind",".ilg",".idx"
".aux", ".bbl", ".blg", ".brf", ".dvi", ".fdb_latexmk", ".fls",
".glo", ".idx", ".ilg", ".ind", ".lof", ".log", ".nlo", ".out",
".pdfsync", ".ps", ".synctex.gz", ".thm", ".toc", ".xdy",
],

// Folders that are not traversed when deleting temp files
Expand Down Expand Up @@ -550,19 +550,17 @@
// ------------------------------------------------------------------

// OPTION: "bibliography"
// Either a single bibliography plugin to use or a list of plugins
// Either a single bibliography plugin to use or a list of plugins
// which will be executed in order, stopping after the first result
// found
// found.
//
// Possible values:
//
// "traditional" the default, regex-based bibliography
// parsing
// "traditional" simple regex-based bibliography parsing
//
// "new" a newer parser which supports more complex
// formatting and additional fields, but may
// be slower
"bibliography": "traditional",
// "new" (default) a parser which supports more
// complex formatting and additional fields.
"bibliography": "new",

// OPTION: "additional_bibliography_file"
// With this setting you can add the path to one or more additional
Expand Down
2 changes: 1 addition & 1 deletion latextools/deprecated_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_setting_name = "compatibility_enable_version3_commands"


class LatextoolsDeprecatedCommand(object):
class LatextoolsDeprecatedCommand:
# every subclass should overwrite this attribute
new_classname = ""

Expand Down
5 changes: 3 additions & 2 deletions latextools/latex_cite_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,9 @@ def get_completions(self, view, prefix, line):
sublime.status_message("No bib files found!")
return
except BibParsingError as e:
traceback.print_exc()
sublime.status_message("Error occurred parsing {0}. {1}.".format(e.filename, e.message))
msg = "Error occurred parsing {0}. {1}.".format(e.filename, e.message)
logger.error(msg)
sublime.status_message(msg)
return

if prefix:
Expand Down
2 changes: 1 addition & 1 deletion latextools/latex_cwl_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_cwl_completions():
return CWL_COMPLETIONS


class CwlCompletions(object):
class CwlCompletions:
"""
Completion manager that coordinates between between the event listener and
the thread that does the actual parsing. It also stores the completions
Expand Down
4 changes: 2 additions & 2 deletions latextools/latex_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def run(self, edit, **args):
if environment:
environment_region = sublime.Region(point - len(environment), point)
view.erase(edit, environment_region)
snippet = "\\\\begin{" + environment + "}\n$1\n\\\\end{" + environment + "}$0"
snippet = "\\\\begin{" + environment + "}\n\t$0\n\\\\end{" + environment + "}"
else:
snippet = "\\\\begin{${1:env}}\n$2\n\\end{$1}$0"
snippet = "\\\\begin{${1:env}}\n\t$0\n\\end{$1}"
view.run_command("insert_snippet", {"contents": snippet})
else:
sublime.status_message(
Expand Down
27 changes: 22 additions & 5 deletions latextools/latex_fill_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .utils.logging import logger
from .utils.settings import get_setting
from .utils.internal_types import FillAllHelper
from .utils.input_quickpanel import show_input_quick_panel

__all__ = [
"LatexFillAllEventListener",
Expand All @@ -20,6 +19,8 @@
"LatexToolsReplaceWord",
]

VISIBLE_OVERLAYS = set()

def reraise(tp, value, tb=None):
if value is None:
value = tp()
Expand All @@ -28,7 +29,7 @@ def reraise(tp, value, tb=None):
raise value


class LatexFillHelper(object):
class LatexFillHelper:
"""
Base class for some LaTeXTools TextCommands. Implements several methods
helpful for inserting text into the view and updating the cursor posiiton.
Expand Down Expand Up @@ -65,7 +66,7 @@ def complete_auto_match(self, view, edit, insert_char):
:param insert_char:
the character to try to automatch
"""
if sublime.load_settings("Preferences.sublime-settings").get("auto_match_enabled", True):
if view.settings().get("auto_match_enabled", True):
# simple case: we have an insert char, insert closing char,
# if its defined
if insert_char:
Expand Down Expand Up @@ -569,7 +570,7 @@ def match_selector(self, view, selector):
return all(view.match_selector(sel.b, selector) for sel in view.sel())


class LatexFillAllPluginConsumer(object):
class LatexFillAllPluginConsumer:
"""
Base class for classes which use FillAllHelper plugins
"""
Expand Down Expand Up @@ -628,6 +629,14 @@ def on_query_context(self, view, key, operator, operand, match_all):
key is "lt_fill_all_{name}" where name is the short name of the
completion type, e.g. "lt_fill_all_cite", etc.
"""

# autofill input quick panel visible
if key == "latextools.input_overlay_visible":
try:
return view.window().id() in VISIBLE_OVERLAYS
except:
return False

# quick exit conditions
if not key.startswith("lt_fill_all_"):
return None
Expand Down Expand Up @@ -991,8 +1000,13 @@ def run(self, edit, completion_type=None, insert_char="", overwrite=False, force
self.remove_regions(view, edit, remove_regions)
self.clear_bracket_cache()
else:
window = view.window()
if not window:
self.clear_bracket_cache()
return

def on_done(i, text=""):
VISIBLE_OVERLAYS.discard(window.id())
if i is None:
insert_text = text
elif i < 0:
Expand All @@ -1019,7 +1033,10 @@ def on_done(i, text=""):
},
)

show_input_quick_panel(view.window(), formatted_completions, on_done)
# track visible input quick panels to provide key binding context
VISIBLE_OVERLAYS.add(window.id())
window.show_quick_panel(formatted_completions, on_done)

self.clear_bracket_cache()


Expand Down
9 changes: 5 additions & 4 deletions latextools/utils/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class FileNotAnalyzed(Exception):
pass


class Analysis(object):
class Analysis:

def __init__(self, tex_root):
self._tex_root = tex_root
Expand Down Expand Up @@ -159,7 +159,7 @@ def tex_base_path(self, file_path):
This is usually the folder of the tex root, but can change if
the import package is used.
Use this instead of the tex root path to implement functions
like the \input command completion.
like the \\input command completion.
"""
file_path = os.path.normpath(file_path)
try:
Expand Down Expand Up @@ -341,7 +341,8 @@ def get_analysis(tex_root):
raise TypeError("tex_root must be a string or view")

result = LocalCache(tex_root).cache("analysis", partial(analyze_document, tex_root))
result._freeze()
if result:
result._freeze()
return result


Expand Down Expand Up @@ -575,7 +576,7 @@ def rowcol(pos):
return rowcol


class objectview(object):
class objectview:
"""
Converts an dict into an object, such that every dict entry
is an attribute of the object
Expand Down
31 changes: 14 additions & 17 deletions latextools/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _global_cache_path():


# marker class for invalidated result
class InvalidObject(object):
class InvalidObject:
_HASH = hash("_LaTeXTools_InvalidObject")

def __eq__(self, other):
Expand All @@ -196,7 +196,7 @@ def __hash__(self):
_invalid_object = InvalidObject()


class Cache(object):
class Cache:
"""
default cache object and definition
Expand Down Expand Up @@ -370,7 +370,7 @@ def load(self, key=None):
if key is None:
for entry in os.listdir(self.cache_path):
if os.path.isfile(entry):
entry_name = os.path.basename[entry]
entry_name = os.path.basename(entry)
try:
self._objects[entry_name] = self._read(entry_name)
except Exception:
Expand Down Expand Up @@ -423,7 +423,7 @@ def save(self, key=None):
del _objs[k]
file_path = os.path.join(self.cache_path, key)
try:
os.path.remove(file_path)
os.remove(file_path)
except OSError:
pass

Expand All @@ -440,15 +440,14 @@ def save(self, key=None):
shutil.rmtree(self.cache_path)
except OSError as e:
logger.error("error while deleting %s: %s", self.cache_path, e)
traceback.print_exc()

elif key in _objs:
if _objs[key] == _invalid_object:
file_path = os.path.join(self.cache_path, key)
try:
os.path.remove(file_path)
os.remove(file_path)
except OSError as e:
logger.error("error while deleting %s: %s", file_path, e)
traceback.print_exc()
else:
os.makedirs(self.cache_path, exist_ok=True)
self._write(key, _objs)
Expand All @@ -473,7 +472,6 @@ def _write(self, key, obj):
pickle.dump(_obj, f, protocol=-1)
except OSError as e:
logger.error("error while writing to %s: %s", key, e)
traceback.print_exc()
raise CacheMiss()

def _schedule_save(self):
Expand Down Expand Up @@ -727,31 +725,30 @@ def _get_cache_life_span(cls):
is used on every cache read
"""

def __parse_life_span_string():
def __parse_life_span_string(life_span_str):
try:
return int(life_span_string)
return int(life_span_str)
except ValueError:
try:
(d, h, m, s) = TIME_RE.match(life_span_string).groups()
(d, h, m, s) = TIME_RE.match(life_span_str).groups()
# time conversions in seconds
times = [(s, 1), (m, 60), (h, 3600), (d, 86400)]
# sum the converted times
# if not specified (None) use 0
return sum(int(t[0] or 0) * t[1] for t in times)
except Exception as e:
logger.error("error parsing life_span_string %s", life_span_string)
traceback.print_exc()
logger.error("error parsing cache.life_span: %s", life_span_str)
# default 30 minutes in seconds
return 1800

with cls._LIFE_SPAN_LOCK:
life_span_string = get_setting("cache.life_span")
life_span_str = get_setting("cache.life_span")
try:
if cls._PREV_LIFE_SPAN_STR == life_span_string:
if cls._PREV_LIFE_SPAN_STR == life_span_str:
return cls._PREV_LIFE_SPAN
except AttributeError:
pass

cls._PREV_LIFE_SPAN_STR = life_span_string
cls._PREV_LIFE_SPAN = life_span = __parse_life_span_string()
cls._PREV_LIFE_SPAN_STR = life_span_str
cls._PREV_LIFE_SPAN = life_span = __parse_life_span_string(life_span_str)
return life_span
Loading

0 comments on commit 62af315

Please sign in to comment.