Now, on selcopy, st generates traditional Unix newlines ('\n'), because
apparently that's what GUI applications are used to see. But some
terminal applications do not handle '\n' very well, so, when pasting to st,
line feeds are replaced with carriage returns, codes that Return key generates.
---
 st.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 93058b9..726b8f9 100644
--- a/st.c
+++ b/st.c
@@ -790,7 +790,7 @@ selcopy(void) {
                        }
                        /* \n at the end of every selected line except for the 
last one */
                        if(is_selected && y < sel.e.y)
-                               *ptr++ = '\r';
+                               *ptr++ = '\n';
                }
                *ptr = 0;
        }
@@ -801,7 +801,7 @@ void
 selnotify(XEvent *e) {
        ulong nitems, ofs, rem;
        int format;
-       uchar *data;
+       uchar *data, *repl, *last;
        Atom type;
 
        ofs = 0;
@@ -812,6 +812,14 @@ selnotify(XEvent *e) {
                        fprintf(stderr, "Clipboard allocation failed\n");
                        return;
                }
+
+               /* Working around inconsistent behaviour of GUI and terminal 
apps */
+               last = data + nitems * format / 8;
+               repl = data;
+               while((repl = memchr(repl, '\n', last - repl))) {
+                       *repl++ = '\r';
+               }
+
                ttywrite((const char *) data, nitems * format / 8);
                XFree(data);
                /* number of 32-bit chunks returned */
-- 
1.7.10.4


Reply via email to