* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
@ 2008-01-30 3:23 brabuhr
2008-02-03 2:56 ` William Morgan
2008-02-16 20:04 ` William Morgan
0 siblings, 2 replies; 8+ messages in thread
From: brabuhr @ 2008-01-30 3:23 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
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
1 sibling, 1 reply; 8+ messages in thread
From: William Morgan @ 2008-02-03 2:56 UTC (permalink / raw)
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>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
2008-02-03 2:56 ` William Morgan
@ 2008-02-09 2:01 ` brabuhr at gmail.com
0 siblings, 0 replies; 8+ messages in thread
From: brabuhr at gmail.com @ 2008-02-09 2:01 UTC (permalink / raw)
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?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
@ 2008-02-16 20:04 ` William Morgan
2008-02-16 20:06 ` [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode William Morgan
2008-02-18 23:24 ` [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message Nicolas Pouillard
0 siblings, 2 replies; 8+ messages in thread
From: William Morgan @ 2008-02-16 20:04 UTC (permalink / raw)
[forgot to send to list]
Reformatted excerpts from brabuhr's message of 2008-02-08:
> 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?
If you want to display them as a list, I would add a mode called
UrlListMode or something like that which was a subclass of
LineCursorMode. You can look to BufferListMode as an example, though it
will be even simpler than that because the content won't ever change.
Spawn an instance of that mode when the user presses 'L', and have
enter in UrlListMode trigger the URL viewing hook, possibly first
running it through BufferManager#ask for editing. We can also trim
trailing punctuation from whatever URI.extract pulls out, since that
sounds like the common case.
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode
2008-02-16 20:04 ` William Morgan
@ 2008-02-16 20:06 ` William Morgan
2008-02-18 23:24 ` [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message Nicolas Pouillard
1 sibling, 0 replies; 8+ messages in thread
From: William Morgan @ 2008-02-16 20:06 UTC (permalink / raw)
---
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>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
2008-02-16 20:04 ` William Morgan
2008-02-16 20:06 ` [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode William Morgan
@ 2008-02-18 23:24 ` Nicolas Pouillard
2008-02-19 3:12 ` Daniel Wagner
1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Pouillard @ 2008-02-18 23:24 UTC (permalink / raw)
Excerpts from William Morgan's message of Sat Feb 16 21:04:32 +0100 2008:
> [forgot to send to list]
>
> Reformatted excerpts from brabuhr's message of 2008-02-08:
> > 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?
>
> If you want to display them as a list, I would add a mode called
> UrlListMode or something like that which was a subclass of
> LineCursorMode. You can look to BufferListMode as an example, though it
> will be even simpler than that because the content won't ever change.
>
> Spawn an instance of that mode when the user presses 'L', and have
> enter in UrlListMode trigger the URL viewing hook, possibly first
> running it through BufferManager#ask for editing. We can also trim
> trailing punctuation from whatever URI.extract pulls out, since that
> sounds like the common case.
You should look the rxvt-unicode terminal, there is an extension to deal with
URLs [1]. That's pretty handy in fact and applies not only to sup.
[1]: http://www.jukie.net/~bart/blog/20070503013555
Regards,
--
Nicolas Pouillard aka Ertai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20080219/cb877745/attachment.bin
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
2008-02-18 23:24 ` [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message Nicolas Pouillard
@ 2008-02-19 3:12 ` Daniel Wagner
2008-02-19 10:17 ` Nicolas Pouillard
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Wagner @ 2008-02-19 3:12 UTC (permalink / raw)
Excerpts from Nicolas Pouillard's message of Mon Feb 18 15:24:54 -0800 2008:
> You should look the rxvt-unicode terminal, there is an extension to deal with
> URLs [1]. That's pretty handy in fact and applies not only to sup.
>
> [1]: http://www.jukie.net/~bart/blog/20070503013555
Sounds nice, does it handle multi-line URLs gracefully? In particular,
in sup a multi-line URL could have a line-break in it... care to report
how it handles this?
http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-no-newline-in-the-actual-message-as-sent
http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-woul
d-be-so-kind-that-contains-a-newline-in-the-eightieth-column
Either way, thanks for the tip!
~d
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
2008-02-19 3:12 ` Daniel Wagner
@ 2008-02-19 10:17 ` Nicolas Pouillard
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Pouillard @ 2008-02-19 10:17 UTC (permalink / raw)
Excerpts from Daniel Wagner's message of Tue Feb 19 04:12:15 +0100 2008:
> Excerpts from Nicolas Pouillard's message of Mon Feb 18 15:24:54 -0800 2008:
> > You should look the rxvt-unicode terminal, there is an extension to deal with
> > URLs [1]. That's pretty handy in fact and applies not only to sup.
> >
> > [1]: http://www.jukie.net/~bart/blog/20070503013555
>
> Sounds nice, does it handle multi-line URLs gracefully? In particular,
> in sup a multi-line URL could have a line-break in it... care to report
> how it handles this?
>
> http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-no-newline-in-the-actual-message-as-sent
> http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-a-newline-in-the-eightieth-column
It doesn't handle br0ken URLs, however here that's perhaps sup jobs to fix
them. I send a patch to the list to fix this.
Regards,
--
Nicolas Pouillard aka Ertai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20080219/61653c81/attachment-0001.bin
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-02-19 10:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode William Morgan
2008-02-18 23:24 ` [sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message Nicolas Pouillard
2008-02-19 3:12 ` Daniel Wagner
2008-02-19 10:17 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox