我在windows中使用linux虚拟机,但是linux emacs不能支持BMP格式。于是把剪贴板的BMP数据转成PNG,再attach org buffer中。
(defun org-attach-bmp-from-clipboard ()
"Convert BMP image data in clipboard to PNG format."
(interactive)
(if (and
(derived-mode-p 'org-mode)
(seq-contains-p (gui-get-selection 'PRIMARY 'TARGETS) (intern "image/x-bmp")))
(let* ((bmp-data (gui-get-selection 'PRIMARY (intern "image/bmp")))
(temp-bmp-file (make-temp-file "emacs-bmp-" nil ".bmp"))
(temp-png-file (concat (file-name-sans-extension temp-bmp-file) ".png"))
(filename (file-name-nondirectory temp-png-file))
link
)
(unless bmp-data
(error "No image data found in clipboard"))
(let ((coding-system-for-write 'emacs-internal))
(with-temp-file temp-bmp-file
(insert bmp-data)))
(if (executable-find "convert")
(progn
(call-process "convert" nil nil nil temp-bmp-file temp-png-file)
(org-attach-attach temp-png-file nil 'mv)
(setq link (org-link-make-string (concat "attachment:" filename)))
(insert link)
(org-toggle-inline-images)
)
(ERROR "ImageMagick 'convert' command not found. Please install ImageMagick."))
(delete-file temp-bmp-file))
(message "Not in Org Mode Or Not BMP in Clipboard")
))