diff options
author | Alexander Griffith <griffitaj@gmail.com> | 2018-03-01 18:58:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-01 18:58:45 -0500 |
commit | db1ae6f94e13475b9fae16bbe290d280f12feeb1 (patch) | |
tree | f1acdd32e17310edbf28f0503e4cc4c28d6d8ff9 /lisp | |
parent | 6c95ac3960852ba0bb41b68675a393e8ebbf49e0 (diff) | |
parent | f9f683f4abb3ef7ddf3f90c4bb216153bb05d23d (diff) |
Merge pull request #157 from hdurer/async-images-check-deleted-buffers
When processing async loaded images check for deleted buffers
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-media.el | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 612fad5..94c6e9f 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -133,31 +133,32 @@ IMAGE-OPTIONS are the precomputed options to apply to the image. MARKER is the marker to where the response should be visible. REGION-LENGTH is the length of the region that should be replaced with the image. " - (let ((url-buffer (current-buffer)) - (is-error-response-p (eq :error (car status-plist)))) - (unwind-protect - (let* ((data (unless is-error-response-p - (goto-char (point-min)) - (search-forward "\n\n") - (buffer-substring (point) (point-max)))) - (image (when data - (apply #'create-image data (when image-options 'imagemagick) - t image-options)))) - (switch-to-buffer (marker-buffer marker)) - ;; Save narrowing in our buffer - (let ((inhibit-read-only t)) - (save-restriction - (widen) - (put-text-property marker (+ marker region-length) 'media-state 'loaded) - (when image - ;; We only set the image to display if we could load - ;; it; we already have set a default image when we - ;; added the tag. - (put-text-property marker (+ marker region-length) - 'display image)) - ;; We are done with the marker; release it: - (set-marker marker nil))) - (kill-buffer url-buffer))))) + (when (marker-buffer marker) ; only if the buffer hasn't been kill in the meantime + (let ((url-buffer (current-buffer)) + (is-error-response-p (eq :error (car status-plist)))) + (unwind-protect + (let* ((data (unless is-error-response-p + (goto-char (point-min)) + (search-forward "\n\n") + (buffer-substring (point) (point-max)))) + (image (when data + (apply #'create-image data (when image-options 'imagemagick) + t image-options)))) + (switch-to-buffer (marker-buffer marker)) + ;; Save narrowing in our buffer + (let ((inhibit-read-only t)) + (save-restriction + (widen) + (put-text-property marker (+ marker region-length) 'media-state 'loaded) + (when image + ;; We only set the image to display if we could load + ;; it; we already have set a default image when we + ;; added the tag. + (put-text-property marker (+ marker region-length) + 'display image)) + ;; We are done with the marker; release it: + (set-marker marker nil))) + (kill-buffer url-buffer)))))) (defun mastodon-media--load-image-from-url (url media-type start region-length) "Takes a URL and MEDIA-TYPE and load the image asynchronously. |