"snoozing" with notmuch?
[notmuch-archives.git] / 0b / 5a471d7a46c43fe5872920231caceab13d2814
1 Return-Path: <too@guru-group.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 5C676431FBF\r
6         for <notmuch@notmuchmail.org>; Wed,  7 May 2014 14:24:50 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id llgTAAKsAXcL for <notmuch@notmuchmail.org>;\r
16         Wed,  7 May 2014 14:24:44 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 92F60431FAE\r
19         for <notmuch@notmuchmail.org>; Wed,  7 May 2014 14:24:44 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 2DD0D1000F2; Thu,  8 May 2014 00:24:40 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH] devel: make man-to-mdwn.pl to work with generated manual\r
25  pages\r
26 Date: Thu,  8 May 2014 00:24:39 +0300\r
27 Message-Id: <1399497879-27392-1-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 1.8.0\r
29 Cc: tomi.ollila@iki.fi\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.13\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Wed, 07 May 2014 21:24:50 -0000\r
43 \r
44 The new manual pages converted from rst using sphinx or rst2man\r
45 has somewhat different syntax. man-to-mdwn.pl is now adjusted\r
46 to produce even better output from this syntax (a bug ot two\r
47 was fixed along the adjustents done).\r
48 This tool still produces better results than just using the\r
49 html pages generated using sphinx / rst2html. For example those\r
50 tools don't create inter-page hyperlinks -- and the preformatted\r
51 pages written by man-to-mdwn.pl just works well with manual page\r
52 content.\r
53 ---\r
54 \r
55 With the notmuch-wiki commit b2e421fc7 (Thu May 8 00:12:05 2014 +0300)\r
56 the manpages* content is generated by this tool on scientific linux 6.2\r
57 machine and no manual post-editing was done.\r
58 \r
59  devel/man-to-mdwn.pl | 33 ++++++++++++++++-----------------\r
60  1 file changed, 16 insertions(+), 17 deletions(-)\r
61 \r
62 diff --git a/devel/man-to-mdwn.pl b/devel/man-to-mdwn.pl\r
63 index 4b59bd663698..64e6202ae970 100755\r
64 --- a/devel/man-to-mdwn.pl\r
65 +++ b/devel/man-to-mdwn.pl\r
66 @@ -6,18 +6,18 @@\r
67  # This program is used to generate mdwn-formatted notmuch manual pages\r
68  # for notmuch wiki. Example run:\r
69  #\r
70 -# $ ./devel/man-to-mdwn.pl man ../notmuch-wiki\r
71 +# $ ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki\r
72  #\r
73  # In case taken into more generic use, modify these comments and examples.\r
74  \r
75 -use 5.8.1;\r
76 +use 5.10.1;\r
77  use strict;\r
78  use warnings;\r
79  \r
80  unless (@ARGV == 2) {\r
81      warn "\n$0 <source-directory> <destination-directory>\n\n";\r
82      # Remove/edit this comment if this script is taken into generic use.\r
83 -    warn "Example: ./devel/man-to-mdwn.pl man ../notmuch-wiki\n\n";\r
84 +    warn "Example: ./devel/man-to-mdwn.pl doc/_build/man ../notmuch-wiki\n\n";\r
85      exit 1;\r
86  }\r
87  \r
88 @@ -48,11 +48,6 @@ while (<P>)\r
89  }\r
90  close P;\r
91  \r
92 -#undef $ENV{'GROFF_NO_SGR'};\r
93 -#delete $ENV{'GROFF_NO_SGR'};\r
94 -$ENV{'GROFF_NO_SGR'} = '1';\r
95 -$ENV{'TERM'} = 'vt100'; # does this matter ?\r
96 -\r
97  my %htmlqh = qw/& &amp;   < &lt;   > &gt;   ' &apos;   " &quot;/;\r
98  # do html quotation to $_[0] (which is an alias to the given arg)\r
99  sub htmlquote($)\r
100 @@ -70,8 +65,10 @@ while (my ($k, $v) = each %fhash)\r
101      #next if -l $v; # skip symlinks here. -- not... references there may be.\r
102  \r
103      my @lines;\r
104 -    #open I, '-|', qw/groff -man -T utf8/, $v;\r
105 -    open I, '-|', qw/groff -man -T latin1/, $v; # this and GROFF_NO_SGR='1'\r
106 +    open I, '-|', qw/env -i/, "PATH=$ENV{PATH}",\r
107 +       qw/GROFF_NO_SGR=1 TERM=vt100 LANG=en_US.utf8 LC_ALL=en_US.utf8/,\r
108 +       qw/man/, $v;\r
109 +       #qw/man -t -E utf8 -T utf8/, $v; # <- needs newer man...\r
110  \r
111      my ($emptyline, $pre, $hl) = (0, 0, 'h1');\r
112      while (<I>) {\r
113 @@ -79,13 +76,15 @@ while (my ($k, $v) = each %fhash)\r
114             $emptyline = 1;\r
115             next;\r
116         }\r
117 -       s/(?<=\S)\s{8,}.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//;\r
118 -       htmlquote $_;\r
119 +       # keep only leftmost in lines like 'NOTMUCH(1)   notmuch   NOTMUCH(1)'\r
120 +       s/\S\K\s{8,}\S.+\s{8,}\S.*//; # $hl = 'h1' if s/(?<=\S)\s{8,}.*//;\r
121         s/[_&]\010&/&/g;\r
122 -       s/((?:_\010[^_])+)/<u>$1<\/u>/g;\r
123 +       s/((?:_\010[^_])+)/\001u\002$1\001\/u\002/g;\r
124         s/_\010(.)/$1/g;\r
125 -       s/((?:.\010.)+)/<b>$1<\/b>/g;\r
126 +       s/((?:.\010.)+)/\001b\002$1\001\/b\002/g;\r
127         s/.\010(.)/$1/g;\r
128 +       htmlquote $_;\r
129 +       s/\001/</g; s/\002/>/g;\r
130  \r
131         if (/^\S/) {\r
132             $pre = 0, push @lines, "</pre>\n" if $pre;\r
133 @@ -116,7 +115,7 @@ while (my ($k, $v) = each %fhash)\r
134      my $pe = '';\r
135      foreach (@lines) {\r
136         if ($pe) {\r
137 -           if (s/^(\s+)<b>([^<]+)<\/b>\((\d+)\)//) {\r
138 +           if (s/^(\s+)<b>([^<]+)\((\d+)\)<\/b>//) {\r
139                 my $link = maymakelink "$pe-$2-$3";\r
140                 $link = maymakelink "$pe$2-$3" unless $link;\r
141                 if ($link) {\r
142 @@ -132,7 +131,7 @@ while (my ($k, $v) = each %fhash)\r
143             }\r
144             $pe = '';\r
145         }\r
146 -       s/<b>([^<]+)<\/b>\((\d+)\)/mayconvert($1, $2)/ge;\r
147 +       s/<b>([^<]+)\((\d+)\)<\/b>/mayconvert($1, $2)/ge;\r
148         $pe = $1 if s/<b>([^<]+)-<\/b>\s*$//;\r
149         print $_;\r
150      }\r
151 @@ -169,7 +168,7 @@ foreach (sort srt values %fhash)\r
152      open I, '<', $in or die $!;\r
153      my $s;\r
154      while (<I>) {\r
155 -       if (/^\s*[.]TH\s+\S+\s+(\S+)/) {\r
156 +       if (/^\s*[.]TH\s+\S+\s+"?(\S+?)"?\s/) {\r
157             $s = $1;\r
158             last;\r
159         }\r
160 -- \r
161 1.8.0\r
162 \r