Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Files that were visited in the last minute will not be closed. (customize from s

- Close old and unused tabs with a simple shortcut.

- By setting the value of the setting value "close_on_open_new" to true, the plugin will execute the closing command when a new tab is opened.
- By setting the value of the setting value `close_on_open_new` to true, the plugin will execute the closing command when a new tab is opened.

- Setting a value for option `keep_number_of_tabs` prevents all tabs from being closed and retains the specified number of tabs.

- Close unrelated tabs to the open project.

Expand Down
14 changes: 10 additions & 4 deletions lessTabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class WM:
def get_project_folder(window):
project_folders = []
project_folders = []
if ( WM.has_project(window) ):
for folder_data in window.project_data()["folders"]:
project_folders.append(folder_data['path'])
Expand All @@ -15,7 +15,7 @@ def has_project(window):
def file_belongs_to_path(buffer, parent_folders, related_paths):
file_in_project = False
path = buffer.file_name()

if ( path ):
file_dir = os.path.dirname(path)
if ( not file_dir in related_paths ):
Expand All @@ -39,10 +39,13 @@ def run(self):
SETTINGS = sublime.load_settings("lessTabs.sublime-settings")
modified_ls = int(SETTINGS.get('modified_life_span'))
accessed_ls = int(SETTINGS.get('accessed_life_span'))
keep_num_tabs = int(SETTINGS.get('keep_number_of_tabs'))

now = time.time()
active_view = sublime.active_window().active_view()

tab_buffers = []

for buffer in self.window.views():
path = buffer.file_name()

Expand All @@ -56,12 +59,15 @@ def run(self):
and now - os.path.getmtime(path) > modified_ls
and now - os.path.getatime(path) > accessed_ls
):
tab_buffers.append(buffer)

for buffer in tab_buffers[keep_num_tabs:]:
WM.close_buffer(self.window, buffer)


class lessTabsCloseProjectUnrelatedCommand(sublime_plugin.WindowCommand):
def run(self):

window = self.window

if ( WM.has_project(window) ):
Expand Down Expand Up @@ -99,7 +105,7 @@ def run(self):
window = self.window
active_view = window.active_view()
file_path = active_view.file_name()

if ( file_path ):
if ( file_path and os.path.exists(file_path) ):
related_paths = []
Expand Down
6 changes: 5 additions & 1 deletion lessTabs.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
"accessed_life_span": 60,

// If true the command of closing tabs will be executed when a new tab is opened
"close_on_open_new" : false
"close_on_open_new" : false,

// Number of tabs to keep while closing tabs. Default is zero which closes
// all tabs.
"keep_number_of_tabs" : 0
}