From 7de65b91bc7a4308f00329e5d74f1d6507b6ea21 Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 21 Mar 2015 15:22:12 +0200 Subject: [PATCH] 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. --- mu4e/mu4e-view.el | 57 ++++++++++++++++++++++++++++++++--------------- mu4e/mu4e.texi | 15 +++++++++---- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 69b2debe..2ae665bb 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -557,6 +557,7 @@ FUNC should be a function taking two arguments: (define-key map "j" 'mu4e~headers-jump-to-maildir) (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 "R" 'mu4e-compose-reply) @@ -1318,38 +1319,58 @@ string." nil nil def))))) (defun mu4e-view-go-to-url (&optional multi) - "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." + "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." + (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") (if multi - (mu4e-view-go-to-urls-multi) - (mu4e-view-go-to-urls-single))) + (mu4e~view-handle-multi-urls urlfunc) + (mu4e~view-handle-single-url urlfunc))) -(defun mu4e-view-go-to-urls-single (&optional num) - "Go to a numbered url." +(defun mu4e~view-handle-single-url (urlfunc &optional num) + "Apply URLFUNC to url NUM in the current message." (interactive) - (let* ((num (or num - (mu4e~view-get-urls-num "URL to visit"))) + (let* ((num (or num (mu4e~view-get-urls-num "URL to visit"))) (url (gethash num mu4e~view-link-map))) (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 () - "Offer to visit multiple URLs from the current message. -Default is to visit all URLs, [1..n], where n is the number of -URLS. You can type multiple values separated by space, e.g. - 1 3-6 8 -will visit URLs 1,3,4,5,6 and 8. +(defun mu4e~view-handle-multi-urls (urlfunc) + "Apply URLFUNC to a a range of urls in the current message. +Default is to aplly it to all URLs, [1..n], where n is the number +of urls. You can type multiple values separated by space, e.g. 1 +3-6 8 will visit urls 1,3,4,5,6 and 8. -Furthermore, there is a shortcut \"a\" which means all URLS, but -as this is the default, you may not need it." +Furthermore, there is a shortcut \"a\" which means all urls, but as +this is the default, you may not need it." (interactive) (let* ((linkstr (mu4e~view-get-urls-num "URL number range (or 'a' for 'all')" t)) (count (hash-table-count mu4e~view-link-map)) (linknums (mu4e-split-ranges-to-numbers linkstr count))) (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*" diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index e196e22f..136bb08d 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1157,6 +1157,9 @@ actions g go to (visit) numbered URL (using `browse-url') (or: or M-RET with point on url) 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) (or: or S-RET with point on attachment) C-u e extracts multiple attachments @@ -2529,13 +2532,17 @@ action} @noindent 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} -(see below), @code{mu4e-headers-for-each} (to iterate over all headers, -see its docstring) and @code{mu4e-view-for-each-part} (to iterate over -all parts/attachments, see its docstring). Another useful function is +(see below), @code{mu4e-headers-for-each} (to iterate over all +headers, see its docstring) and @code{mu4e-view-for-each-part} (to +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 certain pattern; again, see its docstring. -@node Available functions +@node Avaifmlable functions @section Available functions The whole of @t{mu4e} consists of hundreds of elisp functions. However, the