Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emacs-vterm and dnd (drag and drop) #710

Open
rpaulo opened this issue Mar 21, 2024 · 0 comments
Open

emacs-vterm and dnd (drag and drop) #710

rpaulo opened this issue Mar 21, 2024 · 0 comments

Comments

@rpaulo
Copy link

rpaulo commented Mar 21, 2024

Some terminals allow you to drag and drop files from the Finder/Nautilus/etc. and the path name will be inserted into the terminal window. If you do this in Emacs (GUI), the file is opened instead.

To overcome this problem, I wrote this function to insert an escaped path name into Emacs when vterm-mode is in use:

(defun rpaulo-dnd-handle-one-url (orig-fun &rest args)
  "Overrides dnd-handle-one-url in vterm-mode so that when
dragging and dropping a file to vterm the entire shell escaped
path name is inserted instead."
  (if (string= major-mode "vterm-mode")
      (let ((window (nth 0 args))
            (action (nth 1 args))
            (text (nth 2 args)))
        (if (string-match "^file:" text)
            (let ((filename (substring text 5)))
              (dnd-insert-text window action (shell-quote-argument filename))
              (vterm-yank))
          (dnd-insert-text window action text)
          (vterm-yank)))
    (apply orig-fun args)))

(advice-add 'dnd-handle-one-url :around #'rpaulo-dnd-handle-one-url)

I think it may be useful for vterm to have an option that implements this functionality. If you don't agree, feel free to close.

P.S.: This proof of concept elisp code doesn't work on Windows and in some operating systems it adds a couple of extra forward slashes in the beginning (but these cause no problems whatsover).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant