holomorph / transmission

Emacs interface to a Transmission session
GNU General Public License v3.0
85 stars 11 forks source link

Adding specially crafted magnet activates TRAMP #2

Open winny- opened 8 years ago

winny- commented 8 years ago

Not sure what's going on here. I have used magnets for weeks now, and haven't had this odd behavior happen to me before:

Steps to reproduce

  1. Start transmission M-x transmission.
  2. Type a to add a new torrent.
  3. Enter the following magnet URI magnet:?xt=urn:btih:09e37f73e51f403bb543517f0d0a2e1283d61eb0&dn=archlinux-2015.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce from the Archlinux download page.
  4. Emacs tries to ssh into some Archlinux host.

    Expected result

transmission-mode adds the torrent, ignoring any sort of TRAMP shenanigans.

Gif of the issue

cast

holomorph commented 8 years ago

This is probably because I'm using read-file-name. I used to have it so that a prefix key would instead make transmission-add use read-string (now a prefix key prompts for download directory) because yanking arch's magnet link into the prompt would do this nonsense because of the forward slashes. ffs Does it happen if you, for instance, move your emacs.d so there's no tramp history around and do the same thing? I have not encountered this, but I also never use tramp. Edit: I repro'd

holomorph commented 8 years ago

OK, so this isn't really a bug, just annoying. I actually experienced the same thing in the past and just worked around it by either pasting into M-: or the scratch buffer. In any case, there seems to be no simple way to temporarily disable tramp. Even if it was possible, doing so would preclude using tramp to add remote files, which is a pretty nifty use of tramp.

Reverting back to the previous behavior, which was to use read-string instead of read-file-name when a prefix key is used, is not an option for me because I think the new behaviour of adding prompts with a prefix key is better (plus, it was a feature request).

I will try to deal with this by teaching transmission-add default arguments; that is, it will try to guess torrents at point: URLs, file names, or info hashes. I suppose this could be extended to look at the kill ring as well.

winny- commented 8 years ago

Hey, thanks for looking into this. That is a neat use for TRAMP. It sounds like a good idea to guess what the arg to transmission-add actually is.

winny- commented 8 years ago

By the way, I added this to my init.el, and it seems to work perfectly:

(add-hook 'transmission-mode-hook
          (lambda ()
            (local-set-key
             (kbd "A")
             (lambda ()
               (interactive)
               (transmission-add (read-string "Magnet URI: "))))))
spiderbit commented 8 years ago
(define-key transmission-mode-map (kbd "A") 
  (lambda ()
    (interactive)
    (transmission-add (read-string "Magnet URI: "))))

No need for a hook just set the key for the mode. Should do the same, except dont waste a few cpu cycles each time you switch to transmission.

A question can you set the normal transmission standart path to nil? so that the prompt is empty? Have to delete it always.

holomorph commented 8 years ago

A question can you set the normal transmission standart path to nil? so that the prompt is empty? Have to delete it always.

let-binding default-directory to the empty string seems sufficient.

winny- commented 8 years ago

@spiderbit that looks much cleaner, thanks for pointing that out!