From 28a970a77803c30b700eafba372c272f7fc913e3 Mon Sep 17 00:00:00 2001 From: sabof Date: Fri, 7 Feb 2014 05:19:33 +0000 Subject: [PATCH 1/2] mu4e-view-mode: use overlays for url numbers --- mu4e/mu4e-view.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 9cd85ae58..05cf9874e 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -266,6 +266,7 @@ marking if it still had that." (when (or embedded (not (mu4e~view-mark-as-read msg))) (let ((inhibit-read-only t)) (erase-buffer) + (delete-all-overlays) (insert (mu4e-view-message-text msg)) (goto-char (point-min)) (mu4e~fontify-cited) @@ -798,19 +799,22 @@ Also number them so they can be opened using `mu4e-view-go-to-url'." (make-hash-table :size 32 :weakness nil)) (goto-char (point-min)) (while (re-search-forward mu4e~view-url-regexp nil t) - (let ((url (match-string 0))) + (let* ((url (match-string 0)) + (ov (make-overlay (match-beginning 0) (match-end 0)))) (puthash (incf num) url mu4e~view-link-map) - (add-text-properties 0 (length url) + (add-text-properties + (match-beginning 0) + (match-end 0) `(face mu4e-link-face mouse-face highlight mu4e-url ,url keymap ,mu4e-view-clickable-urls-keymap help-echo - "[mouse-1] or [M-RET] to open the link") url) - (replace-match - (concat url - (propertize (format "[%d]" num) - 'face 'mu4e-url-number-face)))))))) + "[mouse-1] or [M-RET] to open the link")) + (overlay-put ov 'after-string + (propertize (format "[%d]" num) + 'face 'mu4e-url-number-face)) + ))))) (defun mu4e~view-hide-cited () From 186fc8941484511749cf54a403cb67d37f733d2c Mon Sep 17 00:00:00 2001 From: sabof Date: Fri, 7 Feb 2014 05:21:59 +0000 Subject: [PATCH 2/2] Avoid unnecessary errors --- mu4e/mu4e-view.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 05cf9874e..35a2dd6eb 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -337,12 +337,12 @@ add text-properties to VAL." (buffer-string)) ""))) -(defun mu4e~view-toggle-contact (&optional point) +(defun* mu4e~view-toggle-contact (&optional point) "Toggle between the long and short versions of long/short string at POINT, or if nil, at (point)." (interactive) (unless (get-text-property (or point (point)) 'long) - (error "point is not toggleable")) + (return-from mu4e~view-toggle-contact)) (let* ((point (or point (point))) ;; find the first pos part of the button (start (previous-property-change point)) @@ -443,14 +443,16 @@ at POINT, or if nil, at (point)." (interactive) (let* (( msg (mu4e~view-get-property-from-event 'mu4e-msg)) ( attnum (mu4e~view-get-property-from-event 'mu4e-attnum))) - (mu4e-view-open-attachment msg attnum))) + (when (and msg attnum) + (mu4e-view-open-attachment msg attnum)))) (defun mu4e~view-save-attach-from-binding () "Save the attachement at point, or click location." (interactive) (let* (( msg (mu4e~view-get-property-from-event 'mu4e-msg)) ( attnum (mu4e~view-get-property-from-event 'mu4e-attnum))) - (mu4e-view-save-attachment-single msg attnum))) + (when (and msg attnum) + (mu4e-view-save-attachment-single msg attnum)))) (defun mu4e~view-construct-attachments-header (msg) "Display attachment information; the field looks like something like: @@ -769,9 +771,10 @@ If the optional argument URL is provided, browse that instead. If the url is mailto link, start writing an email to that address." (interactive) (let* (( url (or url (mu4e~view-get-property-from-event 'mu4e-url)))) - (if (string-match-p "^mailto:" url) - (mu4e~compose-browse-url-mail url) - (browse-url url)))) + (when url + (if (string-match-p "^mailto:" url) + (mu4e~compose-browse-url-mail url) + (browse-url url))))) (defun mu4e~view-show-images-maybe (msg) "Show attached images, if `mu4e-show-images' is non-nil."