[Emacs] Add code for taking screenshots of Emacs
This commit is contained in:
parent
e004e7d0c0
commit
0d24b4a056
@ -549,6 +549,63 @@ b s~, which bring the user directly to the ~*Messages*~ buffer and the
|
|||||||
(switch-to-buffer "*scratch*"))
|
(switch-to-buffer "*scratch*"))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** Screenshots
|
||||||
|
:PROPERTIES:
|
||||||
|
:CUSTOM_ID: Custom-Elisp-Screenshots-l9bkib013aj0
|
||||||
|
:END:
|
||||||
|
Since Emacs27, it is possible for Emacs to take screenshots of itself
|
||||||
|
in various formats. I’m mainly interested by the SVG and PNG format,
|
||||||
|
so I’ll only write functions for these. It isn’t really redundant with
|
||||||
|
the ~screenshot.el~ package used [[#Packages-Configuration-Applications-Screenshot96d1fl6184j0][here]] since these functions take a
|
||||||
|
screenshot of Emacs as a whole rather than of a code snippet.
|
||||||
|
|
||||||
|
First, we have a general function which is a slight modification of
|
||||||
|
the function shared by Alphapapa in [[https://www.reddit.com/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/g2c2c6y/][this Reddit comment]]. It has been
|
||||||
|
modified so it is possible to pass the function an argument for the
|
||||||
|
format the screenshot will be taken as, and if ~type~ is ~nil~ the user
|
||||||
|
can still chose it.
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun self-screenshot (&optional type)
|
||||||
|
"Save a screenshot of type TYPE of the current Emacs frame.
|
||||||
|
As shown by the function `', type can weild the value `svg',
|
||||||
|
`png', `pdf'.
|
||||||
|
|
||||||
|
This function will output in /tmp a file beginning with \"Emacs\"
|
||||||
|
and ending with the extension of the requested TYPE."
|
||||||
|
(interactive)
|
||||||
|
(let* ((type (if type type
|
||||||
|
(intern (completing-read "Screenshot Type: "
|
||||||
|
'(png svg pdf postscript)))))
|
||||||
|
(extension (pcase type
|
||||||
|
('png ".png")
|
||||||
|
('svg ".svg")
|
||||||
|
('pdf ".pdf")
|
||||||
|
('postscript ".ps")
|
||||||
|
(otherwise (error "Cannot export screenshot of type %s" otherwise))))
|
||||||
|
(filename (make-temp-file "Emacs-" nil extension))
|
||||||
|
(data (x-export-frames nil type)))
|
||||||
|
(with-temp-file filename
|
||||||
|
(insert data))
|
||||||
|
(kill-new filename)
|
||||||
|
(message filename)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
For convenience’s sake, I’ll also write two functions dedicated to
|
||||||
|
taking a screenshot in the SVG format and the PNG format respectively.
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun self-screenshot-svg ()
|
||||||
|
"Save an SVG screenshot of Emacs.
|
||||||
|
See `self-screenshot'."
|
||||||
|
(interactive)
|
||||||
|
(self-screenshot 'svg))
|
||||||
|
|
||||||
|
(defun self-screenshot-png ()
|
||||||
|
"Save a PNG screenshot of Emacs.
|
||||||
|
See `self-screenshot'."
|
||||||
|
(interactive)
|
||||||
|
(self-screenshot 'png))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** Org Functions
|
** Org Functions
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: Custom-Elisp-Org-Functionsyshkel6184j0
|
:CUSTOM_ID: Custom-Elisp-Org-Functionsyshkel6184j0
|
||||||
|
Loading…
Reference in New Issue
Block a user