Sewi has asked for the wisdom of the Perl Monks concerning the following question:

We had a recent discussion about X11 pasting behavior on the Padre IRC channel.

This is no Perl challenge, but we're building a Perl IDE and this is why I'ld like to know your preference. Apologies for mis-using perlmonks with this.

The test case was:

abc def
  • abc was selected first
  • def is the current selection
  • The mouse pointer is placed over the "e" of def
  • We noticed three different middle-mouse-button pasting ways throughout the X11 world:

    1. "abc" is inserted before/after the e making the second line "deabcf"

    2. nothing happens at all, because the current selection "def" replaces the current selection "def" (gedit and poedit do this)

    3. "abc" is used to replace the current selection "def" (the last selection is used to replace the current one), this is what Padre did in the last releases.

    4. "def" is appended again (pasted at the text cursor's position), this is what Ubuntu's shell and xman's search input do.

    I'ld like to know...

  • Which option is what you'd call "X11 default"?
  • Which option would be your favorite for a editor/IDE?
  • Thank you.

    Replies are listed 'Best First'.
    Re: X11 pasting
    by almut (Canon) on Dec 29, 2009 at 10:40 UTC

      I don't think there is any "X11 default"; handling of selections/paste buffers has always been up to the individual applications.

      Personally, I would consider 1. the most useful variant, followed by option 3.  OTOH, the 1. behaviour seems rather uncommon (I can't remember to have encountered it in any common application so far), so it's unlikely anyone would expect it...  (Another option I personally like is if the content of the paste buffer is inserted where the editor's text cursor currently is, independently of where exactly you middle-click within the application window, and independently of whether the cursor happens to be in a selection or not.)   In short, I'd say stick with 3. :)

    Re: X11 pasting
    by JavaFan (Canon) on Dec 29, 2009 at 11:23 UTC
      What almut said, there's no "X11 default". All that X11 does is sending the application a mouse-down and a mouse-up event, which in many cases result in the application doing nothing at all. Also note that many application do whatever it would have done if you've typed 'abc' on the keyboard while whatever widget that contains the 'def' has the focus. But other applications do other things: if I select the "abc" in Firefox, and middle-click while hovering over "def", my Firefox loads the page http://abc.go.com.
        "X11 default" may be "something which is usually done by most X11 apps" - like Ctrl-C for copy-to-clipboard.

        Which one would be your favorite?

          it might refer to the default copy buffer, if one isn't specified.... there are a couple of different buffers..... try running "xclip -h" for more info

          I'm not really a human, but I play one on earth.
          Old Perl Programmer Haiku
          Considering that it's X11 you're talking about, I don't think you should look at what applications do, as the behaviour of what happens often differs within the application: different widgets do different things. Take a simple Perl-Tk program using all the default bindings. Middle clicking after a selection will have different effects depending on whether you click on a button, a label or an entry widget.

          I've never used Padre (and I doubt I ever will), but AFAIK, Padre is a graphical application, and hence I'd expect different things to happen depending on where I middle-click.

    Re: X11 pasting
    by rowdog (Curate) on Dec 29, 2009 at 17:56 UTC

      I agree that there is no standard for X11 pasting. I expect the middle button to paste the current selection and if that's not what happens, I'll usually change the program I'm using rather than change my behavior. Vim, Emacs, KDevelop, and Firefox (forms) all give me ddefef.

      That said, I think behavior 3 is interesting and potentially useful but I would want to see that as an option rather than the default. I use selections a lot and it would bug me to paste my last firefox search term rather than the current selection.

      Edit: I meant 3 not 1.

    Re: X11 pasting
    by Porculus (Hermit) on Dec 30, 2009 at 01:57 UTC

      Your #1 and #3 are unexpected, non-standard behaviour. Middle-click in X11 is expected to paste the current selection, not something unpredictable that may have selected at some point in the past.

      If you want to select something without clobbering your "copied text", e.g. in order to select some text and paste over it, then you should not be using the primary selection. Most programs -- including Padre, I assume -- support the standard Ctrl+C/Ctrl+V setup using the clipboard for this kind of operation.

      #2 and #4 are both acceptable behaviours. Emacs provides a configuration option to choose between them.

      I personally favour #4, because I find it easier to get the text cursor in the right place than the mouse pointer. It can be very difficult to middle-click exactly where you want text to be pasted, particularly with inaccurate pointing devices such as laptop touchpads.

    Re: X11 pasting
    by dk (Chaplain) on Dec 29, 2009 at 23:48 UTC
      Just my 5c - I've programmed X11 clipboards using raw Xlib, and I remember that the idea (back then) was that a selection is defined in terms of a program that owns the selection, not text in the clipboard. Rather, the selection usually (i.e. for many of X11 clients, again back then) actualizes as a text chunk only after middle click was pressed. From that point of view, 1 and 3 are ruled out, because by the time middle click is pressed, text extraction procedure would take the current selection, "def", not the one before (technically speaking X11 client can ask for an older selection, but I think no program implements that).

      Personally, I find #2 the most logical but least useful, and #4 the most annoying, because it takes into account text cursor position, not mouse position. I think that #3 is the best way to go.

    Re: X11 pasting
    by duelafn (Parson) on Dec 30, 2009 at 17:19 UTC
    Re: X11 pasting
    by Sewi (Friar) on Jan 04, 2010 at 12:24 UTC
      Thank you all for helping on this issue.

      Padre is using #3 (use the previous selection if the current selection would be replaced by itself) as default now and could be to use the current and not the last selection.

      You could try it out on the current svn trunk and it will be in the next release (0.54) coming soon to CPAN and on the Padre download page.