]> git.cworth.org Git - sup/commitdiff
Merge branch 'master' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Sat, 16 Feb 2008 13:56:13 +0000 (05:56 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Sat, 16 Feb 2008 13:56:13 +0000 (05:56 -0800)
13 files changed:
Rakefile
bin/sup
lib/sup/buffer.rb
lib/sup/index.rb
lib/sup/modes/compose-mode.rb
lib/sup/modes/contact-list-mode.rb
lib/sup/modes/edit-message-mode.rb
lib/sup/modes/scroll-mode.rb
lib/sup/modes/search-results-mode.rb
lib/sup/modes/thread-index-mode.rb
lib/sup/modes/thread-view-mode.rb
lib/sup/tagger.rb
lib/sup/thread.rb

index f99246f7376c4d8ce634840eb2a2a186625964ba..289da642aeddb4a2ea02528f50f55d932c7638f1 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -9,9 +9,13 @@ end # thanks to "Mike H"
 
 ## allow people who use development versions by running "rake gem"
 ## and installing the resulting gem it to be able to do this. (gem
-## versions must be in dotted-digit notation only).
-version = Redwood::VERSION == "git" ? "999" : Redwood::VERSION
-
+## versions must be in dotted-digit notation only and can be passed
+## with the REL environment variable to "rake gem").
+if ENV['REL']
+  version = ENV['REL']
+else
+  version = Redwood::VERSION == "git" ? "999" : Redwood::VERSION
+end
 Hoe.new('sup', version) do |p|
   p.rubyforge_name = 'sup'
   p.author = "William Morgan"
diff --git a/bin/sup b/bin/sup
index 95b0af7409b1aa72145df5375c278b5db5d24825..84fd77c5d07df9b2fc4f16b09cfa17dced6cfbec 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -32,10 +32,11 @@ Usage:
 
 Options are:
 EOS
-  opt :list_hooks, "List all hooks and descriptions thereof, and quit."
-  opt :no_threads, "Turn of threading. Helps with debugging. (Necessarily disables background polling for new messages.)"
+  opt :list_hooks, "List all hooks and descriptions, and quit."
+  opt :no_threads, "Turn off threading. Helps with debugging. (Necessarily disables background polling for new messages.)"
   opt :no_initial_poll, "Don't poll for new messages when starting."
-  opt :search, "Search for threads ", :type => String
+  opt :search, "Search for this query upon startup", :type => String
+  opt :compose, "Compose message to this recipient upon startup", :type => String
 end
 
 if $opts[:list_hooks]
@@ -198,6 +199,10 @@ begin
   
   imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] }
 
+  if $opts[:compose]
+    ComposeMode.spawn_nicely :to_default => $opts[:compose]
+  end
+
   unless $opts[:no_threads]
     PollManager.start
     SuicideManager.start
index 4374fa82be83de4db6c9b573bdc54e6bc57eb4d1..d40a6267d193cb01905c38efbf38bfad581463ba 100644 (file)
@@ -455,7 +455,7 @@ EOS
         elsif File.directory?(answer)
           spawn_modal "file browser", FileBrowserMode.new(answer)
         else
-          answer
+          File.expand_path answer
         end
     end
 
@@ -557,7 +557,6 @@ EOS
 
   def ask_getch question, accept=nil
     raise "impossible!" if @asking
-    @asking = true
 
     accept = accept.split(//).map { |x| x[0] } if accept
 
@@ -570,6 +569,7 @@ EOS
       Ncurses.refresh
     end
 
+    @asking = true
     ret = nil
     done = false
     until done
index cf2ac6dba1ddb4694415795573612a839e8df291..e6e91984332a24cf0a281f3ad8646a24c6a3008d 100644 (file)
@@ -125,9 +125,13 @@ EOS
     @sources[source.id] = source
   end
 
-  def source_for uri; @sources.values.find { |s| s.is_source_for? uri }; end
-  def usual_sources; @sources.values.find_all { |s| s.usual? }; end
-  def sources; @sources.values; end
+  def sources
+    ## favour the inbox by listing non-archived sources first
+    @sources.values.sort_by { |s| s.id }.partition { |s| !s.archived? }.flatten
+  end
+
+  def source_for uri; sources.find { |s| s.is_source_for? uri }; end
+  def usual_sources; sources.find_all { |s| s.usual? }; end
 
   def load_index dir=File.join(@dir, "ferret")
     if File.exists? dir
@@ -512,7 +516,7 @@ protected
         File.chmod 0600, fn
         FileUtils.mv fn, bakfn, :force => true unless File.exists?(bakfn) && File.size(fn) == 0
       end
-      Redwood::save_yaml_obj @sources.values.sort_by { |s| s.id.to_i }, fn, true
+      Redwood::save_yaml_obj sources.sort_by { |s| s.id.to_i }, fn, true
       File.chmod 0600, fn
     end
     @sources_dirty = false
index f063b92129a9487cf9fc6e2a26b450095d3711e5..7674d7bda63538c5014e4e32aa4740f13203f01f 100644 (file)
@@ -20,7 +20,7 @@ class ComposeMode < EditMessageMode
   end
 
   def self.spawn_nicely opts={}
-    to = opts[:to] || BufferManager.ask_for_contacts(:people, "To: ") or return
+    to = opts[:to] || BufferManager.ask_for_contacts(:people, "To: ", [opts[:to_default]]) or return
     cc = opts[:cc] || (BufferManager.ask_for_contacts(:people, "Cc: ") or return if $config[:ask_for_cc])
     bcc = opts[:bcc] || (BufferManager.ask_for_contacts(:people, "Bcc: ") or return if $config[:ask_for_bcc])
     subj = opts[:subj] || (BufferManager.ask(:subject, "Subject: ") or return if $config[:ask_for_subject])
index f7b3ccb567c3b3ec8be6e03dd56ed685c08d9215..7c16babd61aacf220998bfb93aca300c0629d112 100644 (file)
@@ -29,7 +29,7 @@ class ContactListMode < LineCursorMode
 
   def initialize mode=:regular
     @mode = mode
-    @tags = Tagger.new self
+    @tags = Tagger.new self, "contact"
     @num = nil
     @text = []
     super()
index 6a7f273b4ec18d59f14919ec10c8c9e6fb9262e6..f4d933387c84be3758fd64575f911a39fc7a1c7d 100644 (file)
@@ -148,9 +148,13 @@ EOS
   def attach_file
     fn = BufferManager.ask_for_filename :attachment, "File name (enter for browser): "
     return unless fn
-    @attachments << RMail::Message.make_file_attachment(fn)
-    @attachment_names << fn
-    update
+    begin
+      @attachments << RMail::Message.make_file_attachment(fn)
+      @attachment_names << fn
+      update
+    rescue SystemCallError => e
+      BufferManager.flash "Can't read #{fn}: #{e.message}"
+    end
   end
 
   def delete_attachment
index 219a4ce33bb0271653775276b38ef1d88f6f9c6b..74783e5a8c1007ed71cd08c8aca8db58416bdbe8 100644 (file)
@@ -12,7 +12,7 @@ class ScrollMode < Mode
 
   attr_reader :status, :topline, :botline, :leftcol
 
-  COL_JUMP = 4
+  COL_JUMP = 2
 
   register_keymap do |k|
     k.add :line_down, "Down one line", :down, 'j', 'J'
index f64a227811802c1ea3ec64f5b6fbc1e352e33661..6fdc58a0c9da1f0df907ce8e29d786a36db9b4d7 100644 (file)
@@ -9,13 +9,13 @@ class SearchResultsMode < ThreadIndexMode
   end
 
   register_keymap do |k|
-    k.add :refine_search, "Refine search", '.'
+    k.add :refine_search, "Refine search", '|'
   end
 
   def refine_search
-    query = BufferManager.ask :search, "query: ", (@qobj.to_s + " ")
+    query = BufferManager.ask :search, "refine query: ", (@qobj.to_s + " ")
     return unless query && query !~ /^\s*$/
-    SearchResultsMode.spawn_from_query query, @qopts
+    SearchResultsMode.spawn_from_query query
   end
 
   ## a proper is_relevant? method requires some way of asking ferret
index b13729d1d1e0be49cf92ae0aec9a7489c5ecc2d9..e24d7e0398b01601faca320bd3dde650f130f773 100644 (file)
@@ -16,6 +16,10 @@ EOS
 
   register_keymap do |k|
     k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
+    k.add_multi "Load all threads (! to confirm) :", '!' do |kk|
+      kk.add :load_all_threads, "Load all threads (may list a _lot_ of threads)", '!'
+    end
+    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 +54,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
@@ -107,19 +113,32 @@ EOS
     threads.each { |t| select t }
   end
 
-  ## this is called by thread-view-modes when the user wants to view
-  ## the next thread without going to index-mode. we update the cursor
-  ## as a convenience.
+  ## these two methods are called by thread-view-modes when the user
+  ## wants to view the previous/next thread without going back to
+  ## index-mode. we update the cursor as a convenience.
   def launch_next_thread_after thread, &b
+    launch_another_thread thread, 1, &b
+  end
+
+  def launch_prev_thread_before thread, &b
+    launch_another_thread thread, -1, &b
+  end
+
+  def launch_another_thread thread, direction, &b
     l = @lines[thread] or return
+    target_l = l + direction
     t = @mutex.synchronize do
-      if l < @threads.length - 1
-        set_cursor_pos l + 1 # move out of mutex?
-        @threads[l + 1]
+      if target_l >= 0 && target_l < @threads.length
+        @threads[target_l]
       end
-    end or return
+    end
 
-    select t, b
+    if t # there's a next thread
+      set_cursor_pos target_l # move out of mutex?
+      select t, b
+    elsif b # no next thread. call the block anyways
+      b.call
+    end
   end
   
   def handle_single_message_labeled_update sender, m
@@ -166,10 +185,16 @@ EOS
   end
 
   def handle_deleted_update sender, m
-    @ts_mutex.synchronize do
-      return unless @ts.contains? m
-      @ts.remove_thread_containing_id m.id
-    end
+    t = @ts_mutex.synchronize { @ts.thread_for m }
+    return unless t
+    hide_thread t
+    update
+  end
+
+  def handle_spammed_update sender, m
+    t = @ts_mutex.synchronize { @ts.thread_for m }
+    return unless t
+    hide_thread t
     update
   end
 
@@ -457,16 +482,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
         update
         BufferManager.draw_screen
         last_update = Time.now
       end
+      break if @interrupt_search
     end
     @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
 
@@ -486,11 +517,24 @@ EOS
     end
   end
 
+  def cancel_search
+    @interrupt_search = true
+  end
+
+  def load_all_threads
+    load_threads :num => -1
+  end
+
   def load_threads opts={}
-    n = opts[:num] || ThreadIndexMode::LOAD_MORE_THREAD_NUM
+    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]
+
       if num > 0
         BufferManager.flash "Found #{num.pluralize 'thread'}."
       else
index 961fc5d0335e39a80332e813e4dcff010fa15aea..559c58ecd35bbf0c27588aaaabf0f86bdfe55aa9 100644 (file)
@@ -63,6 +63,14 @@ EOS
       kk.add :unread_and_next, "Mark this thread as unread, kill buffer, and view next", 'N'
       kk.add :do_nothing_and_next, "Kill buffer, and view next", 'n'
     end
+
+    k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read/do (n)othing:", ']' do |kk|
+      kk.add :archive_and_prev, "Archive this thread, kill buffer, and view previous", 'a'
+      kk.add :delete_and_prev, "Delete this thread, kill buffer, and view previous", 'd'
+      kk.add :spam_and_prev, "Mark this thread as spam, kill buffer, and view previous", 's'
+      kk.add :unread_and_prev, "Mark this thread as unread, kill buffer, and view previous", 'N'
+      kk.add :do_nothing_and_prev, "Kill buffer, and view previous", 'n'
+    end
   end
 
   ## there are a couple important instance variables we hold to format
@@ -318,6 +326,8 @@ EOS
     end
   end
 
+  IDEAL_TOP_CONTEXT = 3 # try and give 3 rows of top context
+  IDEAL_LEFT_CONTEXT = 4 # try and give 4 columns of left context
   def jump_to_message m, loose_alignment=false
     l = @layout[m]
     left = l.depth * INDENT_SPACES
@@ -325,19 +335,20 @@ EOS
 
     ## jump to the top line
     if loose_alignment
-      jump_to_line [l.top - 3, 0].max # give 3 lines of top context
+      jump_to_line [l.top - IDEAL_TOP_CONTEXT, 0].max # give 3 lines of top context
     else
       jump_to_line l.top
     end
 
     ## jump to the left column
-    if loose_alignment
-      ## try and give 4 columns of left context, but not if it means that
-      ## the right of the message is truncated.
-      jump_to_col [[left - 4, rightcol - l.width - 1].min, 0].max
-    else
-      jump_to_col left
-    end
+    ideal_left = left +
+      if loose_alignment
+        -IDEAL_LEFT_CONTEXT + (l.width - buffer.content_width + IDEAL_LEFT_CONTEXT + 1).clamp(0, IDEAL_LEFT_CONTEXT)
+      else
+        0
+      end
+
+    jump_to_col [ideal_left, 0].max
 
     ## either way, move the cursor to the first line
     set_cursor_pos l.top
@@ -380,6 +391,12 @@ EOS
   def unread_and_next; unread_and_then :next end
   def do_nothing_and_next; do_nothing_and_then :next end
 
+  def archive_and_prev; archive_and_then :prev end
+  def spam_and_prev; spam_and_then :prev end
+  def delete_and_prev; delete_and_then :prev end
+  def unread_and_prev; unread_and_then :prev end
+  def do_nothing_and_prev; do_nothing_and_then :prev end
+
   def archive_and_then op
     dispatch op do
       @thread.remove_label :inbox
@@ -416,15 +433,18 @@ EOS
     return if @dying
     @dying = true
 
+    l = lambda do
+      yield if block_given?
+      BufferManager.kill_buffer_safely buffer
+    end
+
     case op
     when :next
-      @index_mode.launch_next_thread_after(@thread) do
-        @thread.save Index if block_given? && yield
-        BufferManager.kill_buffer_safely buffer
-      end
+      @index_mode.launch_next_thread_after @thread, &l
+    when :prev
+      @index_mode.launch_prev_thread_before @thread, &l
     when :kill
-      @thread.save Index if yield
-      BufferManager.kill_buffer_safely buffer
+      l.call
     else
       raise ArgumentError, "unknown thread dispatch operation #{op.inspect}"
     end
index 3e72463fc0e90128c5dd39e4c3f3535d9bc2cd7f..d62f3404557d637af7c70631e780ad0c63b1df02 100644 (file)
@@ -1,9 +1,11 @@
 module Redwood
 
 class Tagger
-  def initialize mode
+  def initialize mode, noun="thread", plural_noun=nil
     @mode = mode
     @tagged = {}
+    @noun = noun
+    @plural_noun = plural_noun || (@noun + "s")
   end
 
   def tagged? o; @tagged[o]; end
@@ -21,7 +23,7 @@ class Tagger
       return
     end
 
-    noun = num_tagged == 1 ? "thread" : "threads"
+    noun = num_tagged == 1 ? @noun : @plural_noun
 
     unless action
       c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
index 32002c4062cb0e9d7aabf317375cf22eafdeee65..09fbfbbab81d5f6d6814a3e96e166e73370b4bd3 100644 (file)
@@ -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