mu4e: rework uri-handling in view, add mu4e-view-save-url

Rework the handling of URIs in the view a bit; add a functionto save
URLs to the kill ring. Also add mu4e-view-for-each-uri to iterate over
them.
This commit is contained in:
djcb 2015-03-21 15:22:12 +02:00
parent 6680b364a8
commit 7de65b91bc
2 changed files with 50 additions and 22 deletions

View File

@ -557,6 +557,7 @@ FUNC should be a function taking two arguments:
(define-key map "j" 'mu4e~headers-jump-to-maildir) (define-key map "j" 'mu4e~headers-jump-to-maildir)
(define-key map "g" 'mu4e-view-go-to-url) (define-key map "g" 'mu4e-view-go-to-url)
(define-key map "k" 'mu4e-view-save-url)
(define-key map "F" 'mu4e-compose-forward) (define-key map "F" 'mu4e-compose-forward)
(define-key map "R" 'mu4e-compose-reply) (define-key map "R" 'mu4e-compose-reply)
@ -1318,38 +1319,58 @@ string."
nil nil def))))) nil nil def)))))
(defun mu4e-view-go-to-url (&optional multi) (defun mu4e-view-go-to-url (&optional multi)
"Offer to go to URL(s). If MULTI (prefix-argument) is nil, go to "Offer to go to url(s). If MULTI (prefix-argument) is nil, go to
a single one, otherwise, offer to go to a range of URLs." a single one, otherwise, offer to go to a range of urls."
(interactive "P")
(mu4e~view-handle-urls multi (lambda (url) (mu4e~view-browse-url-from-binding url))))
(defun mu4e-view-save-url (&optional multi)
"Offer to save urls(s) to the kill-ring. If
MULTI (prefix-argument) is nil, save a single one, otherwise, offer
to save a range of URLs."
(interactive "P")
(mu4e~view-handle-urls multi
(lambda (url)
(kill-new url)
(mu4e-message "Saved %s to the kill-ring" url))))
(defun mu4e~view-handle-urls (multi urlfunc)
"If MULTI is nil, apply URLFUNC to a single uri, otherwise, apply
it to a range of uris."
(interactive "P") (interactive "P")
(if multi (if multi
(mu4e-view-go-to-urls-multi) (mu4e~view-handle-multi-urls urlfunc)
(mu4e-view-go-to-urls-single))) (mu4e~view-handle-single-url urlfunc)))
(defun mu4e-view-go-to-urls-single (&optional num) (defun mu4e~view-handle-single-url (urlfunc &optional num)
"Go to a numbered url." "Apply URLFUNC to url NUM in the current message."
(interactive) (interactive)
(let* ((num (or num (let* ((num (or num (mu4e~view-get-urls-num "URL to visit")))
(mu4e~view-get-urls-num "URL to visit")))
(url (gethash num mu4e~view-link-map))) (url (gethash num mu4e~view-link-map)))
(unless url (mu4e-warn "Invalid number for URL")) (unless url (mu4e-warn "Invalid number for URL"))
(mu4e~view-browse-url-from-binding url))) (funcall urlfunc url)))
(defun mu4e-view-go-to-urls-multi () (defun mu4e~view-handle-multi-urls (urlfunc)
"Offer to visit multiple URLs from the current message. "Apply URLFUNC to a a range of urls in the current message.
Default is to visit all URLs, [1..n], where n is the number of Default is to aplly it to all URLs, [1..n], where n is the number
URLS. You can type multiple values separated by space, e.g. of urls. You can type multiple values separated by space, e.g. 1
1 3-6 8 3-6 8 will visit urls 1,3,4,5,6 and 8.
will visit URLs 1,3,4,5,6 and 8.
Furthermore, there is a shortcut \"a\" which means all URLS, but Furthermore, there is a shortcut \"a\" which means all urls, but as
as this is the default, you may not need it." this is the default, you may not need it."
(interactive) (interactive)
(let* ((linkstr (mu4e~view-get-urls-num (let* ((linkstr (mu4e~view-get-urls-num
"URL number range (or 'a' for 'all')" t)) "URL number range (or 'a' for 'all')" t))
(count (hash-table-count mu4e~view-link-map)) (count (hash-table-count mu4e~view-link-map))
(linknums (mu4e-split-ranges-to-numbers linkstr count))) (linknums (mu4e-split-ranges-to-numbers linkstr count)))
(dolist (num linknums) (dolist (num linknums)
(mu4e-view-go-to-urls-single num)))) (mu4e~view-handle-single-url urlfunc num))))
(defun mu4e-view-for-each-uri (func)
"Execute FUNC (which receives a uri) for each uri in the current
message."
(maphash (lambda (num uri) (funcall func uri)) mu4e~view-link-map))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconst mu4e~view-raw-buffer-name " *mu4e-raw-view*" (defconst mu4e~view-raw-buffer-name " *mu4e-raw-view*"

View File

@ -1157,6 +1157,9 @@ actions
g go to (visit) numbered URL (using `browse-url') g go to (visit) numbered URL (using `browse-url')
(or: <mouse-1> or M-RET with point on url) (or: <mouse-1> or M-RET with point on url)
C-u g visits multiple URLs C-u g visits multiple URLs
k save the numbered URL in the kill-ring.
C-u g saves multiple URLs
e extract (save) attachment (asks for number) e extract (save) attachment (asks for number)
(or: <mouse-2> or S-RET with point on attachment) (or: <mouse-2> or S-RET with point on attachment)
C-u e extracts multiple attachments C-u e extracts multiple attachments
@ -2529,13 +2532,17 @@ action}
@noindent @noindent
You can also write your own functions without using the above. If you You can also write your own functions without using the above. If you
want to do so, key useful functions are @code{mu4e-message-at-point} want to do so, key useful functions are @code{mu4e-message-at-point}
(see below), @code{mu4e-headers-for-each} (to iterate over all headers, (see below), @code{mu4e-headers-for-each} (to iterate over all
see its docstring) and @code{mu4e-view-for-each-part} (to iterate over headers, see its docstring) and @code{mu4e-view-for-each-part} (to
all parts/attachments, see its docstring). Another useful function is iterate over all parts/attachments, see its docstring). There is also
@code{mu4e-view-for-each-uri} to iterate of all the URIs in the
current message.
Another useful function is
@code{mu4e-headers-find-if} which searches for a message matching a @code{mu4e-headers-find-if} which searches for a message matching a
certain pattern; again, see its docstring. certain pattern; again, see its docstring.
@node Available functions @node Avaifmlable functions
@section Available functions @section Available functions
The whole of @t{mu4e} consists of hundreds of elisp functions. However, the The whole of @t{mu4e} consists of hundreds of elisp functions. However, the