commit b083030f2444004436cbe464f9ca1d43d753b125
parent 900eb843f582b54bed3446a3aa0d60405f2ade67
Author: Hamish Downer <dmishd@gmail.com>
Date: Wed, 16 Feb 2011 00:15:14 +0000
debug statements, better message in async mode
Diffstat:
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/lib/sup/modes/edit-message-async-mode.rb b/lib/sup/modes/edit-message-async-mode.rb
@@ -8,11 +8,11 @@ class EditMessageAsyncMode < LineCursorMode
k.add :edit_finished, "Finished editing message", 'E'
end
- def initialize parent_edit_mode, file_path
+ def initialize parent_edit_mode, file_path, msg_subject
@parent_edit_mode = parent_edit_mode
@file_path = file_path
- @text = ["Your message is saved in a file:", "", @file_path, "",
+ @text = ["", "Your message with subject:", msg_subject, "is saved in a file:", "", @file_path, "",
"You can edit your message in the editor of your choice and continue to",
"use sup while you edit your message.", "",
"When you have finished editing, select this buffer and press 'E'.",]
@@ -41,18 +41,26 @@ protected
return false
end
+ debug "Async mode exiting - file is not being edited"
@parent_edit_mode.edit_message_async_resume
BufferManager.kill_buffer buffer
+ true
end
def file_being_edited?
+ debug "Checking if file is being edited"
begin
File.open(@file_path, 'r') { |f|
- return true if !f.flock(File::LOCK_EX|File::LOCK_NB)
+ if !f.flock(File::LOCK_EX|File::LOCK_NB)
+ debug "could not get exclusive lock on file"
+ return true
+ end
}
- rescue
+ rescue => e
+ debug "Some exception occured when opening file, #{e.class}: #{e.to_s}"
return true
end
+ debug "File is not being edited"
false
end
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -197,28 +197,29 @@ EOS
# put up buffer saying you can now edit the message in another
# terminal or app, and continue to use sup in the meantime.
- @async_mode = EditMessageAsyncMode.new self, @file.path
- BufferManager.spawn "Waiting for message \"#{@header["Subject"]}\" to be finished", @async_mode
+ subject = @header["Subject"] || ""
+ @async_mode = EditMessageAsyncMode.new self, @file.path, subject
+ BufferManager.spawn "Waiting for message \"#{subject}\" to be finished", @async_mode
# hide ourselves, and wait for signal to resume from async mode ...
buffer.hidden = true
+ debug "Edit mode buffer is now hidden"
end
def edit_message_async_resume
buffer.hidden = false
+ debug "Edit mode buffer is now unhidden"
@async_mode = nil
BufferManager.focus_on buffer
@edited = true if File.mtime(@file.path) > @mtime
- return @edited unless @edited
-
header, @body = parse_file @file.path
@header = header - NON_EDITABLE_HEADERS
handle_new_text @header, @body
update
- @edited
+ true
end
def killable?