From: Lars Ingebrigtsen Date: Tue, 4 Oct 2022 13:40:53 +0000 (+0200) Subject: Make cropping of images work in message-mode X-Git-Tag: emacs-29.0.90~1856^2~30 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=682662202d1aca3d43ac50963693cea3fc1b9dcf;p=emacs.git Make cropping of images work in message-mode * lisp/gnus/message.el (message-mode): Set the image cropping function. (message--yank-media-image-handler): Factor out... (message--image-part-string): ... here for reuse. (message--update-image-crop): Update the cropped data. --- diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index 084dce65f09..beccef6f5f4 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -3208,7 +3208,8 @@ Like `text-mode', but with these additional commands: ;; (setq-local syntax-propertize-function #'message--syntax-propertize) (setq-local parse-sexp-ignore-comments t) - (setq-local message-encoded-mail-cache nil)) + (setq-local message-encoded-mail-cache nil) + (setq-local image-crop-buffer-text-function #'message--update-image-crop)) (defun message-setup-fill-variables () "Setup message fill variables." @@ -8927,19 +8928,26 @@ used to take the screenshot." :max-width (truncate (* (frame-pixel-width) 0.8)) :max-height (truncate (* (frame-pixel-height) 0.8)) :scale 1) - (format "<#part type=\"%s\" disposition=inline data-encoding=base64 raw=t>\n%s\n<#/part>" - type - ;; Get a base64 version of the image -- this avoids later - ;; complications if we're auto-saving the buffer and - ;; restoring from a file. - (with-temp-buffer - (set-buffer-multibyte nil) - (insert image) - (base64-encode-region (point-min) (point-max) t) - (buffer-string))) + (message--image-part-string type image) nil nil t) (insert "\n\n")) +(defun message--image-part-string (type image) + (format "<#part type=\"%s\" disposition=inline data-encoding=base64 raw=t>\n%s\n<#/part>" + type + ;; Get a base64 version of the image -- this avoids later + ;; complications if we're auto-saving the buffer and + ;; restoring from a file. + (with-temp-buffer + (set-buffer-multibyte nil) + (insert image) + (base64-encode-region (point-min) (point-max) t) + (buffer-string)))) + +(declare-function image-crop--content-type "image-crop") +(defun message--update-image-crop (_text image) + (message--image-part-string (image-crop--content-type image) image)) + (declare-function gnus-url-unhex-string "gnus-util") (defun message-parse-mailto-url (url)