From 2e433ebfb417126543347a2dbeee8e9ef17fc110 Mon Sep 17 00:00:00 2001 From: Josiah Schwab Date: Wed, 13 Nov 2013 18:08:11 -0800 Subject: [PATCH] Add ability to specify range of URLs to visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * mu4e/mu4e-view.el (mu4e-view-go-to-url): Add the ability to visit multiple URLs by specifying a numeric range. * mu4e/mu4e.texi (The message view: Keybindings): Document ability to visit multiple URLs. `mu4e-view-go-to-url' now behaves like `mu4e-view-save-attachment'. You can specify multiple URLs to visit at once by prefixing the visit command by ; so C-u g asks you for a range of URLs to visit (for example, 1 3-6 8). The range "‘a’" is a shortcut for all URLs. --- mu4e/mu4e-view.el | 56 ++++++++++++++++++++++++++++++++++++++++++++--- mu4e/mu4e.texi | 1 + 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 754ef7b5..1e49c0f1 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -1125,13 +1125,63 @@ list." (mu4e~view-in-headers-context (mu4e-mark-execute-all))) -(defun mu4e-view-go-to-url (num) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; URL handling +(defun mu4e~view-get-urls-num (prompt &optional multi) + "Ask the user with PROMPT for an URL number for MSG, and ensure +it is valid. The number is [1..n] for URLs \[0..(n-1)] in the +message. If MULTI is nil, return the number for the URL; +otherwise (MULTI is non-nil), accept ranges of URL numbers, as +per `mu4e-split-ranges-to-numbers', and return the corresponding +string." + (let* ((count (hash-table-count mu4e~view-link-map)) (def)) + (when (zerop count) (mu4e-error "No links for this message")) + (if (not multi) + (if (= count 1) + (read-number (mu4e-format "%s: " prompt) 1) + (read-number (mu4e-format "%s (1-%d): " prompt count))) + (progn + (setq def (if (= count 1) "1" (format "1-%d" count))) + (read-string (mu4e-format "%s (default %s): " prompt def) + 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." + (interactive "P") + (if multi + (mu4e-view-go-to-urls-multi) + (mu4e-view-go-to-urls-single))) + +(defun mu4e-view-go-to-urls-single (&optional num) "Go to a numbered url." - (interactive "n[mu4e] Visit url with number: ") - (let ((url (gethash num mu4e~view-link-map))) + (interactive) + (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")) (funcall (mu4e~view-browse-url-func 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. + +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)))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defconst mu4e~view-raw-buffer-name " *mu4e-raw-view*" "*internal* Name for the raw message view buffer") diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index ba9c0e6b..552f92d0 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1100,6 +1100,7 @@ actions ------- g go to (visit) numbered URL (using `browse-url') (or: or M-RET with point on url) + C-u g visits multiple URLs e extract (save) attachment (asks for number) (or: or S-RET with point on attachment) C-u e extracts multiple attachments