From 83513ca24c1140c7983e6981e900e4e6607b50e2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 9 Dec 2018 14:42:45 -0500 Subject: mail: Generalize "visit URL" command --- lisp/km-mail.el | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lisp/km-mail.el b/lisp/km-mail.el index 5701c8b..8e5e7c9 100644 --- a/lisp/km-mail.el +++ b/lisp/km-mail.el @@ -211,23 +211,36 @@ Tracking System, set '--in-reply-to' to the initial report and (notmuch-show-stash-git-helper (list root-id) "--in-reply-to=")) " "))))) +(defun km/notmuch-gitlab-url () + (and (re-search-forward + (concat "Reply to this email directly or view it on GitLab: " + "\\(https://gitlab\.com/[^\n]+\\)$") + nil t) + (match-string-no-properties 1))) + +(defun km/notmuch-github-url () + (and (re-search-forward + (concat "Reply to this email directly or view it on GitHub:\n" + "\\(https://github\.com/[^\n]+\\)$") + nil t) + (match-string-no-properties 1))) + +(defvar km/notmuch-url-extractors '(km/notmuch-gitlab-url km/notmuch-github-url)) ;;;###autoload -(defun km/notmuch-visit-github-url (&optional copy) - "Visit the GitHub link associated with this message. -If COPY is non-nil, copy the URL instead of visiting it." +(defun km/notmuch-visit-url (&optional copy) + "Visit the URL link associated with this message. +The URL is set to the the first non-nil value returned +`km/notmuch-url-extractors'. If COPY is non-nil, copy the URL +instead of visiting it." (interactive "P") (funcall (if copy (lambda (url) (kill-new (message url))) #'browse-url) (km/notmuch-with-raw-message (notmuch-show-get-message-id) - (if (re-search-forward - (concat "Reply to this email directly or view it on GitHub:\n" - "\\(https://github\.com/[^\n]+\\)$") - nil t) - (match-string-no-properties 1) - (user-error "No GitHub URL found"))))) + (or (run-hook-with-args-until-success 'km/notmuch-url-extractors) + (user-error "No URL found"))))) ;;; Mail sync -- cgit v1.2.3