Permalink
Browse files

PEP-8 Formatting: 4 space tabs

  • Loading branch information...
1 parent 85a2cae commit 3659c73dc184ce8f8e4056d06237b9a8f88cd758 @fogleman fogleman committed Dec 14, 2012
Showing with 218 additions and 218 deletions.
  1. +54 −54 git_gutter.py
  2. +9 −9 git_gutter_events.py
  3. +80 −80 git_gutter_handler.py
  4. +21 −21 git_helper.py
  5. +54 −54 view_collection.py
View
@@ -3,57 +3,57 @@
from view_collection import ViewCollection
class GitGutterCommand(sublime_plugin.TextCommand):
- def run(self, edit):
- self.clear_all()
-
- (inserted, modified, deleted) = ViewCollection.diff(self.view)
-
- self.lines_removed(deleted)
- self.lines_added(inserted)
- self.lines_modified(modified)
-
- def clear_all(self):
- self.view.erase_regions('git_gutter_deleted_top')
- self.view.erase_regions('git_gutter_deleted_bottom')
- self.view.erase_regions('git_gutter_inserted')
- self.view.erase_regions('git_gutter_changed')
-
- def lines_to_regions(self, lines):
- regions = []
- for line in lines:
- position = self.view.text_point(line-1, 0)
- region = sublime.Region(position,position)
- regions.append(region)
- return regions
-
- def lines_removed(self, lines):
- bottom_lines = []
- for line in lines:
- if not line == 1:
- bottom_lines.append(line-1)
- self.lines_removed_top(lines)
- self.lines_removed_bottom(bottom_lines)
-
- def lines_removed_top(self, lines):
- regions = self.lines_to_regions(lines)
- scope = "markup.deleted"
- icon = '../GitGutter/icons/deleted_top'
- self.view.add_regions('git_gutter_deleted_top', regions, scope, icon)
-
- def lines_removed_bottom(self, lines):
- regions = self.lines_to_regions(lines)
- scope = "markup.deleted"
- icon = '../GitGutter/icons/deleted_bottom'
- self.view.add_regions('git_gutter_deleted_bottom', regions, scope, icon)
-
- def lines_added(self, lines):
- regions = self.lines_to_regions(lines)
- scope = "markup.inserted"
- icon = '../GitGutter/icons/inserted'
- self.view.add_regions('git_gutter_inserted', regions, scope, icon)
-
- def lines_modified(self, lines):
- regions = self.lines_to_regions(lines)
- scope = "markup.changed"
- icon = '../GitGutter/icons/changed'
- self.view.add_regions('git_gutter_changed', regions, scope, icon)
+ def run(self, edit):
+ self.clear_all()
+
+ (inserted, modified, deleted) = ViewCollection.diff(self.view)
+
+ self.lines_removed(deleted)
+ self.lines_added(inserted)
+ self.lines_modified(modified)
+
+ def clear_all(self):
+ self.view.erase_regions('git_gutter_deleted_top')
+ self.view.erase_regions('git_gutter_deleted_bottom')
+ self.view.erase_regions('git_gutter_inserted')
+ self.view.erase_regions('git_gutter_changed')
+
+ def lines_to_regions(self, lines):
+ regions = []
+ for line in lines:
+ position = self.view.text_point(line-1, 0)
+ region = sublime.Region(position,position)
+ regions.append(region)
+ return regions
+
+ def lines_removed(self, lines):
+ bottom_lines = []
+ for line in lines:
+ if not line == 1:
+ bottom_lines.append(line-1)
+ self.lines_removed_top(lines)
+ self.lines_removed_bottom(bottom_lines)
+
+ def lines_removed_top(self, lines):
+ regions = self.lines_to_regions(lines)
+ scope = 'markup.deleted'
+ icon = '../GitGutter/icons/deleted_top'
+ self.view.add_regions('git_gutter_deleted_top', regions, scope, icon)
+
+ def lines_removed_bottom(self, lines):
+ regions = self.lines_to_regions(lines)
+ scope = 'markup.deleted'
+ icon = '../GitGutter/icons/deleted_bottom'
+ self.view.add_regions('git_gutter_deleted_bottom', regions, scope, icon)
+
+ def lines_added(self, lines):
+ regions = self.lines_to_regions(lines)
+ scope = 'markup.inserted'
+ icon = '../GitGutter/icons/inserted'
+ self.view.add_regions('git_gutter_inserted', regions, scope, icon)
+
+ def lines_modified(self, lines):
+ regions = self.lines_to_regions(lines)
+ scope = 'markup.changed'
+ icon = '../GitGutter/icons/changed'
+ self.view.add_regions('git_gutter_changed', regions, scope, icon)
View
@@ -4,15 +4,15 @@
class GitGutterEvents(sublime_plugin.EventListener):
- def on_load(self, view):
- ViewCollection.add(view)
+ def on_load(self, view):
+ ViewCollection.add(view)
- def on_modified(self, view):
- if view.settings().get('git_gutter_live_mode', True):
- ViewCollection.add(view)
+ def on_modified(self, view):
+ if view.settings().get('git_gutter_live_mode', True):
+ ViewCollection.add(view)
- def on_clone(self, view):
- ViewCollection.add(view)
+ def on_clone(self, view):
+ ViewCollection.add(view)
- def on_post_save(self, view):
- ViewCollection.add(view)
+ def on_post_save(self, view):
+ ViewCollection.add(view)
View
@@ -5,98 +5,98 @@
from view_collection import ViewCollection
class GitGutterHandler:
- def __init__(self, view):
- self.view = view
- self.git_temp_file = ViewCollection.git_tmp_file(self.view)
- self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
- if self.on_disk():
- self.git_tree = git_helper.git_tree(self.view)
- self.git_dir = git_helper.git_dir(self.git_tree)
- self.git_path = git_helper.git_file_path(self.view, self.git_tree)
+ def __init__(self, view):
+ self.view = view
+ self.git_temp_file = ViewCollection.git_tmp_file(self.view)
+ self.buf_temp_file = ViewCollection.buf_tmp_file(self.view)
+ if self.on_disk():
+ self.git_tree = git_helper.git_tree(self.view)
+ self.git_dir = git_helper.git_dir(self.git_tree)
+ self.git_path = git_helper.git_file_path(self.view, self.git_tree)
- def on_disk(self):
- # if the view is saved to disk
- return self.view.file_name() != None
+ def on_disk(self):
+ # if the view is saved to disk
+ return self.view.file_name() != None
- def reset(self):
- if self.on_disk() and self.git_path:
- self.view.run_command('git_gutter')
+ def reset(self):
+ if self.on_disk() and self.git_path:
+ self.view.run_command('git_gutter')
- def get_git_path(self):
- return self.git_path
+ def get_git_path(self):
+ return self.git_path
- def update_buf_file(self):
- chars = self.view.size()
- region = sublime.Region(0,chars)
- contents = self.view.substr(region).encode("utf-8")
- contents = contents.replace('\r\n', '\n')
- contents = contents.replace('\r', '\n')
- f = open(self.buf_temp_file.name,'w')
- f.write(contents)
- f.close()
-
- def update_git_file(self):
- # the git repo won't change that often
- # so we can easily wait 5 seconds
- # between updates for performance
- if ViewCollection.git_time(self.view) > 5:
- self.git_temp_file.truncate()
- args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','HEAD:'+self.git_path]
- try:
- proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- contents = proc.stdout.read()
+ def update_buf_file(self):
+ chars = self.view.size()
+ region = sublime.Region(0,chars)
+ contents = self.view.substr(region).encode('utf-8')
contents = contents.replace('\r\n', '\n')
contents = contents.replace('\r', '\n')
- f = open(self.git_temp_file.name,'w')
+ f = open(self.buf_temp_file.name,'w')
f.write(contents)
f.close()
- ViewCollection.update_git_time(self.view)
- except Exception:
- pass
- def process_diff(self,diff_str):
- inserted = []
- modified = []
- deleted = []
+ def update_git_file(self):
+ # the git repo won't change that often
+ # so we can easily wait 5 seconds
+ # between updates for performance
+ if ViewCollection.git_time(self.view) > 5:
+ self.git_temp_file.truncate()
+ args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','HEAD:'+self.git_path]
+ try:
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ contents = proc.stdout.read()
+ contents = contents.replace('\r\n', '\n')
+ contents = contents.replace('\r', '\n')
+ f = open(self.git_temp_file.name,'w')
+ f.write(contents)
+ f.close()
+ ViewCollection.update_git_time(self.view)
+ except Exception:
+ pass
- lines = diff_str.splitlines()
- for line in lines:
- m = re.match("(\d+),?(\d*)(.)(\d+),?(\d*)", line)
- if not m:
- continue
- kind = m.group(3)
- original_line_start = int(m.group(1))
- if len(m.group(2)) > 0:
- original_line_end = int(m.group(2))
- else:
- original_line_end = original_line_start
- line_start = int(m.group(4))
- if len(m.group(5)) > 0:
- line_end = int(m.group(5))
- else:
- line_end = line_start
+ def process_diff(self,diff_str):
+ inserted = []
+ modified = []
+ deleted = []
- if kind == 'c':
- modified += range(line_start,line_end+1)
- elif kind == 'a':
- inserted += range(line_start,line_end+1)
- elif kind == 'd':
- if line == 1:
- deleted.append(line_start)
- else:
- deleted.append(line_start+1)
+ lines = diff_str.splitlines()
+ for line in lines:
+ m = re.match('(\d+),?(\d*)(.)(\d+),?(\d*)', line)
+ if not m:
+ continue
+ kind = m.group(3)
+ original_line_start = int(m.group(1))
+ if len(m.group(2)) > 0:
+ original_line_end = int(m.group(2))
+ else:
+ original_line_end = original_line_start
+ line_start = int(m.group(4))
+ if len(m.group(5)) > 0:
+ line_end = int(m.group(5))
+ else:
+ line_end = line_start
- return (inserted, modified, deleted)
+ if kind == 'c':
+ modified += range(line_start,line_end+1)
+ elif kind == 'a':
+ inserted += range(line_start,line_end+1)
+ elif kind == 'd':
+ if line == 1:
+ deleted.append(line_start)
+ else:
+ deleted.append(line_start+1)
- def diff(self):
- if self.on_disk() and self.git_path:
- self.update_git_file()
- self.update_buf_file()
+ return (inserted, modified, deleted)
- args = ['diff',self.git_temp_file.name,self.buf_temp_file.name]
- proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- results = proc.stdout.read()
+ def diff(self):
+ if self.on_disk() and self.git_path:
+ self.update_git_file()
+ self.update_buf_file()
- return self.process_diff(results)
- else:
- return ([],[],[])
+ args = ['diff',self.git_temp_file.name,self.buf_temp_file.name]
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ results = proc.stdout.read()
+
+ return self.process_diff(results)
+ else:
+ return ([],[],[])
View
@@ -1,33 +1,33 @@
import os
def git_file_path(view, git_path):
- if not git_path:
- return False
- full_file_path = os.path.realpath(view.file_name())
- git_path_to_file = full_file_path.replace(git_path,'')
+ if not git_path:
+ return False
+ full_file_path = os.path.realpath(view.file_name())
+ git_path_to_file = full_file_path.replace(git_path,'')
- if git_path_to_file[0] == "/":
- git_path_to_file = git_path_to_file[1:]
+ if git_path_to_file[0] == '/':
+ git_path_to_file = git_path_to_file[1:]
- return git_path_to_file
+ return git_path_to_file
def git_root(directory):
- if os.path.exists(os.path.join(directory, '.git')):
- return directory
- else:
- parent = os.path.realpath(os.path.join(directory, os.path.pardir))
- if parent == directory:
- # we have reached root dir
- return False
+ if os.path.exists(os.path.join(directory, '.git')):
+ return directory
else:
- return git_root(parent)
+ parent = os.path.realpath(os.path.join(directory, os.path.pardir))
+ if parent == directory:
+ # we have reached root dir
+ return False
+ else:
+ return git_root(parent)
def git_tree(view):
- full_file_path = view.file_name()
- file_parent_dir = os.path.realpath(os.path.dirname(full_file_path))
- return git_root(file_parent_dir)
+ full_file_path = view.file_name()
+ file_parent_dir = os.path.realpath(os.path.dirname(full_file_path))
+ return git_root(file_parent_dir)
def git_dir(directory):
- if not directory:
- return False
- return os.path.join(directory, '.git')
+ if not directory:
+ return False
+ return os.path.join(directory, '.git')
Oops, something went wrong.

0 comments on commit 3659c73

Please sign in to comment.