My friend Rémi found an Emacs package developed by Tecosaur to take screenshots of your code. I usually do it with scrot, but it always requires spending some time cropping the result with Gimp. A bit annoying.
The first one would be to clone the
repository, add its location to
load-path, and use
require to load the module. But doing so means having
to explicitely install its dependencies,
(use-package screenshot :straight (:type git :host github :repo "tecosaur/screenshot"))
Evaluate the form with
C-x C-e, and
straight.el will clone the repository
and load the
M-x screenshot to take a screenshot. If you are currently
selecting a region, it will screenshot this part only. If not, it will use the
Since Screenshot uses the
transient library, it has the same well designed interface system as
I really like the ability to adjust the font size just for the screenshot. By
save action will save the image in the same directory as the
buffer which was selected when
screenshot was executed.
Screenshot lets you change the default value of each setting. This is not
obvious when reading the code, because the variables used are defined
programmatically through two layers of macros: first
It is too bad these values are not defined as proper settings using
defcustom, but we can still set them.
This is a list of available settings:
||Whether to display line numbers or not.|
||Whether to use relative line numbers or not.|
||Whether to show code as simple text or not.|
||Whether to truncate long lines instead of wrapping them.|
||The name of the font to use.|
||The size of the font to use.|
||The width of the border.|
||The corner radius of the border.|
||The minimal width of the screenshot as a number of characters.|
||The maximal width of the screenshot as a number of characters.|
||The corner radius of the shadow.|
||The intensity of the shadow.|
||The hexadecimal code of the shadow.|
||The horizontal offset of the shadow in pixels.|
||The vertical offset of the shadow in pixels.|
Another nice feature is the presence of a hook executed in the temporary buffer used for the screenshot, allowing to execute code affecting this buffer just before the actual screenshot is being taken.
In my case, I use it to disable the fill column indicator and to remove the additional line spacing added by default by Screenshot.
This is my configuration:
(defun g-screenshot-on-buffer-creation () (setq display-fill-column-indicator-column nil) (setq line-spacing nil)) (use-package screenshot :straight (:type git :host github :repo "tecosaur/screenshot") :config (setq screenshot-line-numbers-p nil) (setq screenshot-min-width 80) (setq screenshot-max-width 80) (setq screenshot-truncate-lines-p nil) (setq screenshot-text-only-p nil) (setq screenshot-font-family "Berkeley Mono") (setq screenshot-font-size 10) (setq screenshot-border-width 16) (setq screenshot-radius 0) (setq screenshot-shadow-radius 0) (setq screenshot-shadow-offset-horizontal 0) (setq screenshot-shadow-offset-vertical 0) :hook ((screenshot-buffer-creation-hook . g-screenshot-on-buffer-creation)))
All in all a very useful package!