commit 96364b5a2e36ad96d39644e2ae19381735f5f263
parent 575be4748c62d9958cdbeb3660d97d04ee04e0b7
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Wed, 2 Jun 2010 23:53:03 +0200
Jump and open next/previous message with C-n and C-p
Added functionality and key bindings for thread-view-mode where you can jump
_and_ open the next message. If a message has been opened by the jump it
will be closed if you continue to jump (in either direction). This is
saved in :toggled_state in the layout.
I often want to just jump to the next message to be able to skim through
a whole thread, if there was a key binding; jump and then hit enter
would work - but this patch gives me exactly what I want.
I'm not entirely happy with the key bindings, but there are not that many
left.
Signed-off-by: Gaute Hope
Diffstat:
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -3,7 +3,7 @@ module Redwood
class ThreadViewMode < LineCursorMode
## this holds all info we need to lay out a message
class MessageLayout
- attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color, :star_color, :orig_new
+ attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color, :star_color, :orig_new, :toggled_state
end
class ChunkLayout
@@ -54,7 +54,9 @@ EOS
k.add :edit_labels, "Edit or add labels for a thread", 'l'
k.add :expand_all_quotes, "Expand/collapse all quotes in a message", 'o'
k.add :jump_to_next_open, "Jump to next open message", 'n'
+ k.add :jump_to_next_and_open, "Jump to next message and open", "\C-n"
k.add :jump_to_prev_open, "Jump to previous open message", 'p'
+ k.add :jump_to_prev_and_open, "Jump to previous message and open", "\C-p"
k.add :align_current_message, "Align current message in buffer", 'z'
k.add :toggle_starred, "Star or unstar message", '*'
k.add :toggle_new, "Toggle unread/read status of message", 'N'
@@ -129,6 +131,7 @@ EOS
next unless m
earliest ||= m
@layout[m].state = initial_state_for m
+ @layout[m].toggled_state = false
@layout[m].color = altcolor ? :alternate_patina_color : :message_patina_color
@layout[m].star_color = altcolor ? :alternate_starred_patina_color : :starred_patina_color
@layout[m].orig_new = m.has_label? :read
@@ -440,6 +443,29 @@ EOS
end
end
+ def jump_to_next_and_open
+ return continue_search_in_buffer if in_search? # err.. don't know why im doing this
+
+ m = (curpos ... @message_lines.length).argfind { |i| @message_lines[i] }
+ return unless m
+
+ if @layout[m].toggled_state == true
+ @layout[m].state = :closed
+ @layout[m].toggled_state = false
+ update
+ end
+
+ nextm = @layout[m].next
+ if @layout[nextm].state == :closed
+ @layout[nextm].state = :open
+ @layout[nextm].toggled_state = true
+ end
+
+ jump_to_message nextm if nextm
+
+ update if @layout[nextm].toggled_state
+ end
+
def jump_to_next_open force_alignment=nil
return continue_search_in_buffer if in_search? # hack: allow 'n' to apply to both operations
m = (curpos ... @message_lines.length).argfind { |i| @message_lines[i] }
@@ -456,6 +482,26 @@ EOS
jump_to_message m, true
end
+ def jump_to_prev_and_open force_alignment=nil
+ m = (0 .. curpos).to_a.reverse.argfind { |i| @message_lines[i] }
+ return unless m
+
+ if @layout[m].toggled_state == true
+ @layout[m].state = :closed
+ @layout[m].toggled_state = false
+ update
+ end
+
+ nextm = @layout[m].prev
+ if @layout[nextm].state == :closed
+ @layout[nextm].state = :open
+ @layout[nextm].toggled_state = true
+ end
+
+ jump_to_message nextm if nextm
+ update if @layout[nextm].toggled_state
+ end
+
def jump_to_prev_open
m = (0 .. curpos).to_a.reverse.argfind { |i| @message_lines[i] } # bah, .to_a
return unless m