Marcus Williams
2008-Jan-19 18:42 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
This adds the ability to stop the current threading operation. This is
usually a search, but its anything that ends up calling load_n_threads
in thread-index-view. The user can hit ctrl-g to stop the operation.
---
lib/sup/modes/thread-index-mode.rb | 34 +++++++++++++++++++++++++++++-----
lib/sup/thread.rb | 2 +-
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb
b/lib/sup/modes/thread-index-mode.rb
index dec3c1d..a265a04 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,7 @@ EOS
register_keymap do |k|
k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads",
''M''
+ k.add :cancel_search, "Cancel current search", :ctrl_g
k.add :reload, "Refresh view", ''@''
k.add :toggle_archived, "Toggle archived status",
''a''
k.add :toggle_starred, "Star or unstar all messages in thread",
''*''
@@ -50,6 +51,8 @@ EOS
@load_thread_opts = load_thread_opts
@hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
@date_width = DATE_WIDTH
+
+ @interrupt_search = false
initialize_threads # defines @ts and @ts_mutex
update # defines @text and @lines
@@ -456,16 +459,22 @@ EOS
## TODO: figure out @ts_mutex in this method
def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={}
+ @interrupt_search = false
@mbid = BufferManager.say "Searching for threads..."
+
+ ts_to_load = n
+ ts_to_load = ts_to_load + @ts.size unless n == -1 # -1 means all threads
+
orig_size = @ts.size
last_update = Time.now
- @ts.load_n_threads(@ts.size + n, opts) do |i|
+ @ts.load_n_threads(ts_to_load, opts) do |i|
if (Time.now - last_update) >= 0.25
- BufferManager.say "Loaded #{i.pluralize
''thread''}...", @mbid
+ BufferManager.say "Loaded #{i.pluralize
''thread''} (use ^G to cancel search)...", @mbid
update
BufferManager.draw_screen
last_update = Time.now
end
+ break if @interrupt_search
end
@ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
@@ -485,13 +494,28 @@ EOS
end
end
- def load_threads opts={}
- n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+ def cancel_search
+ @interrupt_search = true
+ end
+ def load_all_threads
+ load_threads :num => -1
+ end
+
+ def load_threads opts={}
+ if opts[:num].nil?
+ n = ThreadIndexMode::LOAD_MORE_THREAD_NUM
+ else
+ n = opts[:num]
+ end
+
myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
opts[:when_done].call(num) if opts[:when_done]
+
+ cancelled = @interrupt_search?" (search cancelled by
user)":""
+
if num > 0
- BufferManager.flash "Found #{num.pluralize
''thread''}."
+ BufferManager.flash "Found #{num.pluralize
''thread''}#{cancelled}."
else
BufferManager.flash "No matches."
end
diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb
index 32002c4..09fbfbb 100644
--- a/lib/sup/thread.rb
+++ b/lib/sup/thread.rb
@@ -324,7 +324,7 @@ class ThreadSet
## load in (at most) num number of threads from the index
def load_n_threads num, opts={}
@index.each_id_by_date opts do |mid, builder|
- break if size >= num
+ break if size >= num unless num == -1
next if contains_id? mid
m = builder.call
--
1.5.3.7
Marcus Williams
2008-Jan-19 18:49 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
On 19.1.2008, I wrote:> This adds the ability to stop the current threading operation. This > is usually a search, but its anything that ends up calling > load_n_threads in thread-index-view. The user can hit ctrl-g to stop > the operation.bah... sorry sent a duff patch that included some stuff for the load all threads option. Will resend again so ignore that one! Marcus
Marcus Williams
2008-Jan-19 18:59 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
This adds the ability to stop the current threading operation. This is
usually a search, but its anything that ends up calling load_n_threads
in thread-index-view. The user can hit ctrl-g to stop the operation.
---
lib/sup/modes/thread-index-mode.rb | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb
b/lib/sup/modes/thread-index-mode.rb
index dec3c1d..2b8cc20 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,7 @@ EOS
register_keymap do |k|
k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads",
''M''
+ k.add :cancel_search, "Cancel current search", :ctrl_g
k.add :reload, "Refresh view", ''@''
k.add :toggle_archived, "Toggle archived status",
''a''
k.add :toggle_starred, "Star or unstar all messages in thread",
''*''
@@ -50,6 +51,8 @@ EOS
@load_thread_opts = load_thread_opts
@hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
@date_width = DATE_WIDTH
+
+ @interrupt_search = false
initialize_threads # defines @ts and @ts_mutex
update # defines @text and @lines
@@ -456,16 +459,19 @@ EOS
## TODO: figure out @ts_mutex in this method
def load_n_threads n=LOAD_MORE_THREAD_NUM, opts={}
+ @interrupt_search = false
@mbid = BufferManager.say "Searching for threads..."
+
orig_size = @ts.size
last_update = Time.now
@ts.load_n_threads(@ts.size + n, opts) do |i|
if (Time.now - last_update) >= 0.25
- BufferManager.say "Loaded #{i.pluralize
''thread''}...", @mbid
+ BufferManager.say "Loaded #{i.pluralize
''thread''} (use ^G to cancel)...", @mbid
update
BufferManager.draw_screen
last_update = Time.now
end
+ break if @interrupt_search
end
@ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
@@ -485,13 +491,20 @@ EOS
end
end
+ def cancel_search
+ @interrupt_search = true
+ end
+
def load_threads opts={}
n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
myopts = @load_thread_opts.merge({ :when_done => (lambda do |num|
opts[:when_done].call(num) if opts[:when_done]
+
+ cancelled = @interrupt_search?" (search cancelled by
user)":""
+
if num > 0
- BufferManager.flash "Found #{num.pluralize
''thread''}."
+ BufferManager.flash "Found #{num.pluralize
''thread''}#{cancelled}."
else
BufferManager.flash "No matches."
end
--
1.5.3.7
William Morgan
2008-Jan-23 19:15 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
Reformatted excerpts from Marcus Williams''s message of 2008-01-19:> This adds the ability to stop the current threading operation. This is > usually a search, but its anything that ends up calling load_n_threads > in thread-index-view. The user can hit ctrl-g to stop the operation.This looks great. I have a mild preference for not changing the messages, and there just being a general expectation of ^G being a cancelling key in Sup like it is in Emacs, but I''m open to suggestion by others. I''m merging this into next and we can all meditate on it. I''m slowly working my way through the other patches, so have patience, everyone. -- William <wmorgan-sup at masanjin.net>
Marcus Williams
2008-Jan-23 20:14 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
On 23.1.2008, William Morgan wrote:> Reformatted excerpts from Marcus Williams''s message of 2008-01-19: > > This adds the ability to stop the current threading operation. This is > > usually a search, but its anything that ends up calling load_n_threads > > in thread-index-view. The user can hit ctrl-g to stop the operation. > > This looks great. I have a mild preference for not changing the > messages, and there just being a general expectation of ^G being a > cancelling key in Sup like it is in Emacs, but I''m open to suggestion by > others.My feeling was it wasnt obvious that you could cancel the operation without it. If there was some way of making that more obvious somewhere then the message could be removed. I didnt even realise I could use ^G elsewhere until fairly recently! Marcus
William Morgan
2008-Feb-03 01:06 UTC
[sup-talk] [PATCH] Add ability to interrupt current thread operation (search)
Reformatted excerpts from Marcus Williams''s message of 2008-01-23:> My feeling was it wasnt obvious that you could cancel the operation > without it. If there was some way of making that more obvious > somewhere then the message could be removed. I didnt even realise I > could use ^G elsewhere until fairly recently!After trying it, I do like it better without the extra messages, so next currently has them removed. I could make ^G more promiment in the new user''s guide... -- William <wmorgan-sup at masanjin.net>