25
23
'a|all' => \$display_all,
26
24
'e|edit' => \$mode_edit,
27
25
'h|headers' => \$display_headers,
28
's|section=s' => \$display_section,
26
'section=s' => \$display_section,
29
27
'help' => \$mode_help,
30
28
'version' => \$mode_version,
32
30
print "Try `$app_name --help' for more information.\n";
38
36
print "todo - display your todo file\n\n".
39
#01234567890123456789012345678901234567890123456789012345678901234567890123456789
40
37
"Usage: $app_name [OPTIONS]\n\n".
42
39
" -a, --all display all sections\n".
43
40
" -e, --edit edit your todo file\n".
44
41
" -h, --headers show setion headers\n".
45
" -s, --section=SECTION display sections matching the regular expression\n".
42
" -s, --section=SECTION display this named section\n".
46
43
" --help display this help and exit\n".
47
" --version output version information and exit\n".
49
"Running without any options is the same as running with --section=TODO and\n".
50
"lists the default section of the todo file.\n".
52
"The environment variables EDITOR is used.\n".
54
"Please report bugs to Tim Marston <tim\@ed.am>.\n";
44
" --version output version information and exit\n";
59
49
if( $mode_version ) {
60
50
print "todo 1.0\n".
61
"Copyright (C) 2011, 2012 Tim Marston.\n".
51
"Copyright (C) 2011 Tim Marston.\n".
62
52
"http://ed.am/software/todo\n";
112
102
# determine editor from environment, default to "emacs -nw"
114
$editor = $ENV{ 'EDITOR' };
115
defined $editor or $editor = 'emacs -nw';
103
my $editor = $ENV{ 'EDITOR' };
104
defined $editor or $editor = 'emacs -nw';
116
105
my @exec_array = split( / +/, $editor );
117
106
push( @exec_array, "$todo_dir/todo" );
141
# function to display a line
144
my ( $line, $section ) = @_;
145
state $old_section = '';
147
# detect section change
148
if( $section ne $old_section ) {
149
$old_section = $section;
151
# display section heading
152
if( $display_headers || $display_all ) {
154
( "=" x length( $section ) )."\n";
158
# replace tabs with 4 spaces
166
130
# scan through file
167
my $candidate_section = '';
131
my $next_section = '';
168
132
my $section = '';
133
my $old_section = '';
170
134
open FILE, "<$todo_dir/todo" or die "can't open todo file";
173
138
# detect the line after section headings, and thus sections
174
if( /^[-=]{2,}/ && $candidate_section ne '' ) {
175
$section = $candidate_section;
176
$candidate_section = '';
139
if( /^[-=]{2,}/ && $next_section ne '' ) {
140
$section = $next_section;
181
143
# detect section headings
182
if( /^[-_\.A-Za-z0-9 ]+$/ ) {
183
$candidate_section = $_;
184
chomp $candidate_section;
144
elsif( /^[A-Z]+$/ ) {
146
chomp( $next_section );
148
# we have neither a section heading nor the line after
187
$candidate_section = '';
191
display_line( $last_line, $section ) if( $last_line ne '' );
194
if( ( lc( $section ) eq lc( $display_section ) ) ||
195
( $section && $display_all ) )
153
if( ( $section eq $display_section ) ||
154
( $section && $display_all ) )
156
# detect section change
157
if( $section ne $old_section ) {
158
$old_section = $section;
160
# display section heading
161
if( $display_headers ||
165
( "=" x length( $section ) )."\n";
169
# replace tabs with 4 spaces
203
display_line( $last_line, $section ) if( $last_line ne '' );