26
23
'a|all' => \$display_all,
27
24
'e|edit' => \$mode_edit,
28
25
'h|headers' => \$display_headers,
29
'l|list' => \$mode_less,
30
's|section=s' => \$display_section,
26
'section=s' => \$display_section,
31
27
'help' => \$mode_help,
32
28
'version' => \$mode_version,
43
39
" -a, --all display all sections\n".
44
40
" -e, --edit edit your todo file\n".
45
41
" -h, --headers show setion headers\n".
46
" -l, --list show the list in your pager (see notes)\n".
47
42
" -s, --section=SECTION display this named section\n".
48
43
" --help display this help and exit\n".
49
" --version output version information and exit\n".
51
"The advantage of using '--list' is that the pager is run as if the\n".
52
"todo list were being edited. This means that if you decide to spawn an\n".
53
"editor from you pager and edit the list, these changes get noticed.\n".
55
"The environment variables EDITOR and PAGER are used.\n".
57
"Please report bugs to Tim Marston <tim\@ed.am>.\n";
44
" --version output version information and exit\n";
62
49
if( $mode_version ) {
63
50
print "todo 1.0\n".
64
"Copyright (C) 2011, 2012 Tim Marston.\n".
51
"Copyright (C) 2011 Tim Marston.\n".
65
52
"http://ed.am/software/todo\n";
122
102
# determine editor from environment, default to "emacs -nw"
125
$editor = $ENV{ 'PAGER' };
126
defined $editor or $editor = 'less';
129
$editor = $ENV{ 'EDITOR' };
130
defined $editor or $editor = 'emacs -nw';
103
my $editor = $ENV{ 'EDITOR' };
104
defined $editor or $editor = 'emacs -nw';
132
105
my @exec_array = split( / +/, $editor );
133
106
push( @exec_array, "$todo_dir/todo" );
157
# function to display a line
160
my ( $line, $section ) = @_;
161
state $old_section = '';
163
# detect section change
164
if( $section ne $old_section ) {
165
$old_section = $section;
167
# display section heading
168
if( $display_headers || $display_all ) {
170
( "=" x length( $section ) )."\n";
174
# replace tabs with 4 spaces
182
130
# scan through file
183
my $candidate_section = '';
131
my $next_section = '';
184
132
my $section = '';
133
my $old_section = '';
186
134
open FILE, "<$todo_dir/todo" or die "can't open todo file";
189
138
# detect the line after section headings, and thus sections
190
if( /^[-=]{2,}/ && $candidate_section ne '' ) {
191
$section = $candidate_section;
192
$candidate_section = '';
139
if( /^[-=]{2,}/ && $next_section ne '' ) {
140
$section = $next_section;
197
143
# detect section headings
198
if( /^[-_\.A-Za-z0-9 ]+$/ ) {
199
$candidate_section = $_;
200
chomp $candidate_section;
144
elsif( /^[A-Z]+$/ ) {
146
chomp( $next_section );
148
# we have neither a section heading nor the line after
203
$candidate_section = '';
207
display_line( $last_line, $section ) if( $last_line ne '' );
210
if( ( lc( $section ) eq lc( $display_section ) ) ||
211
( $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
219
display_line( $last_line, $section ) if( $last_line ne '' );