emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 682662202d: Make cropping of images work in message-mode


From: Lars Ingebrigtsen
Subject: master 682662202d: Make cropping of images work in message-mode
Date: Tue, 4 Oct 2022 09:41:08 -0400 (EDT)

branch: master
commit 682662202d1aca3d43ac50963693cea3fc1b9dcf
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 lisp/gnus/message.el | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 084dce65f0..beccef6f5f 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]