visual-mode and X-selections

Hans-Peter Deifel hpdeifel at gmx.de
Thu Nov 1 15:53:33 CET 2012


Hi List!

I think that the interaction between visual-mode and the X11 selections
is not optimal. Since I don't know if the current behavior is
intentional, I haven't yet opened a bug report.

The selected text in visual-mode is currently copied via the function
x-select-text. With the Emacs 24.1 default configuration, this copies to
the X-selection CLIPBOARD (configurable through
x-select-enable-clipboard and x-select-enable-primary.)

In the rest of Emacs, this function is only used for the explicit
copy/yank commands. Copying the active region is controlled by the
variable select-active-regions and uses the PRIMARY X-selection by
default.

This behavior is consistent with most other X applications: The mouse
selection is saved in PRIMARY and the explicit copy/paste commands use
the CLIPBOARD.

Thus, it would be nice if Evil would also use the PRIMARY selection by
default for the selected text in visual-mode.

I currently use the following redefinition of
evil-visual-update-x-selection, that does what I need:

#+BEGIN_SRC elisp
(defun evil-visual-update-x-selection (&optional buffer)
  "Update the X selection with the current visual region."
  (with-current-buffer (or buffer (current-buffer))
    (when (and (evil-visual-state-p)
               (fboundp 'x-select-text)
               (or (not (boundp 'ns-initialized))
                   (with-no-warnings ns-initialized))
               (not (eq evil-visual-selection 'block)))
      (x-set-selection 'PRIMARY (buffer-substring-no-properties
                                 evil-visual-beginning
                                 evil-visual-end))
      (setq x-last-selected-text-primary ))))
#+END_SRC

Regards,
Hans-Peter



More information about the implementations-list mailing list