mu4e: remove mu4e-view-url-regexp, use thing-at-point

Don't use our own URL-matching regexp, use the one that emacs provides
(in thing-at-point), which is a bit more general, and seems to better
handle some URLs.
This commit is contained in:
djcb
2015-03-21 10:28:01 +02:00
parent 2d78755bd6
commit 6680b364a8

View File

@ -1,6 +1,6 @@
;;; mu4e-view.el -- part of mu4e, the mu mail user agent ;;; mu4e-view.el -- part of mu4e, the mu mail user agent
;; ;;
;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema ;; Copyright (C) 2011-2015 Dirk-Jan C. Binnema
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
@ -39,6 +39,7 @@
(require 'button) (require 'button)
(require 'epa) (require 'epa)
(require 'epg) (require 'epg)
(require 'thingatpt)
(eval-when-compile (byte-compile-disable-warning 'cl-functions)) (eval-when-compile (byte-compile-disable-warning 'cl-functions))
(require 'cl) (require 'cl)
@ -161,11 +162,6 @@ The first letter of NAME is used as a shortcut character.")
This is to determine what is the parent docid for embedded This is to determine what is the parent docid for embedded
message extracted at some path.") message extracted at some path.")
(defvar mu4e-view-url-regexp
"\\(\\(https?\\://\\|mailto:\\)[-+\[:alnum:\].?_$%/+&#@!*~,:;=/()]+\\)"
"Regexp that matches http:/https:/mailto: URLs; match-string 1
will contain the matched URL, if any.")
(defvar mu4e~view-attach-map nil (defvar mu4e~view-attach-map nil
"A mapping of user-visible attachment number to the actual part index.") "A mapping of user-visible attachment number to the actual part index.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -243,7 +239,7 @@ found."
"\n" "\n"
(mu4e-message-body-text msg))) (mu4e-message-body-text msg)))
(defun mu4e~view-embedded-winbuf () (defun mu4e~view-embedded-winbuf ()
"Get a buffer (shown in a window) for the embedded message." "Get a buffer (shown in a window) for the embedded message."
(let* ((buf (get-buffer-create mu4e~view-embedded-buffer-name)) (let* ((buf (get-buffer-create mu4e~view-embedded-buffer-name))
(win (or (get-buffer-window buf) (split-window-vertically)))) (win (or (get-buffer-window buf) (split-window-vertically))))
@ -688,7 +684,6 @@ FUNC should be a function taking two arguments:
(define-key menumap [reply] '("Reply" . mu4e-compose-reply)) (define-key menumap [reply] '("Reply" . mu4e-compose-reply))
(define-key menumap [sepa3] '("--")) (define-key menumap [sepa3] '("--"))
(define-key menumap [query-next] (define-key menumap [query-next]
'("Next query" . mu4e-headers-query-next)) '("Next query" . mu4e-headers-query-next))
(define-key menumap [query-prev] (define-key menumap [query-prev]
@ -796,6 +791,12 @@ If the url is mailto link, start writing an email to that address."
mu4e-view-image-max-width mu4e-view-image-max-width
mu4e-view-image-max-height))))))))) mu4e-view-image-max-height)))))))))
(defvar mu4e~view-beginning-of-url-regexp
"https?\\://\\|mailto:"
"Regexp that matches the beginning of http:/https:/mailto: URLs; match-string 1
will contain the matched URL, if any.")
;; this is fairly simplistic... ;; this is fairly simplistic...
(defun mu4e~view-make-urls-clickable () (defun mu4e~view-make-urls-clickable ()
"Turn things that look like URLs into clickable things. "Turn things that look like URLs into clickable things.
@ -805,22 +806,24 @@ Also number them so they can be opened using `mu4e-view-go-to-url'."
(setq mu4e~view-link-map ;; buffer local (setq mu4e~view-link-map ;; buffer local
(make-hash-table :size 32 :weakness nil)) (make-hash-table :size 32 :weakness nil))
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward mu4e-view-url-regexp nil t) (while (re-search-forward mu4e~view-beginning-of-url-regexp nil t)
(let* ((url (match-string 0)) (let ((bounds (thing-at-point-bounds-of-url-at-point)))
(ov (make-overlay (match-beginning 0) (match-end 0)))) (when bounds
(puthash (incf num) url mu4e~view-link-map) (let* ((url (thing-at-point-url-at-point))
(add-text-properties (ov (make-overlay (car bounds) (cdr bounds))))
(match-beginning 0) (puthash (incf num) url mu4e~view-link-map)
(match-end 0) (add-text-properties
`(face mu4e-link-face (car bounds)
mouse-face highlight (cdr bounds)
mu4e-url ,url `(face mu4e-link-face
keymap ,mu4e-view-clickable-urls-keymap mouse-face highlight
help-echo mu4e-url ,url
"[mouse-1] or [M-RET] to open the link")) keymap ,mu4e-view-clickable-urls-keymap
(overlay-put ov 'after-string help-echo
(propertize (format "[%d]" num) "[mouse-1] or [M-RET] to open the link"))
'face 'mu4e-url-number-face))))))) (overlay-put ov 'after-string
(propertize (format "[%d]" num)
'face 'mu4e-url-number-face)))))))))
(defun mu4e~view-hide-cited () (defun mu4e~view-hide-cited ()
@ -1315,9 +1318,8 @@ 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). "Offer to go to URL(s). If MULTI (prefix-argument) is nil, go to
If MULTI (prefix-argument) is nil, go to a single one, otherwise, a single one, otherwise, offer to go to a range of URLs."
offer to go to a range of URLs."
(interactive "P") (interactive "P")
(if multi (if multi
(mu4e-view-go-to-urls-multi) (mu4e-view-go-to-urls-multi)