brabuhr
2008-Jan-30 03:23 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
On Jan 29, 2008 2:47 PM, Daniel Wagner <daniel at wagner-home.com> wrote:> One thing I find myself doing all the time is highlighting a web address > and pasting it into Firefox.This adds a new key binding to the thread-view mode (L) to assist with loading URIs from the body of the message. This first pass will pull the URIs from the message text and loop through them while asking if that URI should be loaded. Currently, there is no code to actually perform the load. --- lib/sup/modes/thread-view-mode.rb | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb index 961fc5d..5fae8fa 100644 --- a/lib/sup/modes/thread-view-mode.rb +++ b/lib/sup/modes/thread-view-mode.rb @@ -1,4 +1,5 @@ require ''open3'' +require ''uri'' module Redwood class ThreadViewMode < LineCursorMode @@ -48,6 +49,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 :follow_link, "Follow a web link", "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'' @@ -456,6 +458,34 @@ EOS end end + def follow_link + chunk = @chunk_lines[curpos] + + return unless chunk.is_a?(Chunk::Text) + + uris = URI.extract(chunk.lines.join("\n")).uniq.sort + + if uris.size > 0 + Redwood::log uris.join("\n") + Redwood::BufferManager.flash "#{uris.size} URIs found." + sleep 1 + + uris.each do |uri| + case Redwood::BufferManager.ask_yes_or_no "Load URI: #{uri} (y/n)" + when true + Redwood::BufferManager.flash "<add launch the url code here please :-)>" + break + when false + next + else + break + end + end + else + Redwood::BufferManager.flash "No URIs found." + end + end + private def initial_state_for m -- 1.5.2.5
William Morgan
2008-Feb-03 02:56 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
Reformatted excerpts from brabuhr''s message of 2008-01-29:> This adds a new key binding to the thread-view mode (L) to assist with > loading URIs from the body of the message. This first pass will pull > the URIs from the message text and loop through them while asking if > that URI should be loaded. Currently, there is no code to actually > perform the load.Looks good. I have a slight preference for a "if uris.size == 0" block that flashes a message and returns, so that the meat of the method doesn''t have to be too indented. My limited research indicates that there isn''t a standard way (like mailcap) of viewing a URL. So probably a "view-url" hook is the best way to approach the actual viewing code. -- William <wmorgan-sup at masanjin.net>
brabuhr at gmail.com
2008-Feb-09 02:01 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
On Feb 2, 2008 9:56 PM, William Morgan <wmorgan-sup at masanjin.net> wrote:> Reformatted excerpts from brabuhr''s message of 2008-01-29: > > This adds a new key binding to the thread-view mode (L) to assist with > > loading URIs from the body of the message. This first pass will pull > > the URIs from the message text and loop through them while asking if > > that URI should be loaded. Currently, there is no code to actually > > perform the load. > > Looks good. I have a slight preference for a "if uris.size == 0" block > that flashes a message and returns, so that the meat of the method > doesn''t have to be too indented.I was also thinking that it would be better to display the discovered URIs in a list instead of the prompting, but I wasn''t sure how to implement that. Another problem I see is that the extractor is too-greedy and will pull in the punctuation following the URL; so, perhaps the list should allow line editing before calling the view-url hook?