From r_goertz at web.de  Fri Sep  1 10:23:21 2017
From: r_goertz at web.de (Ralf Goertz)
Date: Fri, 1 Sep 2017 10:23:21 +0200
Subject: [Rd] patch: automatically adjust width option when terminal is
 resized
In-Reply-To: <20170828093331.39607d5b@delligoertz.fritz.box>
References: <20170828093331.39607d5b@delligoertz.fritz.box>
Message-ID: <20170901102321.6921e48a@delligoertz.fritz.box>

Am Mon, 28 Aug 2017 09:33:31 +0200
schrieb Ralf Goertz <r_goertz at web.de>:


Hello, me again

> Hi,
> 
> I guess there have been discussions about this in the past and from
> what I understood hooking an R-function to facilitate automatic
> adjustment is problematic. So why not doing it like this:

would anybody care to comment? I think it is quite important to have an
automatic adjustment of R's idea of the width of its terminal window. I
quite often find myself in the situation that I started R in its own
(wide) xterm. Then I look at some data frame or vector like this (using
small width here in order to stay within the ususal width of a text
posting):

> (r=rnorm(20))
 [1]  0.05672115  0.59047528  0.41337747  0.01737960 -0.78133482
 [6]  0.49218494 -0.78793312 -1.26125820  0.56748784  0.65725277
[11] -0.04419487  0.14463142 -0.48613097  0.42789592  1.22424913
[16]  0.43272842 -0.70089673  0.14313221 -0.97159181 -1.29164930


Then I want to plot something

> hist(r)

Because the plot window and the xterm don't fit side by side I resize
the xterm to be smaller. Then I want to see the data again:

> r
 [1]  0.05672115  0.59047528  0.41337747  0.01737960 -
0.78133482
 [6]  0.49218494 -0.78793312 -1.26125820  0.56748784  
0.65725277
[11] -0.04419487  0.14463142 -0.48613097  0.42789592  
1.22424913
[16]  0.43272842 -0.70089673  0.14313221 -0.97159181 -
1.29164930

This is ugly and hard to read. Many good programs like vim adjust their
internal width representation automatically. Why shouldn't R do the
same? It seems quite easy, at least when readline is used:

 
--- R-3.4.1/src/unix/sys-std.c  2017-03-24 00:03:59.000000000 +0100
+++ R-3.4.1/src/unix/sys-std.patched.c  2017-08-28 09:16:02.714204023
+0200 @@ -1005,6 +1005,9 @@
                // introduced in readline 4.0: only used for >= 6.3
 #ifdef HAVE_RL_RESIZE_TERMINAL
                rl_resize_terminal();
+               int rl_height, rl_width;
+               rl_get_screen_size(&rl_height,&rl_width);
+               R_SetOptionWidth(rl_width);
 #endif
             }
 #endif

> I tried it out and it works perfectly here. Of course there should be
> an option to switch this on and off but you get the idea. What do you
> think?

It would be much appreciated if you considered it.

Thanks Ralf



[Rd] patch: automatically adjust width option when terminal is resized
Ralf Goertz