Skip to content

Instantly share code, notes, and snippets.

@Luctins

Luctins/insert-image.el

Last active Jan 26, 2021
Embed
What would you like to do?
orgmode image inserter
(defun org-insert-image-from-clipboard ()
"Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file. Depends in X.org to work (for now)"
(interactive)
(setq folder-name (concat (file-name-sans-extension (buffer-file-name)) "-orgimg"))
(message folder-name)
(if (not (file-directory-p folder-name))
(make-directory folder-name nil))
(setq filename
(concat
folder-name "/"
(make-temp-name
(concat ;(buffer-file-name) ;"-"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
;; TODO: add switch to detect Xorg or wayland session using (getenv "XDG_SESSION_TYPE")
(insert
(if (string= (car (split-string
(shell-command-to-string
(concat "xclip -selection clip -t image/png -o >> " filename ))
":")) "Error")
(message "clipboard does not contain a image!")
(concat "[[./" (file-relative-name filename) "]]")))
(org-display-inline-images))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment