[சனி செப்டம்பர் 23, 2023] Ihor Radchenko wrote: >> +*** Images and files in clipboard can be attached >> + >> +Org can now attach images in clipboard and files copied/cut to the >> +clipboard from file managers using the ~yank-media~ command which also >> +inserts a link to the attached file. >> + >> +Images can be saved to a separate directory instead of being attached, >> +customize ~org-media-image-save-type~. > > This requires Emacs 29, which should be documented.
Yes, will do. >> ;; Update `customize-package-emacs-version-alist' >> (add-to-list 'customize-package-emacs-version-alist >> @@ -15125,20 +15128,20 @@ INCREMENT-STEP divisor." >> (setq hour (mod hour 24)) >> (setq pos-match-group 1 >> new (format "-%02d:%02d" hour minute))) >> - >> + > > These whitespace changes are not relevant. Sorry, I missed these sneaky changes when I made the commit. >> +;;; Yank media handler and DND >> +(defun org-setup-yank-dnd-handlers () >> + "Setup the `yank-media' and DND handlers for buffer." >> + (setq-local dnd-protocol-alist >> + (cons '("^file:///" . org--dnd-local-file-handler) >> + dnd-protocol-alist)) >> + (yank-media-handler "image/.*" #'org--image-yank-media-handler) > > This function is not yet available in Emacs <29. Need to protect with > `fboundp'. Of course. >> +(defcustom org-media-image-save-type 'attach > > Maybe org-yank-image-save-type? That is a better name but still doesn't inform the user that it is respected by DND too. >> +(defun org--image-yank-media-handler (mimetype data) >> + "Save image DATA of mime-type MIMETYPE and insert link at point. >> +It is saved as per `org-media-image-save-type'. The name for the >> +image is prompted and the extension is automatically added to the >> +end." >> + (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype))) >> + (iname (read-string "Insert filename for image: ")) > > It would be nice if we auto-generate the file name here by default. It > is what I would expect from yanking an image at least. Hmm, I think I prefer having a descriptive name for the file. It would aid in searching for the attachment later (in the org document, and using find & friends). We can add a user option but how should the name be auto-generated? Timestamp? I have no ideas in this regard.