<<< Date Index >>>     <<< Thread Index >>>

Re: [Patch] Add ability to specify the column when to wrap long lines



Hi there,

On Thu, 05 May 2005, 20:21:33 +0200, Manfred Hollstein wrote:
> On Thu, 05 May 2005, 20:04:11 +0200, David Champion wrote:
> > * On 2005.05.05, in <20050505164132.GB7242@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> > *   "Manfred Hollstein" <mh@xxxxxxxxxx> wrote:
> > > 
> > > The patch for this incl. the documentation is attached. I'd appreciate
> > > if it can be approved and applied by someone.
> > 
> > This seems like a reasonable thing for mutt to be capable of, but I'd
> > rather see wrapmargin and wrapcolumn combined -- e.g., if $wrapcolumn
> > is positive, wrap at that column, if negative, wrap at that offset from
> > the width of the terminal.  This is fairly typical behavior for screen
> > layout engines, so it should be generally understood.
> > 
> > Could wrapcolumn be adapted to do that, and wrapmargin be phased out in
> > a later release?  Internally wrapmargin could translate to wrapcolumn.
> 
> Sure, that's even better. I didn't want to touch wrapmargin, because I
> didn't know how widely it is actually used. I'll work on a patch and post
> it to the list.

The attached patch does exactly this. I also added some code to warn the
user about the fact, that wrapmargin will go away in future releases of
mutt, and which maps actual uses of wrapmargin onto their equivalent
using wrapcolumn.

Feedback?

Cheers.

l8er
manfred
2005-05-09 12:27:44  Manfred Hollstein  <mh@xxxxxxxxxx>

        * globals.h (WrapColumn): Add new global variable.
        * init.h (MuttVars): Likewise.
        * init.c (mutt_init): Add warning message about deprecation of
        wrapmargin variable in favour of new wrapcolumn. Map uses of
        wrapmargin onto corresponding settings for wrapcolumn.
        * handler.c (text_enriched_handler): Initialize .WrapMargin field
        under consideration of the new variable WrapColumn.
        (text_plain_flowed_handler): Likewise for flowed_max.
        * pager.c (format_line): Likewise for wrap_cols.
        * Muttrc, doc/manual.sgml: Add documentation for new variable.
        * doc/manual*.html, doc/manual.txt, doc/muttrc.man: Regenerate.

diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/Muttrc mutt-1.5.9/Muttrc
--- mutt-1.5.9.orig/Muttrc      2005-03-13 17:37:11.000000000 +0100
+++ mutt-1.5.9/Muttrc   2005-05-09 11:49:47.400244841 +0200
@@ -3963,6 +3963,21 @@ macro pager   <f1> "!less /usr/local/doc
 # unset, searches will not wrap.
 # 
 # 
+# set wrapcolumn=0
+#
+# Name: wrapcolumn
+# Type: number
+# Default: 0
+# 
+# 
+# Controls at which column mutt's pager does smart wrapping. If
+# set to 0, no smart wrapping is done. If set to a negative value,
+# mutt's pager wraps at screen width - absolute value (wrapcolumn);
+# if set to a positive value, it'll wrap at that column. If the
+# absolute value of wrapcolumn is larger than what the current
+# display can handle, this value is ignored.
+# 
+# 
 # set wrapmargin=0
 #
 # Name: wrapmargin
@@ -3972,6 +3987,8 @@ macro pager   <f1> "!less /usr/local/doc
 # 
 # Controls the size of the margin remaining at the right side of
 # the terminal when mutt's pager does smart wrapping.
+#
+# Note, this variable will be replaced by wrapcolumn in future releases.
 # 
 # 
 # set write_inc=10
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/doc/manual.sgml mutt-1.5.9/doc/manual.sgml
--- mutt-1.5.9.orig/doc/manual.sgml     2005-03-13 17:37:11.000000000 +0100
+++ mutt-1.5.9/doc/manual.sgml  2005-05-09 11:49:47.406243212 +0200
@@ -6916,6 +6916,20 @@ When set, searches will wrap around the 
 unset, searches will not wrap.
 
 
+<sect2>wrapcolumn<label id="wrapcolumn">
+<p>
+Type: number<newline>
+Default: 0
+
+<p>
+Controls at which column mutt's pager does smart wrapping. If
+set to 0, no smart wrapping is done. If set to a negative value,
+mutt's pager wraps at screen width - absolute value (wrapcolumn);
+if set to a positive value, it'll wrap at that column. If the
+absolute value of wrapcolumn is larger than what the current
+display can handle, this value is ignored.
+
+
 <sect2>wrapmargin<label id="wrapmargin">
 <p>
 Type: number<newline>
@@ -6924,6 +6938,8 @@ Default: 0
 <p>
 Controls the size of the margin remaining at the right side of
 the terminal when mutt's pager does smart wrapping.
+<p>
+Note, wrapmargin will be replaced by wrapcolumn in future releases.
 
 
 <sect2>write&lowbar;inc<label id="write_inc">
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/doc/manual-6.html 
mutt-1.5.9/doc/manual-6.html
--- mutt-1.5.9.orig/doc/manual-6.html   2005-03-13 17:37:24.000000000 +0100
+++ mutt-1.5.9/doc/manual-6.html        2005-05-09 12:25:16.856459698 +0200
@@ -3680,6 +3680,19 @@ Default: yes</P>
 unset, searches will not wrap.</P>
 
 
+<H3><A NAME="wrapcolumn"></A> wrapcolumn</H3>
+
+<P>Type: number<BR>
+Default: 0</P>
+
+<P>Controls at which column mutt's pager does smart wrapping. If
+set to 0, no smart wrapping is done. If set to a negative value,
+mutt's pager wraps at screen width - absolute value (wrapcolumn);
+if set to a positive value, it'll wrap at that column. If the
+absolute value of wrapcolumn is larger than what the current
+display can handle, this value is ignored.</P>
+
+
 <H3><A NAME="wrapmargin"></A> wrapmargin</H3>
 
 <P>Type: number<BR>
@@ -3687,6 +3700,7 @@ Default: 0</P>
 
 <P>Controls the size of the margin remaining at the right side of
 the terminal when mutt's pager does smart wrapping.</P>
+<P>Note, wrapmargin will be replaced by wrapcolumn in future releases.</P>
 
 
 <H3><A NAME="write_inc"></A> write_inc</H3>
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/doc/manual.txt mutt-1.5.9/doc/manual.txt
--- mutt-1.5.9.orig/doc/manual.txt      2005-03-13 17:37:17.000000000 +0100
+++ mutt-1.5.9/doc/manual.txt   2005-05-09 12:21:46.009628537 +0200
@@ -379,9 +379,10 @@
         6.3.274 wait_key
         6.3.275 weed
         6.3.276 wrap_search
-        6.3.277 wrapmargin
-        6.3.278 write_inc
-        6.3.279 write_bcc
+        6.3.277 wrapcolumn
+        6.3.278 wrapmargin
+        6.3.279 write_inc
+        6.3.280 write_bcc
      6.4 Functions
         6.4.1 generic
         6.4.2 index
@@ -6645,7 +6646,19 @@
   When set, searches will wrap around the first (or last) message. When
   unset, searches will not wrap.
 
-  66..33..227777..  wwrraappmmaarrggiinn
+  66..33..227777..  wwrraappccoolluummnn
+
+  Type: number
+  Default: 0
+
+  Controls at which column mutt's pager does smart wrapping. If set to
+  0, no smart wrapping is done. If set to a negative value, mutt's pager
+  wraps at screen width - absolute value (wrapcolumn); if set to a
+  positive value, it'll wrap at that column. If the absolute value of
+  wrapcolumn is larger than what the current display can handle, this
+  value is ignored.
+
+  66..33..227788..  wwrraappmmaarrggiinn
 
   Type: number
   Default: 0
@@ -6653,7 +6666,9 @@
   Controls the size of the margin remaining at the right side of the
   terminal when mutt's pager does smart wrapping.
 
-  66..33..227788..  wwrriittee__iinncc
+  Note, wrapmargin will be replaced by wrapcolumn in future releases.
+
+  66..33..227799..  wwrriittee__iinncc
 
   Type: number
   Default: 10
@@ -6664,7 +6679,7 @@
 
   Also see the ````$read_inc'''' variable.
 
-  66..33..227799..  wwrriittee__bbcccc
+  66..33..228800..  wwrriittee__bbcccc
 
   Type: boolean
   Default: yes
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/doc/muttrc.man mutt-1.5.9/doc/muttrc.man
--- mutt-1.5.9.orig/doc/muttrc.man      2005-03-13 17:37:11.000000000 +0100
+++ mutt-1.5.9/doc/muttrc.man   2005-05-09 12:07:38.159865587 +0200
@@ -4779,6 +4779,21 @@ unset, searches will not wrap.
 
 
 .TP
+.B wrapcolumn
+.nf
+Type: number
+Default: 0
+.fi
+.IP
+Controls at which column mutt's pager does smart wrapping. If
+set to 0, no smart wrapping is done. If set to a negative value,
+mutt's pager wraps at screen width - absolute value (wrapcolumn);
+if set to a positive value, it'll wrap at that column. If the
+absolute value of wrapcolumn is larger than what the current
+display can handle, this value is ignored.
+
+
+.TP
 .B wrapmargin
 .nf
 Type: number
@@ -4787,6 +4802,8 @@ Default: 0
 .IP
 Controls the size of the margin remaining at the right side of
 the terminal when mutt's pager does smart wrapping.
+.IP
+Note, wrapmargin will be replaced by wrapcolumn in future releases.
 
 
 .TP
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/globals.h mutt-1.5.9/globals.h
--- mutt-1.5.9.orig/globals.h   2005-02-12 21:01:02.000000000 +0100
+++ mutt-1.5.9/globals.h        2005-05-09 11:49:47.407242940 +0200
@@ -172,6 +172,7 @@ WHERE short ReadInc;
 WHERE short SendmailWait;
 WHERE short SleepTime INITVAL (1);
 WHERE short Timeout;
+WHERE short WrapColumn;
 WHERE short WrapMargin;
 WHERE short WriteInc;
 
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/handler.c mutt-1.5.9/handler.c
--- mutt-1.5.9.orig/handler.c   2005-02-03 19:47:52.000000000 +0100
+++ mutt-1.5.9/handler.c        2005-05-09 11:49:47.409242397 +0200
@@ -781,7 +781,12 @@ void text_enriched_handler (BODY *a, STA
 
   memset (&stte, 0, sizeof (stte));
   stte.s = s;
-  stte.WrapMargin = ((s->flags & M_DISPLAY) ? (COLS-4) : 
((COLS-4)<72)?(COLS-4):72);
+  if (WrapColumn > 0)
+    stte.WrapMargin = ((s->flags & M_DISPLAY) ? (MIN (COLS-4, WrapColumn)) : 
((MIN (COLS-4, WrapColumn))<72)?(MIN (COLS-4, WrapColumn)):72);
+  else if (WrapColumn < 0)
+    stte.WrapMargin = ((s->flags & M_DISPLAY) ? (COLS-WrapColumn) : 
((COLS-WrapColumn)<72)?(COLS-WrapColumn):72);
+  if (WrapColumn == 0 || stte.WrapMargin < 0)
+    stte.WrapMargin = ((s->flags & M_DISPLAY) ? (COLS-4) : 
((COLS-4)<72)?(COLS-4):72);
   stte.line_max = stte.WrapMargin * 4;
   stte.line = (char *) safe_calloc (1, stte.line_max + 1);
   stte.param = (char *) safe_calloc (1, STRING);
@@ -995,8 +1000,15 @@ static void text_plain_flowed_handler (B
   
   if ((flowed_max = FLOWED_MAX) > COLS - 3)
     flowed_max = COLS - 3;
-  if (flowed_max > COLS - WrapMargin)
-    flowed_max = COLS - WrapMargin;
+  if (WrapColumn > 0)
+  {
+    if (flowed_max > WrapColumn)
+      flowed_max = WrapColumn;
+  }
+  else if (WrapColumn < 0)
+  {
+    flowed_max = COLS + WrapColumn;
+  }
   if (flowed_max <= 0)
     flowed_max = COLS;
     
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/init.c mutt-1.5.9/init.c
--- mutt-1.5.9.orig/init.c      2005-02-12 20:06:16.000000000 +0100
+++ mutt-1.5.9/init.c   2005-05-09 11:49:47.411241854 +0200
@@ -2412,6 +2412,25 @@ void mutt_init (int skip_sys_rc, LIST *c
     exit (1);
   }
 
+  if (WrapMargin != 0)
+  {
+    fputs ("wrapmargin: Usage of this variable is deprecated. It will be 
replaced by\n", stderr);
+    fputs ("  ``wrapcolumn'' in future releases. Please read the documentation 
and change\n", stderr);
+    fputs ("  your muttrc files accordingly.\n", stderr);
+    if (WrapColumn != 0)
+    {
+      fputs ("  You defined both ``wrapmargin'' and ``wrapcolumn'' in your 
muttrc files.\n", stderr);
+      fputs ("  The setting of ``wrapmargin'' will be ignored.\n", stderr);
+    }
+    need_pause = 1;
+
+    if (WrapColumn == 0)       /* Map wrapmargin's settings onto wrapcolumn.  
*/
+      WrapColumn = -WrapMargin;
+    /* Ignore any wrap-points outside of the display's width.  */
+    if (WrapColumn > COLS || -WrapColumn > COLS)
+      WrapColumn = 0;
+  }
+
   if (mutt_execute_commands (commands) != 0)
     need_pause = 1;
 
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/init.h mutt-1.5.9/init.h
--- mutt-1.5.9.orig/init.h      2005-03-01 16:56:02.000000000 +0100
+++ mutt-1.5.9/init.h   2005-05-09 11:49:47.414241039 +0200
@@ -2798,11 +2798,23 @@ struct option_t MuttVars[] = {
   ** When set, searches will wrap around the first (or last) message. When
   ** unset, searches will not wrap.
   */
+  { "wrapcolumn",      DT_NUM,  R_PAGER, UL &WrapColumn, 0 },
+  /*
+  ** .pp
+  ** Controls at which column mutt's pager does smart wrapping. If
+  ** set to 0, no smart wrapping is done. If set to a negative value,
+  ** mutt's pager wraps at screen width - absolute value (wrapcolumn);
+  ** if set to a positive value, it'll wrap at that column. If the
+  ** absolute value of wrapcolumn is larger than what the current
+  ** display can handle, this value is ignored.
+  */
   { "wrapmargin",      DT_NUM,  R_PAGER, UL &WrapMargin, 0 },
   /*
   ** .pp
   ** Controls the size of the margin remaining at the right side of
   ** the terminal when mutt's pager does smart wrapping.
+  ** .pp
+  ** Note, wrapmargin will be replaced by wrapcolumn in future releases.
   */
   { "write_inc",       DT_NUM,  R_NONE, UL &WriteInc, 10 },
   /*
diff -rup -x CVS -x RCS -x '*.o' -x '*.info*' -x '*.elc' -x '*.dvi' -x '*.orig' 
-x '*~' -x version.el mutt-1.5.9.orig/pager.c mutt-1.5.9/pager.c
--- mutt-1.5.9.orig/pager.c     2005-02-12 20:30:16.000000000 +0100
+++ mutt-1.5.9/pager.c  2005-05-09 12:01:40.077652297 +0200
@@ -1035,8 +1035,12 @@ static int format_line (struct line_t **
   int ch, vch, k, last_special = -1, special = 0, t;
   wchar_t wc;
   mbstate_t mbstate;
-
-  int wrap_cols = COLS - WrapMargin;
+  int wrap_cols;
+  
+  if (WrapColumn <= 0)
+    wrap_cols = COLS + WrapColumn;
+  else if (WrapColumn > 0)
+    wrap_cols = MIN (WrapColumn, COLS);
   
   if (wrap_cols <= 0)
     wrap_cols = COLS;