bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra


From: Stephane Chauveau
Subject: bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra
Date: Fri, 9 Dec 2016 10:30:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

Hi,

I have the same problem and I was indeed able to fix it by replacing the \a by \e\\

Below is my patched gui-backend-get-selection (for 25.5.1) and how I enable
it in my .emacs.

(unless window-system
  (when (string= emacs-version "25.1.1" )

    ;;
    ;; The \a used to terminate the OSC52 get-selection reply is causing
    ;; some issues in the current term/xterm.el implementation (emacs 25.1).
    ;; so avoid calling (xterm--init-activate-get-selection)
    ;;
    ;; Below is patched version of the faulty method
    ;;
    (cl-defmethod gui-backend-get-selection
        (type data-type
              &context (window-system nil)
              ;; Only applies to terminals which have it enabled.
              ((terminal-parameter nil 'xterm--get-selection-PATCHED) (eql t)))
      (unless (eq data-type 'STRING)
        (error "Unsupported data type %S" data-type))
      (let* ((screen (eq (terminal-parameter nil 'terminal-initted)
                         'terminal-init-screen))
             (query (concat "\e]52;" (xterm--selection-char type) ";")))
        (with-temp-buffer
          (set-buffer-multibyte nil)
          (xterm--query
           (concat (when screen "\eP") query "?\e\\" (when screen "\e\\"))
           (list (cons query (lambda ()
                               (while (let ((char (read-char)))
                                        (unless (eq char ?\\)
                                          (unless (eq char ?\e)
                                            (insert char))
                                          t))))))
           'no-async)
          (base64-decode-region (point-min) (point-max))
          (decode-coding-region (point-min) (point-max) 'utf-8-unix t))))

    ;; Call this instead of xterm--init-activate-get-selection
    ;; to enable our patched implementation of gui-backend-get-selection
    (defun xterm--init-activate-get-selection-PATCHED ()
      (set-terminal-parameter nil 'xterm--get-selection-PATCHED t)
      )

    ;; a hook that will be called at the end of the xterm initialization
    (defun xterm-osc52-hook ()
      "Specific configuration when running in xterm"
      (message "in xterm-osc52-hook")
      (xterm--init-activate-set-selection)
      (xterm--init-activate-get-selection-PATCHED)
      )
(add-hook 'terminal-init-xterm-hook 'xterm-osc52-hook) ) ;; end of check of emacs version ) ;; end of unless window-system

==============

It probably does not work well with Screen because \e\\ is also the DCS terminator.

I do not use Screen but looking at the implementation of gui-backend-set-selection, I suppose that a solution could be to split the DSC request in two between the \e and the \\.

For instance, the line

(concat (when screen "\eP") query "?\e\\" (when screen "\e\\"))

could become

(concat (when screen "\eP") query "?\e" (when screen "\e\\\eP")
 "\\" (when screen "\e\\"))


Remark: Tmux requires a different DCS format and so will not work properly even though it is identified as Screen.









reply via email to

[Prev in Thread] Current Thread [Next in Thread]