From owner-freebsd-current@FreeBSD.ORG Mon Nov 25 12:54:51 2013 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 900086EB for ; Mon, 25 Nov 2013 12:54:51 +0000 (UTC) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3lp0081.outbound.protection.outlook.com [213.199.154.81]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0D1D22747 for ; Mon, 25 Nov 2013 12:54:50 +0000 (UTC) Received: from ul9n (199.102.77.238) by DB3PR06MB172.eurprd06.prod.outlook.com (10.141.1.151) with Microsoft SMTP Server (TLS) id 15.0.800.7; Mon, 25 Nov 2013 12:54:42 +0000 Date: Mon, 25 Nov 2013 12:54:31 +0000 From: Anthony Perkins To: Subject: Patch: Add option to fmt to ignore email reply lines Message-ID: <20131125125430.GC67451@ul9n> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline User-Agent: Mutt/1.5.22 (2013-10-16) X-Originating-IP: [199.102.77.238] X-ClientProxiedBy: BL2PR03CA001.namprd03.prod.outlook.com (10.255.109.18) To DB3PR06MB172.eurprd06.prod.outlook.com (10.141.1.151) X-Forefront-PRVS: 0041D46242 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(199002)(189002)(66654002)(56776001)(81686001)(568964001)(54316002)(47446002)(80976001)(63696002)(69226001)(56816003)(77096001)(74366001)(33716001)(87266001)(33656001)(512954002)(79102001)(76796001)(74502001)(74662001)(31966008)(76786001)(81816001)(71186001)(81342001)(83506001)(76176001)(46102001)(51856001)(66066001)(54356001)(42186004)(53806001)(74876001)(80022001)(74706001)(50986001)(49866001)(47736001)(81542001)(65816001)(47976001)(84326002)(85306002)(4396001)(59766001)(87976001)(83072001)(76482001)(83322001)(77982001)(19580395003); DIR:OUT; SFP:; SCL:1; SRVR:DB3PR06MB172; H:ul9n; CLIP:199.102.77.238; FPR:; RD:InfoNoRecords; A:0; MX:1; LANG:en; X-OriginatorOrg: acperkins.com X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 12:54:51 -0000 --LQksG6bCIzRHxTLp Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline I've added an option to 'fmt' to ignore lines beginning with the greater-than symbol, so that whole email replies can be piped through fmt (e.g. via vi from mutt) without needing to repeat the command for each of my paragraphs. This is my first real patch, so I would appreciate any feedback. Many thanks, Anthony --LQksG6bCIzRHxTLp Content-Type: text/x-diff; charset="us-ascii" Content-Disposition: attachment; filename="ignore-email-replies.diff" Index: fmt.1 =================================================================== --- fmt.1 (revision 258550) +++ fmt.1 (working copy) @@ -99,6 +99,10 @@ .Fl p flag, any change in the amount of whitespace at the start of a line results in a new paragraph being begun. +.It Fl r +Ignore lines beginning with a +.Ql \&> +(greater-than) character, marking email replies. .It Fl s Collapse whitespace inside lines, so that multiple whitespace characters are turned into a single space. Index: fmt.c =================================================================== --- fmt.c (revision 258550) +++ fmt.c (working copy) @@ -227,6 +227,7 @@ static const wchar_t *sentence_enders=L".?!"; /* Double-space after these */ static int grok_mail_headers=0; /* treat embedded mail headers magically? */ static int format_troff=0; /* Format troff? */ +static int format_email_replies=1; /* Format email replies? */ static int n_errors=0; /* Number of failed files. Return on exit. */ static wchar_t *output_buffer=0; /* Output line will be built here */ @@ -266,7 +267,7 @@ /* 1. Grok parameters. */ - while ((ch = getopt(argc, argv, "0123456789cd:hl:mnpst:w:")) != -1) + while ((ch = getopt(argc, argv, "0123456789cd:hl:mnprst:w:")) != -1) switch(ch) { case 'c': centerP = 1; @@ -294,6 +295,9 @@ case 'p': allow_indented_paragraphs = 1; continue; + case 'r': + format_email_replies = 0; + continue; case 's': coalesce_spaces_P = 1; continue; @@ -328,6 +332,7 @@ " -m try to make sure mail header lines stay separate\n" " -n format lines beginning with a dot\n" " -p allow indented paragraphs\n" +" -r ignore lines beginning with a greater-than sign\n" " -s coalesce whitespace inside lines\n" " -t have tabs every columns\n" " -w set maximum width to \n" @@ -419,6 +424,7 @@ /* We need a new paragraph if and only if: * this line is blank, * OR it's a troff request (and we don't format troff), + * OR it's not an email reply, prefixed with ">" * OR it's a mail header, * OR it's not a mail header AND the last line was one, * OR the indentation has changed @@ -427,6 +433,7 @@ */ if ( length==0 || (line[0]=='.' && !format_troff) + || (line[0]=='>' && !format_email_replies) || header_type==hdr_Header || (header_type==hdr_NonHeader && prev_header_type>hdr_NonHeader) || (np!=last_indent @@ -437,7 +444,8 @@ first_indent = np; last_indent = np; if (header_type==hdr_Header) last_indent=2; /* for cont. lines */ - if (length==0 || (line[0]=='.' && !format_troff)) { + if (length==0 || (line[0]=='.' && !format_troff) || + (line[0]=='>' && !format_email_replies)) { if (length==0) putwchar('\n'); else --LQksG6bCIzRHxTLp--