What can cause errors?
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 967, in on_selection_modified
run_view_callbacks('on_selection_modified', view_id)
File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 741, in run_view_callbacks
callback(v, *args)
File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 162, in profiler
return event_handler(*args)
File "/Users/z/Library/Application Support/Sublime Text/Packages/User/percentage in status bar.py", line 30, in on_selection_modified
self._update(view)
File "/Users/z/Library/Application Support/Sublime Text/Packages/User/percentage in status bar.py", line 33, in _update
pt = view.sel()[0].begin()
File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime.py", line 2253, in __getitem__
raise IndexError()
IndexError
There is my modified version to add percentage
import sublime
import sublime_plugin
class LineCountListener(sublime_plugin.EventListener):
"""
This class describes a line count listener.
Note: Set ``"show_line_column", "disabled"``
to disable ST's built-in line/column status
https://forum.sublimetext.com/t/line-count-or-percentage-in-status-bar/67711
"""
def on_new(self, view: sublime.View):
"""
Update status for new view.
"""
self._update(view)
def on_load(self, view: sublime.View):
"""
Update status after loading file.
"""
self._update(view)
def on_selection_modified(self, view: sublime.View):
"""
Update status when caret moves.
"""
self._update(view)
def _update(self, view: sublime.View):
pt = view.sel()[0].begin()
row, col = view.rowcol(pt)
cols = len(view.line(pt))
lines, _ = view.rowcol(view.size())
# view.set_status("zzz_lines", f"L: {(row + 1)}/{(lines + 1)}, C: {col + 1}/{cols + 1}")
# view.set_status("zzz_lines", f"Line {(row + 1)} of {(lines + 1)}, Column {col + 1}")
view.set_status("zzz_lines", f" {((row + 1)/(lines + 1))*100:.2f}% ")