From: Brendan Cully Date: Sun, 4 Mar 2007 02:47:41 +0000 (-0800) Subject: Add $wrap, which supersedes $wrapmargin. X-Git-Tag: mutt-1-5-15-rel~47^2~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26b5e1a5232046ebc941a54993ab13904f3af6c2;p=mutt Add $wrap, which supersedes $wrapmargin. When set to a positive number, wrap at that column. When set to a negative number, keep that many characters empty on the right. --- diff --git a/ChangeLog b/ChangeLog index c6d0726b..ae755713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-03-03 18:47 -0800 Brendan Cully (f23dba931c3f) + + * UPDATING, copy.c, globals.h, handler.c, init.c, init.h, + mutt_curses.h, pager.c: Add $wrap, which supersedes $wrapmargin. + When set to a positive number, wrap at that column. When set to a + negative number, keep that many characters empty on the right. + +2007-03-03 00:35 -0800 Brendan Cully (3e3d3bf73c9f) + + * ChangeLog, hg-changelog-map, hg-commit: Use hg-commit to perform + commits that also update the ChangeLog. + 2007-03-03 00:34 -0800 Brendan Cully (03596c38dd53) * hg-commit: Use hg-commit to perform commits that also update the diff --git a/UPDATING b/UPDATING index fa20cff2..944f8b65 100644 --- a/UPDATING +++ b/UPDATING @@ -4,6 +4,7 @@ mutt. Please read this file carefully when upgrading your installation. The keys used are: !: modified feature, -: deleted feature, +: new feature + + $wrap (>0 wraps at $wrap, <0 = $wrapmargin) + $assumed_charset, $attach_charset, $ignore_linear_white_space + $save_history, $history_file (save history across sessions) + $smtp_url (ESMTP relay support) diff --git a/copy.c b/copy.c index 114b99c4..e459a554 100644 --- a/copy.c +++ b/copy.c @@ -281,7 +281,7 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags, if (flags & (CH_DECODE|CH_PREFIX)) { if (mutt_write_one_header (out, 0, headers[x], - flags & CH_PREFIX ? prefix : 0, COLS - WrapMargin) == -1) + flags & CH_PREFIX ? prefix : 0, mutt_term_width (Wrap)) == -1) { error = TRUE; break; diff --git a/globals.h b/globals.h index 85ae034b..0d025dfe 100644 --- a/globals.h +++ b/globals.h @@ -200,7 +200,7 @@ WHERE short SaveHist; WHERE short SendmailWait; WHERE short SleepTime INITVAL (1); WHERE short Timeout; -WHERE short WrapMargin; +WHERE short Wrap; WHERE short WriteInc; WHERE short ScoreThresholdDelete; diff --git a/handler.c b/handler.c index deea6531..6d7048b5 100644 --- a/handler.c +++ b/handler.c @@ -994,12 +994,10 @@ static int text_plain_flowed_handler (BODY *a, STATE *s) if (s->prefix) add = 1; - if ((flowed_max = FLOWED_MAX) > COLS - 3) - flowed_max = COLS - 3; - if (flowed_max > COLS - WrapMargin) - flowed_max = COLS - WrapMargin; - if (flowed_max <= 0) - flowed_max = COLS; + if ((flowed_max = FLOWED_MAX) > mutt_term_width (0) - 3) + flowed_max = mutt_term_width (0) - 3; + if (flowed_max > mutt_term_width (Wrap)) + flowed_max = mutt_term_width (Wrap); while (bytes > 0 && fgets (line, sizeof (line), s->fpin)) diff --git a/init.c b/init.c index ce69d166..0008ab7f 100644 --- a/init.c +++ b/init.c @@ -1974,8 +1974,13 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) if (query || *s->dptr != '=') { + val = *ptr; + /* compatibility alias */ + if (mutt_strcmp (MuttVars[idx].option, "wrapmargin") == 0) + val = *ptr < 0 ? -*ptr : 0; + /* user requested the value of this variable */ - snprintf (err->data, err->dsize, "%s=%d", MuttVars[idx].option, *ptr); + snprintf (err->data, err->dsize, "%s=%d", MuttVars[idx].option, val); break; } @@ -2006,6 +2011,13 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) if (*ptr < 0) *ptr = 0; } + else if (mutt_strcmp (MuttVars[idx].option, "wrapmargin") == 0) + { + if (*ptr < 0) + *ptr = 0; + else + *ptr = -*ptr; + } } else if (DTYPE (MuttVars[idx].type) == DT_QUAD) { @@ -2547,7 +2559,15 @@ static int var_to_string (int idx, char* val, size_t len) else if (DTYPE (MuttVars[idx].type) == DT_QUAD) strfcpy (tmp, vals[quadoption (MuttVars[idx].data)], sizeof (tmp)); else if (DTYPE (MuttVars[idx].type) == DT_NUM) - snprintf (tmp, sizeof (tmp), "%d", (*((short *) MuttVars[idx].data))); + { + short sval = *((short *) MuttVars[idx].data); + + /* avert your eyes, gentle reader */ + if (mutt_strcmp (MuttVars[idx].option, "wrapmargin") == 0) + sval = sval > 0 ? 0 : -sval; + + snprintf (tmp, sizeof (tmp), "%d", sval); + } else if (DTYPE (MuttVars[idx].type) == DT_SORT) { const struct mapping_t *map; diff --git a/init.h b/init.h index 71db9659..109fa2f5 100644 --- a/init.h +++ b/init.h @@ -2997,6 +2997,13 @@ struct option_t MuttVars[] = { ** When set, mutt will weed headers when displaying, forwarding, ** printing, or replying to messages. */ + { "wrap", DT_NUM, R_PAGER, UL &Wrap, 0 }, + /* + ** .pp + ** When set to a positive value, mutt will wrap text at $$wrap characters. + ** When set to a negative value, mutt will wrap text so that there are $$wrap + ** characters of empty space on the right side of the terminal. + */ { "wrap_search", DT_BOOL, R_NONE, OPTWRAPSEARCH, 1 }, /* ** .pp @@ -3005,11 +3012,10 @@ struct option_t MuttVars[] = { ** When set, searches will wrap around the first (or last) message. When ** unset, searches will not wrap. */ - { "wrapmargin", DT_NUM, R_PAGER, UL &WrapMargin, 0 }, + { "wrapmargin", DT_NUM, R_PAGER, UL &Wrap, 0 }, /* ** .pp - ** Controls the size of the margin remaining at the right side of - ** the terminal when mutt's pager does smart wrapping. + ** (DEPRECATED) Equivalent to setting $wrap with a negative value. */ { "write_inc", DT_NUM, R_NONE, UL &WriteInc, 10 }, /* diff --git a/mutt_curses.h b/mutt_curses.h index 94c1a69b..536f8a35 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -159,6 +159,16 @@ void mutt_progress_init (progress_t* progress, const char *msg, long size); void mutt_progress_update (progress_t* progress, long pos); +static inline int mutt_term_width(short wrap) +{ + if (wrap < 0) + return COLS > -wrap ? COLS + wrap : COLS; + else if (wrap) + return wrap < COLS ? wrap : COLS; + else + return COLS; +} + extern int *ColorQuote; extern int ColorQuoteUsed; extern int ColorDefs[]; diff --git a/pager.c b/pager.c index 0a1009e7..533339d5 100644 --- a/pager.c +++ b/pager.c @@ -1066,10 +1066,7 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf, wchar_t wc; mbstate_t mbstate; - int wrap_cols = COLS - WrapMargin; - - if (wrap_cols <= 0) - wrap_cols = COLS; + int wrap_cols = mutt_term_width (Wrap); /* FIXME: this should come from lineInfo */ memset(&mbstate, 0, sizeof(mbstate));