(defun cycoe/create-image-dir (&optional image-dir)
(interactive)
(let ((dir (or image-dir (car (split-string (buffer-name (current-buffer)) "\\.")))))
(if (file-exists-p dir)
(message "directory ./%s is exists!" dir)
(make-directory-internal dir))
dir))
(add-hook 'org-mode-hook 'cycoe/create-image-dir)
(defun org-insert-clipboard-image ()
(interactive)
(let ((filepath (concat
(cycoe/create-image-dir)
(make-temp-name
(concat "/Screenshot_" (format-time-string "%Y%m%d_%H%M%S_")))
".png")))
(shell-command (concat "xclip -selection clipboard -t image/png -o > /dev/null && xclip -selection clipboard -t image/png -o > " filepath))
(when (file-exists-p filepath)
(insert (concat "[[file:" filepath "]]")))))
如上所示,当剪贴板里没有图片时运行 org-insert-clipboard-image 会卡死,但是在命令行直接运行 xclip -selection clipboard -t image/png -o > /dev/null && xclip -selection clipboard -t image/png -o > test.png
则没问题,有大佬知道怎么解决吗