<commit_before>import sublime
from something_borrowed.diff_match_patch.diff_match_patch import diff_match_patch
import gscommon as gs

class MergeException(Exception):
	pass

def _merge(view, size, text, edit):
	def ss(start, end):
		return view.substr(sublime.Region(start, end))
	dmp = diff_match_patch()
	diffs = dmp.diff_main(ss(0, size), text)
	dmp.diff_cleanupEfficiency(diffs)
	i = 0
	dirty = False
	for d in diffs:
		k, s = d
		l = len(s)
		if k == 0:
			# match
			l = len(s)
			if ss(i, i+l) != s:
				raise MergeException('mismatch', dirty)
			i += l
		else:
			dirty = True
			if k > 0:
				# insert
				view.insert(edit, i, s)
				i += l
			else:
				# delete
				if ss(i, i+l) != s:
					raise MergeException('mismatch', dirty)
				view.erase(edit, sublime.Region(i, i+l))

def merge(view, size, text):
	if size < 0:
		size = view.size()
	edit = view.begin_edit()
	try:
		_merge(view, size, text, edit)
	except MergeException as (err, dirty):
		def cb():
			if dirty:
				view.run_command('undo')
			gs.notice("GsPatch", "Could not merge changes into the buffer, edit aborted: %s" % err)
		sublime.set_timeout(cb, 0)
		return err
	finally:
		view.end_edit(edit)
	return ''
<commit_msg>- return whether or not the buffer is now dirty and an error instead of   issuing a notice - refactor... - make sure to turn off translate_tabs_spaces<commit_after>import sublime
from something_borrowed.diff_match_patch.diff_match_patch import diff_match_patch
import gscommon as gs

class MergeException(Exception):
	pass

def _merge(view, size, text, edit):
	def ss(start, end):
		return view.substr(sublime.Region(start, end))
	dmp = diff_match_patch()
	diffs = dmp.diff_main(ss(0, size), text)
	dmp.diff_cleanupEfficiency(diffs)
	i = 0
	dirty = False
	for d in diffs:
		k, s = d
		l = len(s)
		if k == 0:
			# match
			l = len(s)
			if ss(i, i+l) != s:
				raise MergeException('mismatch', dirty)
			i += l
		else:
			dirty = True
			if k > 0:
				# insert
				view.insert(edit, i, s)
				i += l
			else:
				# delete
				if ss(i, i+l) != s:
					raise MergeException('mismatch', dirty)
				view.erase(edit, sublime.Region(i, i+l))
	return dirty

def merge(view, size, text):
	try:
		edit = view.begin_edit()
		dirty = False
		err = ''
		vs = view.settings()
		ttts = vs.get("translate_tabs_to_spaces")
		vs.set("translate_tabs_to_spaces", False)
		if size < 0:
			size = view.size()
		dirty = _merge(view, size, text, edit)
	except MergeException as (err, d):
		dirty = d
		err = "Could not merge changes into the buffer, edit aborted: %s" % err
	except Exception as ex:
		err = "where ma bees at?: %s" % ex
	finally:
		view.end_edit(edit)
		vs.set("translate_tabs_to_spaces", ttts)
		return (dirty, err)

{'fraction_non_alphanumeric': 0.12661498708010335, 'fraction_numerical': 0.004060538944259874, 'mean_word_length': 3.4499178981937604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6359790', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1031, 'n_words': 300}