unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message
@ 2018-11-08 10:45 David Edmondson
  2019-03-28 11:23 ` David Bremner
  2019-03-28 17:41 ` David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: David Edmondson @ 2018-11-08 10:45 UTC (permalink / raw)
  To: notmuch

Add a new binding when looking at messages, B, that prompts with a
list of URLs found in the current message, if any. Open the one that
is selected in a browser.
---

Based on ideas from `rcirc-browse-url'.

 emacs/notmuch-show.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 78f1af47..3f478bb6 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1511,6 +1511,7 @@ reset based on the original query."
     (define-key map "<" 'notmuch-show-toggle-thread-indentation)
     (define-key map "t" 'toggle-truncate-lines)
     (define-key map "." 'notmuch-show-part-map)
+    (define-key map "B" 'notmuch-show--browse-urls)
     map)
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
@@ -1573,6 +1574,8 @@ All currently available key bindings:
 ;; region a->b is not found when point is at b. We walk backwards
 ;; until finding the property.
 (defun notmuch-show-message-extent ()
+  "Return a cons cell containing the start and end buffer offset
+of the current message."
   (let (r)
     (save-excursion
       (while (not (setq r (get-text-property (point) :notmuch-message-extent)))
@@ -2519,6 +2522,32 @@ beginning of the line."
 				    (point))
 				  (line-end-position)))
 
+(defmacro notmuch-show--with-currently-shown-message (&rest body)
+  "Evaluate BODY with display restricted to the currently shown
+message."
+  `(save-excursion
+     (save-restriction
+      (let ((extent (notmuch-show-message-extent)))
+	(narrow-to-region (car extent) (cdr extent))
+	,@body))))
+
+(defun notmuch-show--gather-urls ()
+  "Gather any URLs in the current message."
+  (notmuch-show--with-currently-shown-message
+   (let (urls)
+     (goto-char (point-min))
+     (while (re-search-forward goto-address-url-regexp (point-max) t)
+       (push (match-string-no-properties 0) urls))
+     (reverse urls))))
+
+(defun notmuch-show--browse-urls ()
+  "Offer to browse any URLs in the current message."
+  (interactive)
+  (let ((urls (notmuch-show--gather-urls)))
+    (if urls
+	(browse-url (completing-read "Browse URL: " (cdr urls) nil nil (car urls)))
+      (message "No URLs found."))))
+
 (provide 'notmuch-show)
 
 ;;; notmuch-show.el ends here
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message
  2018-11-08 10:45 [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message David Edmondson
@ 2019-03-28 11:23 ` David Bremner
  2019-03-28 11:34   ` David Edmondson
  2019-03-28 17:41 ` David Bremner
  1 sibling, 1 reply; 5+ messages in thread
From: David Bremner @ 2019-03-28 11:23 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:


> +(defun notmuch-show--browse-urls ()
> +  "Offer to browse any URLs in the current message."
> +  (interactive)
> +  (let ((urls (notmuch-show--gather-urls)))
> +    (if urls
> +	(browse-url (completing-read "Browse URL: " (cdr urls) nil nil (car urls)))
> +      (message "No URLs found."))))
> +
>  (provide 'notmuch-show)

It's a minor point, but should this really have -- to signal a private
function? It's bound to key which sortof makes it defacto public, no?

d

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message
  2019-03-28 11:23 ` David Bremner
@ 2019-03-28 11:34   ` David Edmondson
  2019-03-28 13:20     ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: David Edmondson @ 2019-03-28 11:34 UTC (permalink / raw)
  To: David Bremner, notmuch

On Thursday, 2019-03-28 at 08:23:37 -03, David Bremner wrote:

> David Edmondson <dme@dme.org> writes:
>
>
>> +(defun notmuch-show--browse-urls ()
>> +  "Offer to browse any URLs in the current message."
>> +  (interactive)
>> +  (let ((urls (notmuch-show--gather-urls)))
>> +    (if urls
>> +	(browse-url (completing-read "Browse URL: " (cdr urls) nil nil (car urls)))
>> +      (message "No URLs found."))))
>> +
>>  (provide 'notmuch-show)
>
> It's a minor point, but should this really have -- to signal a private
> function? It's bound to key which sortof makes it defacto public, no?

Yes.

Do you want an updated patch or will you fix it on the fly?

dme.
-- 
I'm catching up with myself!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message
  2019-03-28 11:34   ` David Edmondson
@ 2019-03-28 13:20     ` David Bremner
  0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2019-03-28 13:20 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> On Thursday, 2019-03-28 at 08:23:37 -03, David Bremner wrote:
>
>> David Edmondson <dme@dme.org> writes:
>>
>>
>>> +(defun notmuch-show--browse-urls ()
>>> +  "Offer to browse any URLs in the current message."
>>> +  (interactive)
>>> +  (let ((urls (notmuch-show--gather-urls)))
>>> +    (if urls
>>> +	(browse-url (completing-read "Browse URL: " (cdr urls) nil nil (car urls)))
>>> +      (message "No URLs found."))))
>>> +
>>>  (provide 'notmuch-show)
>>
>> It's a minor point, but should this really have -- to signal a private
>> function? It's bound to key which sortof makes it defacto public, no?
>
> Yes.
>
> Do you want an updated patch or will you fix it on the fly?
>

I can fix it.

d

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message
  2018-11-08 10:45 [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message David Edmondson
  2019-03-28 11:23 ` David Bremner
@ 2019-03-28 17:41 ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: David Bremner @ 2019-03-28 17:41 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> Add a new binding when looking at messages, B, that prompts with a
> list of URLs found in the current message, if any. Open the one that
> is selected in a browser.

pushed, amended as discussed.

d

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-28 17:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-08 10:45 [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message David Edmondson
2019-03-28 11:23 ` David Bremner
2019-03-28 11:34   ` David Edmondson
2019-03-28 13:20     ` David Bremner
2019-03-28 17:41 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).