GNU Emacs
Emacs
Dashboard

21.14 Drag and Drop

In most graphical desktop environments, Emacs has basic support for drag and drop operations. For instance, dropping text onto an Emacs frame inserts the text where it is dropped. Dropping a file onto an Emacs frame visits that file. As a special case, dropping the file on a Dired buffer moves or copies the file (according to the conventions of the application it came from) into the directory displayed in that buffer.

Dropping a file normally visits it in the window you drop it on. If you prefer to visit the file in a new window in such cases, customize the variable dnd-open-file-other-window.

The XDND and Motif drag and drop protocols, and the old KDE 1.x protocol, are currently supported.

Emacs can also optionally drag the region with the mouse into another portion of this or another buffer. To enable that, customize the variable mouse-drag-and-drop-region to a non- nil value. Normally, the text is moved, i.e. cut and pasted, when the destination is the same buffer as the origin; dropping the region on another buffer copies the text instead. If the value of this variable names a modifier key, such as ‘ shift’, ‘ control’ or ‘ alt’, then pressing that modifier key when dropping the text will copy it instead of cutting it, even if you drop on the same buffer as the one from which the text came.

In order to cut text even when source and destination buffers differ, set the option mouse-drag-and-drop-region-cut-when-buffers-differ to a non- nil value. By default, on a graphic display the selected text is shown in a tooltip and point moves together with the mouse cursor during dragging. To suppress such behavior, set the options mouse-drag-and-drop-region-show-tooltip and/or mouse-drag-and-drop-region-show-cursor to nil.