Skip to content

Instantly share code, notes, and snippets.

@rougier
Created April 30, 2022 12:57
Show Gist options
  • Save rougier/b6c60c27b2969b21b7c06154303472c7 to your computer and use it in GitHub Desktop.
Save rougier/b6c60c27b2969b21b7c06154303472c7 to your computer and use it in GitHub Desktop.
GNU Emacs DND protocol
;; Open scratch buffer, evalute code below and drag and drop some files onto the scratch buffer.
;; Code by Ivan Tadeu Ferreira Antunes Filho
;; https://ivanaf.com/emacs_drag-drop_pdfs_paste_html_custom_templates.html
(defun scratch--file-insert (uri)
(message "%s" uri))
(defun scratch--file-dnd-fallback (uri action)
(let ((dnd-protocol-alist
(rassq-delete-all 'scratch--file-dnd-protocol
(copy-alist dnd-protocol-alist))))
(dnd-handle-one-url nil action uri)))
(defun scratch--file-dnd-protocol (uri action)
(cond ((string= (buffer-name) "*scratch*")
(condition-case nil
(scratch--file-insert uri)
;; (error
;; (scratch--file-dnd-fallback uri action))
))
(t
(scratch--file-dnd-fallback uri action))))
(add-to-list 'dnd-protocol-alist
'("^file:" . scratch--file-dnd-protocol))
;; --- Code by Ivan Tadeu Ferreira Antunes Filho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment