From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 714426DE0207 for ; Thu, 8 Nov 2018 02:45:16 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.365 X-Spam-Level: X-Spam-Status: No, score=0.365 tagged_above=-999 required=5 tests=[AWL=-0.288, DKIMWL_WL_MED=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_NEUTRAL=0.652, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id txHT4s_S5vXb for ; Thu, 8 Nov 2018 02:45:14 -0800 (PST) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by arlo.cworth.org (Postfix) with ESMTPS id 79C3D6DE018C for ; Thu, 8 Nov 2018 02:45:14 -0800 (PST) Received: by mail-wm1-f52.google.com with SMTP id t15-v6so726445wmt.0 for ; Thu, 08 Nov 2018 02:45:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IzSg6CmX1HdeiRGX0K/6VRlcoxjtk0jP2o12l1pShVU=; b=FfCq2uDXHqmVjX69daXOz9OATJiX4ZktyenxQ2CtI39ZCD4DeHlKclKbVJdO0aboFk nkkN9bAS9CVoajsoLdajgo6RGs+27JupkAsR64scqQ/7dgCU1GbX0CiW03fM2eaCo0hh uO1QkykFbKPsF/OMIRB0I36DWFYWCdJ36I+HKYe2l2Lu33IbfdJxRL4L5X50FTqTUM88 LqFQnVgRjhsjggbzzr5bcbF+BSw6XGfFxfpeENZE/PHsHcPeA65mA8UHmxznKk+PMAvm Udr8/y+ey3Of2X2MCz53iQD0RyOgRC6A55TncXJQiKFR4iZDRcf1zN3zyg/QnTuytGvb cY6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IzSg6CmX1HdeiRGX0K/6VRlcoxjtk0jP2o12l1pShVU=; b=tV3rCdDQFdtW1JYBNU206LAHNfgLNAAh2f2e1gHhxVAVAHrJcZEeCxzjtXTLphUNx+ IKX2Cj+MsUG0qxdCVAPZP6f3pT/9nk/bNr5qAhrgxMIpU3jRjjdLNZA9fftiiuoIaSud TubMTSEN0MCe6RYHjHPDKiuqJASfI1/6JxLJYMrPYj9Jxgq+yRkcJEK3EQ2DgnPlLajD l/a+mVahMl3vcFWBVbya+CpQhxLoJj9fYNbT/D9SIQbExozWV6Yqo7g0SPypY2bx3/y8 kzBPvLyVuc6rimzr+daU7KZJK9ybR6QJS2fchCXvncxegXhnbkESoNifrzjk6vd+O9sy maXA== X-Gm-Message-State: AGRZ1gKUmrfGaY0ZKRkYYxPLpjMz3tyhH6/mcUAq/H3sqGPHhnDVW6X4 3/QQVj6LFV+0Suc+ACDRIDGEN4Xlozk= X-Google-Smtp-Source: AJdET5dA5FkzoEDQu5Wu53EGH9iVuCMOYm4ezIs/GJnfK6TXozJ5HFzxW1FAF5R3f7GPfRVNT15GJw== X-Received: by 2002:a1c:c46:: with SMTP id 67-v6mr749924wmm.6.1541673911138; Thu, 08 Nov 2018 02:45:11 -0800 (PST) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by smtp.gmail.com with ESMTPSA id e10-v6sm5562505wrp.56.2018.11.08.02.45.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 02:45:09 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 1ad5ccf3 for ; Thu, 8 Nov 2018 10:45:08 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v1 1/1] emacs: Easy access to URLs mentioned in the current message Date: Thu, 8 Nov 2018 10:45:08 +0000 Message-Id: <20181108104508.84911-1-dme@dme.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Nov 2018 10:45:16 -0000 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