From: wmorgan-sup@masanjin.net (William Morgan)
Subject: [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode
Date: Sat, 16 Feb 2008 12:06:32 -0800 [thread overview]
Message-ID: <1203192317-sup-4404@south> (raw)
In-Reply-To: <1203192249-sup-6640@south>
---
Here's a "starter patch". Still needs HookManager integration to
actually view the URLs, and probably some touching up of the extraction
to trim out punctuation and the like. I found that URI.extract is very
general unless you restrict it to particular schemata, so this limits it
to http and ftp only. Feel free to expand/tweak any of it.
lib/sup.rb | 1 +
lib/sup/modes/thread-view-mode.rb | 13 +++++++++++++
lib/sup/modes/url-list-mode.rb | 23 +++++++++++++++++++++++
3 files changed, 37 insertions(+), 0 deletions(-)
create mode 100644 lib/sup/modes/url-list-mode.rb
diff --git a/lib/sup.rb b/lib/sup.rb
index cec36b6..3c591e6 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -276,6 +276,7 @@ require "sup/modes/buffer-list-mode"
require "sup/modes/poll-mode"
require "sup/modes/file-browser-mode"
require "sup/modes/completion-mode"
+require "sup/modes/url-list-mode"
require "sup/sent"
$:.each do |base|
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index fb324c1..99b7908 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -48,6 +48,7 @@ EOS
k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "("
k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")"
k.add :pipe_message, "Pipe message or attachment to a shell command", '|'
+ k.add :view_urls, "View URLs in message", 'L'
k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk|
kk.add :archive_and_kill, "Archive this thread and kill buffer", 'a'
@@ -118,6 +119,18 @@ EOS
def lines; @text.length; end
def [] i; @text[i]; end
+ def view_urls
+ m = @message_lines[curpos] or return
+ chunks = m.chunks.select { |c| c.is_a? Chunk::Text }
+ return if chunks.empty?
+
+ lines = chunks.map { |c| c.lines }.flatten.join(" ")
+ urls = URI.extract(lines, %w(http ftp)).uniq.sort
+ return if urls.empty?
+
+ BufferManager.spawn "URLs for #{m.subj}", UrlListMode.new(urls)
+ end
+
def show_header
m = @message_lines[curpos] or return
BufferManager.spawn_unless_exists("Full header for #{m.id}") do
diff --git a/lib/sup/modes/url-list-mode.rb b/lib/sup/modes/url-list-mode.rb
new file mode 100644
index 0000000..f51cd52
--- /dev/null
+++ b/lib/sup/modes/url-list-mode.rb
@@ -0,0 +1,23 @@
+module Redwood
+class UrlListMode < LineCursorMode
+ register_keymap do |k|
+ k.add :view_url, "View selected URL", :enter
+ end
+
+ def initialize urls
+ @urls = urls
+ @text = urls.map { |u| u.to_s }
+ super()
+ end
+
+ def lines; @text.length end
+ def [] i; @text[i] end
+
+ def view_url
+ url = BufferManager.ask :url, "URL: ", @urls[curpos].to_s
+ return unless url
+ BufferManager.flash "viewing #{url.inspect}"
+ end
+end
+
+end
--
1.5.4.rc2.69.g10f0
--
William <wmorgan-sup at masanjin.net>
next prev parent reply other threads:[~2008-02-16 20:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-30 3:23 [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message brabuhr
2008-02-03 2:56 ` William Morgan
2008-02-09 2:01 ` brabuhr at gmail.com
2008-02-16 20:04 ` William Morgan
2008-02-16 20:06 ` William Morgan [this message]
2008-02-18 23:24 ` Nicolas Pouillard
2008-02-19 3:12 ` Daniel Wagner
2008-02-19 10:17 ` Nicolas Pouillard
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=1203192317-sup-4404@south \
--to=wmorgan-sup@masanjin.net \
/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