diff options
| author | Jim Porter | 2024-06-23 14:53:49 -0700 |
|---|---|---|
| committer | Jim Porter | 2024-07-04 12:14:37 -0700 |
| commit | f91387cce8f6f1dced427ad44686ffcc69574ef6 (patch) | |
| tree | b272e2feef489f2425b8d2929410d472c26ae7f2 | |
| parent | 208207c1c07fb4669c6b7d64c27236074f996ae4 (diff) | |
| download | emacs-f91387cce8f6f1dced427ad44686ffcc69574ef6.tar.gz emacs-f91387cce8f6f1dced427ad44686ffcc69574ef6.zip | |
In SHR, load from URL cache if possible when zooming images
* lisp/net/shr.el (shr-replace-image): New function extracted from...
(shr-image-fetched): ... here.
(shr-zoom-image): Check URL cache and call 'shr-replace-image' if we
can.
| -rw-r--r-- | lisp/net/shr.el | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 8b62691bfb6..ea3d8deeff8 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -678,17 +678,22 @@ full-buffer size." | |||
| 678 | (start (or (previous-single-property-change end 'image-url) | 678 | (start (or (previous-single-property-change end 'image-url) |
| 679 | (point-min))) | 679 | (point-min))) |
| 680 | (dom-size (get-text-property position 'image-dom-size)) | 680 | (dom-size (get-text-property position 'image-dom-size)) |
| 681 | (flags `( :zoom ,zoom-level | ||
| 682 | :width ,(car dom-size) | ||
| 683 | :height ,(cdr dom-size))) | ||
| 681 | (buffer-read-only nil)) | 684 | (buffer-read-only nil)) |
| 682 | ;; Delete the old picture. | 685 | ;; Delete the old picture. |
| 683 | (put-text-property start end 'display nil) | 686 | (put-text-property start end 'display nil) |
| 684 | (message "%s" (cadr (assq zoom-level shr-image-zoom-level-alist))) | 687 | (message "%s" (cadr (assq zoom-level shr-image-zoom-level-alist))) |
| 685 | (url-retrieve url #'shr-image-fetched | 688 | (if (and (not shr-ignore-cache) |
| 686 | `(,(current-buffer) ,start | 689 | (url-is-cached url)) |
| 687 | ,(set-marker (make-marker) end) | 690 | (shr-replace-image (shr-get-image-data url) start |
| 688 | (:zoom ,zoom-level | 691 | (set-marker (make-marker) end) flags) |
| 689 | :width ,(car dom-size) | 692 | (url-retrieve url #'shr-image-fetched |
| 690 | :height ,(cdr dom-size))) | 693 | `(,(current-buffer) ,start |
| 691 | t))))) | 694 | ,(set-marker (make-marker) end) |
| 695 | ,flags) | ||
| 696 | t)))))) | ||
| 692 | 697 | ||
| 693 | ;;; Utility functions. | 698 | ;;; Utility functions. |
| 694 | 699 | ||
| @@ -1109,6 +1114,25 @@ the mouse click event." | |||
| 1109 | (expand-file-name (file-name-nondirectory url) | 1114 | (expand-file-name (file-name-nondirectory url) |
| 1110 | directory))))) | 1115 | directory))))) |
| 1111 | 1116 | ||
| 1117 | (defun shr-replace-image (data start end &optional flags) | ||
| 1118 | (save-excursion | ||
| 1119 | (save-restriction | ||
| 1120 | (widen) | ||
| 1121 | (let ((alt (buffer-substring start end)) | ||
| 1122 | (properties (text-properties-at start)) | ||
| 1123 | ;; We don't want to record these changes. | ||
| 1124 | (buffer-undo-list t) | ||
| 1125 | (inhibit-read-only t)) | ||
| 1126 | (remove-overlays start end) | ||
| 1127 | (delete-region start end) | ||
| 1128 | (goto-char start) | ||
| 1129 | (funcall shr-put-image-function data alt flags) | ||
| 1130 | (while properties | ||
| 1131 | (let ((type (pop properties)) | ||
| 1132 | (value (pop properties))) | ||
| 1133 | (unless (memq type '(display image-zoom)) | ||
| 1134 | (put-text-property start (point) type value)))))))) | ||
| 1135 | |||
| 1112 | (defun shr-image-fetched (status buffer start end &optional flags) | 1136 | (defun shr-image-fetched (status buffer start end &optional flags) |
| 1113 | (let ((image-buffer (current-buffer))) | 1137 | (let ((image-buffer (current-buffer))) |
| 1114 | (when (and (buffer-name buffer) | 1138 | (when (and (buffer-name buffer) |
| @@ -1119,23 +1143,7 @@ the mouse click event." | |||
| 1119 | (search-forward "\r\n\r\n" nil t)) | 1143 | (search-forward "\r\n\r\n" nil t)) |
| 1120 | (let ((data (shr-parse-image-data))) | 1144 | (let ((data (shr-parse-image-data))) |
| 1121 | (with-current-buffer buffer | 1145 | (with-current-buffer buffer |
| 1122 | (save-excursion | 1146 | (shr-replace-image data start end flags))))) |
| 1123 | (save-restriction | ||
| 1124 | (widen) | ||
| 1125 | (let ((alt (buffer-substring start end)) | ||
| 1126 | (properties (text-properties-at start)) | ||
| 1127 | ;; We don't want to record these changes. | ||
| 1128 | (buffer-undo-list t) | ||
| 1129 | (inhibit-read-only t)) | ||
| 1130 | (remove-overlays start end) | ||
| 1131 | (delete-region start end) | ||
| 1132 | (goto-char start) | ||
| 1133 | (funcall shr-put-image-function data alt flags) | ||
| 1134 | (while properties | ||
| 1135 | (let ((type (pop properties)) | ||
| 1136 | (value (pop properties))) | ||
| 1137 | (unless (memq type '(display image-zoom)) | ||
| 1138 | (put-text-property start (point) type value))))))))))) | ||
| 1139 | (kill-buffer image-buffer))) | 1147 | (kill-buffer image-buffer))) |
| 1140 | 1148 | ||
| 1141 | (defun shr-image-from-data (data) | 1149 | (defun shr-image-from-data (data) |