deadpixi / sam

An updated version of the sam text editor.
Other
433 stars 47 forks source link

Cannot transfer text between two instances of sam #62

Closed siebenmann closed 6 years ago

siebenmann commented 7 years ago

Suppose that you are running two copies of sam (perhaps on different machines) and you want to transfer some text from a file in one to a file in the other. In theory you should be able to snarf the text in the source sam, <exch> to make it the X selection, <exch> in the target sam to import the X selection, and then paste it. In practice this doesn't work; the target sam winds up with nothing from its <exch> operation. It does work if I use xterm running cat >/dev/null as an intermediate.

This may be related to #61, since both involve <exch>.

In attempting to look at the code with very little knowledge of how X selection things work, I noticed that libXg/gwin.c's SelectSwap() appears to set the selection as a UTF8_STRING, but SendSel() returns false unless it is being asked for an XA_STRING. Some instrumentation suggests that when another sam asks for the selection, SendSel() is usually called with a UTF8_STRING Atom as the *target value. In the current code, it will thus fail. Hacking it up to accept UTF8_STRING as well appears to make things work between two sam processes (although it doesn't fix #61).

ckeen commented 6 years ago

Hm, even this hacky solution is better than the current state of affairs... I will try to recreate this.

ckeen commented 6 years ago
diff --git a/libXg/gwin.c b/libXg/gwin.c
index 4bee554..f8d5a65 100644
--- a/libXg/gwin.c
+++ b/libXg/gwin.c
@@ -491,7 +491,8 @@ SendSel(Widget w, Atom *sel, Atom *target, Atom *rtype, XtPointer *ans,
     XTextProperty p = {0};
     char *ls[2] = {NULL, NULL};

-    if (*target == XA_STRING){
+    if ((*target == XA_STRING) ||
+        (*target == XInternAtom(_dpy, "UTF8_STRING", 0))){
         ls[0] = gw->gwin.selection? gw->gwin.selection : "";
         if (XmbTextListToTextProperty(_dpy, ls, 1, XUTF8StringStyle, &p) != Success)
             return false;

This seems to allow pasting between two instances of sam. What's keeping us from including this?

deadpixi commented 6 years ago

@ckeen Works for me. Can you open a PR?

deadpixi commented 6 years ago

Merged and closing. Thanks!