Restore eldoc-eval.el.
[emacs/old-mirror.git] / packages / notes-mode / Notes.pm
blob129299bf512eaef8122160be1fcd2aa58ccc3f4c
1 #!/usr/bin/perl
4 # Notes.pm
5 # $Id: Notes.pm,v 1.9 2010/06/20 18:31:22 johnh Exp $
7 # Copyright (C) 1996-2006,2012 Free Software Foundation, Inc.
8 # Comments to <johnh@isi.edu>.
10 # This file is under the Gnu Public License, version 2.
11 # For details see the COPYING which accompanies this distribution.
15 # A Perl module implement a notes class.
18 require 5.000;
19 package Notes;
20 use Carp;
21 use strict;
23 #----------------------------------------------------------------------
25 # my($Notes::revsion) = '$Id: Notes.pm,v 1.9 2010/06/20 18:31:22 johnh Exp $'; #' font-lock hack
26 # my($Notes::VERSION) = 1.00;
28 # public method
29 # optional argument: pathname to read
30 sub new {
31 my ($class, $file) = @_;
32 my $self = bless {};
33 if (defined($file)) {
34 $self->read_from_file($file);
35 } else {
36 $self->init();
38 return $self;
42 # public method
43 sub read_from_file {
44 my ($self, $filename) = @_;
46 $self->init();
48 open(FILE, "<$filename") || croak "Cannot open $filename";
49 my(@lines) = <FILE>;
50 close FILE;
51 my($i);
52 my($start, $Subject) = (0, undef);
53 my(%entries);
55 for ($i = 0; $i < $#lines; $i++) {
56 if ($lines[$i] =~ /^\* / &&
57 $lines[$i+1] =~ /^-+\r?$/) {
58 $self->push_entry($Subject, join("", @lines[$start .. $i-1]));
59 $start = $i;
60 ($Subject) = ($lines[$i] =~ /^\*\s+(.*)\r?$/);
63 $i = $#lines + 1;
64 $self->push_entry($Subject, join("", @lines[$start .. $i-1]));
65 return 1;
68 # public_method
69 sub subjects {
70 my($self) = @_;
71 return $self->{'subjects'};
74 # public method
75 sub by_subject {
76 my($self, $Subject) = @_;
77 my($subject) = lc($Subject);
78 return wantarray ? () : undef
79 if (!defined($self->{'entryis_by_subject'}{$subject}));
80 my(@ret) = ();
81 foreach (@{$self->{'entryis_by_subject'}{$subject}}) {
82 push (@ret, $self->{'entries'}[$_]);
84 return @ret;
87 # public method
88 sub prelude {
89 my($self) = @_;
90 return $self->{'pre'};
94 # private method
95 sub push_entry {
96 my($self, $Subject, $entry) = @_;
97 if (!defined($Subject)) {
98 $self->{'pre'} = $entry;
99 return;
101 my($subject) = lc($Subject);
102 push (@{ $self->{'subjects'} }, $Subject);
103 push (@{ $self->{'entries'} }, $entry);
104 push (@{ $self->{'entryis_by_subject'}{$subject} }, $#{$self->{'entries'}});
108 # private method
109 sub init {
110 my($self) = @_;
111 # These inits break things. Go figure.
112 # @{ $self->{'subjects'} } = @{$self->{'entries'}} = ();
113 # %{ $self->{'entryis_by_subject'} } = ();
114 $self->{'pre'} = '';