Re: [Patch] Add ability to specify the column when to wrap long lines
* Manfred Hollstein <mh@xxxxxxxxxx> [May 09. 2005 13:46]:
> 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?
Here's a patch for 1.5.10. I think it was agreed upon applying this, or
were there issues?
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.
================================================================================
--- mutt-1.5.10/doc/manual-6.html
+++ mutt-1.5.10/doc/manual-6.html
@@ -3772,6 +3772,19 @@
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>
@@ -3779,6 +3792,7 @@
<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>
--- mutt-1.5.10/doc/manual.sgml
+++ mutt-1.5.10/doc/manual.sgml
@@ -7053,6 +7053,20 @@
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>
@@ -7061,6 +7075,8 @@
<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_inc<label id="write_inc">
--- mutt-1.5.10/doc/manual.txt
+++ mutt-1.5.10/doc/manual.txt
@@ -390,9 +390,10 @@
6.3.282 wait_key
6.3.283 weed
6.3.284 wrap_search
- 6.3.285 wrapmargin
- 6.3.286 write_inc
- 6.3.287 write_bcc
+ 6.3.285 wrapcolumn
+ 6.3.286 wrapmargin
+ 6.3.287 write_inc
+ 6.3.288 write_bcc
6.4 Functions
6.4.1 generic
6.4.2 index
@@ -6769,7 +6770,19 @@
When set, searches will wrap around the first (or last) message. When
unset, searches will not wrap.
- 66..33..228855.. wwrraappmmaarrggiinn
+ 66..33..227857.. 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..228865.. wwrraappmmaarrggiinn
Type: number
Default: 0
@@ -6777,7 +6790,9 @@
Controls the size of the margin remaining at the right side of the
terminal when mutt's pager does smart wrapping.
- 66..33..228866.. wwrriittee__iinncc
+ Note, wrapmargin will be replaced by wrapcolumn in future releases.
+
+ 66..33..228876.. wwrriittee__iinncc
Type: number
Default: 10
@@ -6788,7 +6803,7 @@
Also see the ````$read_inc'''' variable.
- 66..33..228877.. wwrriittee__bbcccc
+ 66..33..228887.. wwrriittee__bbcccc
Type: boolean
Default: yes
--- mutt-1.5.10/doc/muttrc.man
+++ mutt-1.5.10/doc/muttrc.man
@@ -4886,6 +4886,21 @@
.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
@@ -4894,6 +4909,8 @@
.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
--- mutt-1.5.10/globals.h
+++ mutt-1.5.10/globals.h
@@ -175,6 +175,7 @@
WHERE short SendmailWait;
WHERE short SleepTime INITVAL (1);
WHERE short Timeout;
+WHERE short WrapColumn;
WHERE short WrapMargin;
WHERE short WriteInc;
--- mutt-1.5.10/handler.c
+++ mutt-1.5.10/handler.c
@@ -780,7 +780,12 @@
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);
@@ -996,8 +1001,15 @@
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;
--- mutt-1.5.10/init.c
+++ mutt-1.5.10/init.c
@@ -2433,6 +2433,25 @@
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;
--- mutt-1.5.10/init.h
+++ mutt-1.5.10/init.h
@@ -2853,11 +2853,23 @@
** 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 },
/*
--- mutt-1.5.10/Muttrc
+++ mutt-1.5.10/Muttrc
@@ -4070,6 +4070,21 @@
# 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
@@ -4079,6 +4094,8 @@
#
# 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
--- mutt-1.5.10/pager.c
+++ mutt-1.5.10/pager.c
@@ -1061,8 +1061,12 @@
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;
--
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?"
-- A. P. J.