Function: message-insert-screenshot

message-insert-screenshot is an interactive and byte-compiled function defined in message.el.gz.

Signature

(message-insert-screenshot DELAY)

Documentation

Take a screenshot and insert in the current buffer.

DELAY (the numeric prefix) says how many seconds to wait before starting the screenshotting process.

The message-screenshot-command variable says what command is used to take the screenshot.

Probably introduced at or before Emacs version 28.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/message.el.gz
(defun message-insert-screenshot (delay)
  "Take a screenshot and insert in the current buffer.
DELAY (the numeric prefix) says how many seconds to wait before
starting the screenshotting process.

The `message-screenshot-command' variable says what command is
used to take the screenshot."
  (interactive "p" message-mode)
  (unless (executable-find (car message-screenshot-command))
    (error "Can't find %s to take the screenshot"
	   (car message-screenshot-command)))
  (cl-decf delay)
  (unless (zerop delay)
    (dotimes (i delay)
      (message "Sleeping %d second%s..."
	       (- delay i)
	       (if (= (- delay i) 1)
		   ""
		 "s"))
      (sleep-for 1)))
  (message "Take screenshot")
  (let ((image
	 (with-temp-buffer
	   (set-buffer-multibyte nil)
	   (apply #'call-process
		  (car message-screenshot-command) nil (current-buffer) nil
		  (cdr message-screenshot-command))
	   (buffer-string))))
    (set-mark (point))
    (insert-image
     (create-image image 'png t
		   :max-width (truncate (* (frame-pixel-width) 0.8))
		   :max-height (truncate (* (frame-pixel-height) 0.8))
		   :scale 1)
     (format "<#part type=\"image/png\" disposition=inline data-encoding=base64 raw=t>\n%s\n<#/part>"
	     ;; 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))))
    (insert "\n\n")
    (message "")))