> +  (setq interprogram-cut-function
> +        (if (string-prefix-p "screen" (getenv "TERM"))
> +            #'xterm--screen-interprogram-cut
> +          #'xterm--interprogram-cut)))

Please don't change interprogram-cut-function, since this breaks down if
you use a single Emacs session with both GUI and text frames (and with
potentially various different terminal kinds).

Instead use gui-method-declare for gui-set-selection (new in Emacs-25).

Thanks, I'll modify the patch accordingly tomorrow.
 

Sorry for the delay. I've tried implementing this, but I'm a bit at a loss here: If I understand the GUI method code correctly, it only works for real GUIs, not terminal emulators that happen to be GUI applications, right? At least the window-system variable, which gui-method apparently uses, is always nil in my tests with hterm. Should this be something like 'xterm?