Paste an image on clipboard to Emacs Org mode file without saving it

后端 未结 8 1008
慢半拍i
慢半拍i 2021-01-30 09:21

As I\'m using the Emacs Org mode as a research log, sometime I want to keep track of something via screenshot images, and I definitely don\'t want to save them. So I\'m wonderin

8条回答
  •  生来不讨喜
    2021-01-30 09:37

    For Windows 10 users, I modified the answer provided by @assem to work with out-of-the-box tools:

    (defun my-org-screenshot ()
      "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."  
       (interactive)
       (setq filename
         (concat
           (make-temp-name
             (concat (buffer-file-name)
                  "_"
                  (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
       (shell-command "snippingtool /clip")
       (shell-command (concat "powershell -command \"Add-Type -AssemblyName System.Windows.Forms;if ($([System.Windows.Forms.Clipboard]::ContainsImage())) {$image = [System.Windows.Forms.Clipboard]::GetImage();[System.Drawing.Bitmap]$image.Save('" filename "',[System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'clipboard content saved as file'} else {Write-Output 'clipboard does not contain image data'}\""))
       (insert (concat "[[file:" filename "]]"))
       (org-display-inline-images))
    

    The whole write-up can be found here

提交回复
热议问题