From: web-sup@superscript.com (William Erik Baxter)
Subject: [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display.
Date: Fri, 18 Sep 2009 15:54:18 -0400 [thread overview]
Message-ID: <1253303493-sup-288@kronos> (raw)
---
lib/sup/modes/label-list-mode.rb | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb
index f65ec2e..d94f56f 100644
--- a/lib/sup/modes/label-list-mode.rb
+++ b/lib/sup/modes/label-list-mode.rb
@@ -8,6 +8,24 @@ class LabelListMode < LineCursorMode
k.add :toggle_show_unread_only, "Toggle between showing all labels and those with unread mail", 'u'
end
+ HookManager.register "label-list-filter", <<EOS
+Filter the label list, typically to sort.
+Variables:
+ counted: an array of counted labels.
+Return value:
+ An array of counted labels with sort_by output structure.
+EOS
+
+ HookManager.register "label-list-format", <<EOS
+Create the sprintf format string for label-list-mode.
+Variables:
+ width: the maximum label width
+ tmax: the maximum total message count
+ umax: the maximum unread message count
+Return value:
+ A format string for sprintf
+EOS
+
def initialize
@labels = []
@text = []
@@ -50,14 +68,22 @@ protected
@text = []
labels = LabelManager.all_labels
- counts = labels.map do |label|
+ counted = labels.map do |label|
string = LabelManager.string_for label
total = Index.num_results_for :label => label
unread = (label == :unread)? total : Index.num_results_for(:labels => [label, :unread])
[label, string, total, unread]
- end.sort_by { |l, s, t, u| s.downcase }
+ end
+
+ if HookManager.enabled? "label-list-filter"
+ counts = HookManager.run "label-list-filter", :counted => counted
+ else
+ counts = counted.sort_by { |l, s, t, u| s.downcase }
+ end
width = counts.max_of { |l, s, t, u| s.length }
+ tmax = counts.max_of { |l, s, t, u| t }
+ umax = counts.max_of { |l, s, t, u| u }
if @unread_only
counts.delete_if { | l, s, t, u | u == 0 }
@@ -78,8 +104,13 @@ protected
next
end
+ fmt = HookManager.run "label-list-format", :width => width, :tmax => tmax, :umax => umax
+ if !fmt
+ fmt = "%#{width + 1}s %5d %s, %5d unread"
+ end
+
@text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
- sprintf("%#{width + 1}s %5d %s, %5d unread", string, total, total == 1 ? " message" : "messages", unread)]]
+ sprintf(fmt, string, total, total == 1 ? " message" : "messages", unread)]]
@labels << [label, unread]
yield i if block_given?
end.compact
--
1.5.3.2
next reply other threads:[~2009-09-18 19:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-18 19:54 William Erik Baxter [this message]
2009-10-01 16:58 ` William Morgan
[not found] ` <1254418284-sup-3486@kronos>
2009-10-12 13:30 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1253303493-sup-288@kronos \
--to=web-sup@superscript.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox