22import subprocess
33import os
44import os .path
5+ import threading
6+ from time import sleep
57
68# Used for output suppression when calling subprocess functions; see
79# http://stackoverflow.com/questions/10251391/suppressing-output-in-python-subprocess-call
810devnull = open (os .devnull , 'w' )
911
12+ def start (): # Gets invoked at the bottom of this file.
13+ """
14+ Regularly (every 5s) updates the file_exclude_patterns setting from a
15+ background thread.
16+ """
17+ def run ():
18+ while True :
19+ update_file_exclude_patterns ()
20+ sleep (5 )
21+
22+ thread = threading .Thread (target = run )
23+ thread .daemon = True
24+ thread .start ()
25+
1026def update_file_exclude_patterns ():
1127 """
1228 Updates the "file_exclude_patterns" preference to include all .gitignored
@@ -23,9 +39,19 @@ def update_file_exclude_patterns():
2339 folder_exclude_patterns .append (path .rstrip ('/' ))
2440 else :
2541 file_exclude_patterns .append (path )
26- s .set ('file_exclude_patterns' , file_exclude_patterns )
27- s .set ('folder_exclude_patterns' , folder_exclude_patterns )
28- sublime .save_settings ("Preferences.sublime-settings" )
42+
43+ # Only make changes if anything has actually changed, to avoid spamming the
44+ # sublime console
45+ new_files = set (file_exclude_patterns )
46+ old_files = set (s .get ('file_exclude_patterns' , []))
47+ new_folders = set (folder_exclude_patterns )
48+ old_folders = set (s .get ('folder_exclude_patterns' , []))
49+
50+
51+ if new_files != old_files or new_folders != old_folders :
52+ s .set ('file_exclude_patterns' , file_exclude_patterns )
53+ s .set ('folder_exclude_patterns' , folder_exclude_patterns )
54+ sublime .save_settings ("Preferences.sublime-settings" )
2955
3056def all_ignored_paths ():
3157 """
@@ -139,4 +165,6 @@ def repo_ignored_paths(git_repo):
139165 relative_paths = [line .replace ('Would remove ' , '' , 1 ) for line in lines ]
140166 absolute_paths = [git_repo + '/' + path for path in relative_paths ]
141167
142- return absolute_paths
168+ return absolute_paths
169+
170+ start ()
0 commit comments