Repository navigation
Type file paths into the terminal for X11/pgtk drops and clipboard-image pastes - #626
Merged
Merged
Conversation
X11 and pgtk dispatch drag-and-drop through special-event-map and the dnd-protocol-alist machinery, so the <drag-n-drop> binding in ghostel-mode-map never fires there and a dropped file opened with find-file instead of typing its path. Register a buffer-local dnd-protocol-alist handler (the dired pattern) that shell-quotes the dropped path into the terminal, converts hostname-qualified local URIs, ignores foreign-host URIs, and falls back to opening the file when the terminal has no live process. File drops now end with a separating space on all ports.
A PTY has no inbound image channel, so a clipboard image can only reach a terminal program as a file path. Register a buffer-local yank-media handler (Emacs 29+) that writes the clipboard image to a temp file and types its shell-quoted path, sharing the send path with drag-and-drop. The file is created in the temp directory of the host the shell runs on, so TRAMP terminals receive a valid host-side path; the bytes are written in the exclusive-create call under a binary coding system so a dos-EOL default cannot corrupt them. A drop into a dead terminal signals user-error. The extension mapping inlines the MIME-subtype rule because mailcap-mime-type-to-extension is Emacs 29+ and package-lint rejects the unguarded call.
The yank-media handler already writes arbitrary clipboard bytes to a temp file, so register it for application/pdf as well and rename it to ghostel--yank-media-data. The autoselect catch-all also accepts PDF, after image flavors, so a PDF-only clipboard pastes while an image still wins when both are offered.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On X11 and pgtk, dropping a file onto a ghostel buffer opened it with
find-fileinstead of typing its path into the terminal. Those ports dispatchdrag-n-dropthroughspecial-event-map, which is handled insideread_charbefore any key-sequence lookup — so the<drag-n-drop>binding inghostel-mode-mapnever fires there. (NS and w32 bind the event in the global map instead, which the mode map shadows; that's why drops always worked on macOS.)Relatedly, there was no way to paste a clipboard image (e.g. a screenshot) into the terminal at all: a PTY has no inbound image channel, so an image can only reach a terminal program as a file path.
File drops (commit 1)
Register a buffer-local
dnd-protocol-alisthandler inghostel-mode(the same mechanism dired uses). The handler:file://<localhost>/path) viadnd-get-local-file-uri, mirroring the stockdnd-open-filechaindnd-open-local-filewhen the terminal has no live process, so drops into a[Process exited]buffer behave like stock Emacs instead of vanishing into a retired PTYThe existing
<drag-n-drop>keymap binding stays for NS/w32; its file branch now shares the same sending helper, so file drops end with a separating space on all ports.Clipboard images and PDFs via yank-media (commits 2-3)
Register a buffer-local
yank-mediahandler (Emacs 29+) forimage/.*andapplication/pdfthat writes the clipboard bytes to a temp file and types its shell-quoted path, sharing the send path with drag-and-drop. The file is created in the temp directory of the host the shell runs on, so TRAMP terminals receive a valid host-side path; the bytes are written in the exclusive-create call under a binary coding system so a dos-EOL default cannot corrupt them. A paste into a dead terminal signalsuser-error.Emacs 31's autoselect only prefers png/jpeg, which strands TIFF-only clipboards (Qt applications like Flameshot declare TIFF on macOS) with "No preferred MIME type to yank" —
ghostel-modeappends a buffer-local catch-all toyank-media-preferred-typesso any image flavor (and PDF, after images) autoselects while stock priorities still win.Verification
NSPasteboard declareTypes:— AppleScript-set clipboards advertise synthesized flavors and don't reproduce the bug).dnd-handle-multiple-urlsentry point; 6 new ERT tests cover the yank-media handler (byte round-trip across all 256 byte values under a dos-EOL default, remote localname, autoselect, dead-terminal guard).Known limitations, deliberately out of scope: Emacs 29 pgtk consults
dnd-protocol-alistin the wrong buffer (nowith-selected-windowbefore Emacs 30; main supported version is 30+), Emacs 30+'sdnd-handle-multiple-urlsdelivers 3+-URI drops out of source order (upstream quirk in its collection loop), text/URL drops on X11 keep their stock behavior, and pasted temp files are left to OS temp reaping (the shell consumes the path after every ghostel-visible event has passed).