diff --git a/application.py b/application.py index 35275f2..4e8c2c2 100755 --- a/application.py +++ b/application.py @@ -442,7 +442,7 @@ class Application(object): # buffer handling def new_file_buffer(self, path, data, switch_to=True): assert not self.has_buffer_name(path), '%r is already open' % path - assert not os.path.exists(path), '%r already exists' % path + #assert not os.path.exists(path), '%r already exists' % path # touch the file f = open(path, 'w') f.write(data) diff --git a/method/buffers.py b/method/buffers.py index d34886c..8217750 100644 --- a/method/buffers.py +++ b/method/buffers.py @@ -115,6 +115,7 @@ class SaveBufferAs(Method): class SaveBuffer(Method): '''Save the contents of a buffer''' def _execute(self, w, **vargs): + a = w.application if not w.buffer.changed(): w.set_error("(No changes need to be saved)") return @@ -125,7 +126,18 @@ class SaveBuffer(Method): w.buffer.save(force=True) w.set_error("File had disappeared! Wrote %s" % (w.buffer.path)) except buffer.FileChangedError, e: - pass + path1 = w.buffer.path + tf = tempfile.NamedTemporaryFile(delete=False) + tf.write(w.buffer.make_string()) + tf.close() + path2 = tf.name + a.methods['diff'].execute(w, path1=path1, path2=path2) + w.set_error("File changed on disk; showing differences") +class ReloadBuffer(Method): + '''Reload the contents of a buffer from the filesystem''' + def _execute(self, w, **vargs): + w.buffer.reload() + w.set_error("Buffer contents reloaded from %r" % w.buffer.path) class ToggleTabs(Method): '''Toggle whether to write tabs out or not (defaults to false)'''