Created
February 21, 2023 16:06
-
-
Save BrandonIrizarry/a8e9c53c3e329c7014e55bc9db84a604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun bci/--screenshot-to-image-format (type) | |
"Save a screenshot of the current frame as a TYPE image, with | |
the appropriate file-extension. | |
TYPE should be given as a quoted symbol, as it is passed directly | |
to `x-export-frames'. | |
The result is saved to a temp file, with the filename placed also | |
in the kill-ring." | |
(let* ((file-extension | |
(if (eq type 'postscript) | |
".ps" | |
(format ".%s" (symbol-name type)))) | |
(filename (make-temp-file "Emacs" nil file-extension)) | |
(data (x-export-frames nil type))) | |
(with-temp-file filename | |
(insert data)) | |
(kill-new filename) | |
(message filename))) | |
;; Wrapper for convenient interactive usage | |
(defun bci/screenshot-to-image-format () | |
(interactive) | |
(let* ((table '(("svg" . svg) | |
("pdf" . pdf) | |
("postscript" . postscript) | |
("png" . png))) | |
(choice | |
(cdr (assoc (completing-read "Format: " | |
'("svg" "pdf" "postscript" "png") nil) | |
table)))) | |
(let ((filename (bci/--screenshot-to-image-format choice))) | |
(if (y-or-n-p "Preview?") | |
(find-file filename))))) | |
(bind-key "C-<print>" #'bci/screenshot-to-image-format) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment