App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/EmacsMain.pm  view on Meta::CPAN

  require App::Chart::Latest;
  my $latest = App::Chart::Latest->get ($symbol);

  my $face = latest_to_face($latest);

  my $help = join (' - ', $symbol, $latest->{'name'}//'') . "\n";
  if (my $quote_date = $latest->{'quote_date'}) {
    my $quote_time = $latest->{'quote_time'} || '';
    $help .= __x("Quote: {quote_date} {quote_time}",
                 quote_date => $quote_date,
                 quote_time => $quote_time)
      . "\n";
  }
  if (my $last_date = $latest->{'last_date'}) {
    my $last_time = $latest->{'last_time'} || '';
    $help .= __x("Last:  {last_date} {last_time}",
                 last_date => $last_date,
                 last_time => $last_time);
    $help .= "\n";
  }
  $help .= __x("{location} time; source {source}",
               location => App::Chart::TZ->for_symbol($symbol)->name,
               source => $latest->{'source'});

  return [$symbol, latest_line($latest), $face, $help];
}

#-----------------------------------------------------------------------------
# commands

# send latest lines for SYMBOL-LIST
sub emacs_command_latest_get_list {
  my ($symbol_list) = @_;

  # write in chunks of 20 symbols
  while (@$symbol_list) {
    my @part = splice @$symbol_list, 0, 20;
    emacs_write (symbol('latest-line-list'),
                 [ map { latest_elem($_) } @part ]);
  }
}

sub emacs_command_request_symbols {
  my ($symbol_list) = @_;
  require App::Chart::Gtk2::Job::Latest;
  App::Chart::Gtk2::Job::Latest->start ($symbol_list);
}

sub emacs_command_request_explicit {
  goto &emacs_command_request_symbols;
}

# send the symbols in symlist $key
sub emacs_command_get_symlist {
  my ($key) = @_;
  require App::Chart::Gtk2::Symlist;
  my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
  emacs_write (symbol('symlist-list'), symbol($key), $symlist->symbol_listref);
}

sub emacs_command_synchronize {
  my ($n) = @_;
  emacs_write (symbol('synchronize', $n));
}

sub emacs_command_synchronous {
  my ($seq, $func, @args) = @_;
  if (DEBUG) { print "  synchronous to $func\n"; }
  emacs_write (symbol('synchronous'), $seq,
               call_command ([$func, @args]));
}

sub emacs_command_noop {
}


#-----------------------------------------------------------------------------
# symlist manipulations

# (request-symlist KEY)
# Begin a download of latest prices for all symbols in symlist KEY.
#
sub emacs_command_request_symlist {
  my ($key) = @_;
  require App::Chart::Gtk2::Symlist;
  my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
  require App::Chart::Gtk2::Job::Latest;
  App::Chart::Gtk2::Job::Latest->start_symlist ($symlist);
}

sub emacs_command_request_explicit_symlist {
  goto &emacs_command_request_symlist;
}

# (symlist-delete KEY POS COUNT)
#
sub emacs_command_symlist_delete {
  my ($key, $pos, $count) = @_;
  my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
  foreach (1 .. $count) {
    my $iter = $symlist->iter_nth_child (undef, $pos);
    $symlist->remove ($iter);
  }
}

sub emacs_command_symlist_insert {
  my ($key, $pos, $symbol_list) = @_;
  my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
  foreach my $symbol (@$symbol_list) {
    $symlist->insert_symbol_at_pos ($symbol, $pos++);
  }
}


#-----------------------------------------------------------------------------
# completion - symbols

sub emacs_command_get_completion_symbols {
  my %symbols;

  #   # favourites list symbols
  #   {
  #     require App::Chart::Gtk2::Symlist::Favourites;
  #     if (my $favourites = App::Chart::Gtk2::Symlist::Favourites->instance) {
  #       my $href = $favourites->hash;
  #       %symbols = %$href;  # copy
  #     }
  #   }

lib/App/Chart/EmacsMain.pm  view on Meta::CPAN

  if (DEBUG) { print "  quote-one $symbol\n"; }

  my $elem = latest_elem ($symbol);
  my $extra = '';
  if (length($symbol) > 9) {
    $extra = $symbol;
  }

  # " - name", when the name is available
  my $latest = App::Chart::Latest->get ($symbol);
  if (my $name = $latest->{'name'}) {
    if ($extra) {
      $extra = join (' - ', $extra, $name);
    } else {
      $extra = $name;
    }
  }
  my $timezone = App::Chart::TZ->for_symbol($symbol);
  if ($timezone != App::Chart::TZ->loco) {
    $extra = join ('  ', $extra, '[' . $timezone->name . ']');
  }
  $elem->[1] = join ("\n", $elem->[1], $extra);

  return $elem;
}

#-----------------------------------------------------------------------------
# latest records

sub emacs_command_get_latest_record {
  my ($symbol) = @_;
  require App::Chart::Latest;
  my $latest = App::Chart::Latest->get ($symbol);

  return [ symbol('symbol'),     $latest->{'symbol'},
           symbol('name'),       $latest->{'name'},
           symbol('quote-date'), $latest->{'quote_date'},
           symbol('quote-time'), $latest->{'quote_time'},
           symbol('bid'),        $latest->{'bid'},
           symbol('offer'),      $latest->{'offer'},
           symbol('open'),       $latest->{'open'},
           symbol('high'),       $latest->{'high'},
           symbol('low'),        $latest->{'low'},
           symbol('last'),       $latest->{'last'},
           symbol('last-date'),  $latest->{'last_date'},
           symbol('last-time'),  $latest->{'last_time'},
           symbol('change'),     $latest->{'change'},
           symbol('volume'),     $latest->{'volume'},
           symbol('decimals'),   0,
           symbol('note'),       $latest->{'note'},
           symbol('source'),     $latest->{'source'},
           symbol('face'),       latest_to_face($latest),
         ];
}


#-----------------------------------------------------------------------------
# spreadsheet support

# return when SYMBOL-LIST has been downloaded
# (define-public (emacs-command-request-symbols-synchronous symbol-list)
#   (call-with-current-continuation
#    (lambda (cont)
#      (define (callback this-symbol-list)
#        (set! this-symbol-list (remove latest-in-progress? this-symbol-list))
#        (set! symbol-list (lset-difference string=?
# 					  symbol-list this-symbol-list))
#        (if (null? symbol-list)
# 	   (begin
# 	     (notify-disconnect 'latest-update callback)
# 	     (cont #f))))
#      (notify-connect 'latest-update callback)
#      (c-main-enq! latest-request-symbols symbol-list)
#      (c-main-goto-top)))
#   'nil)

1;
__END__

=head1 NAME

App::Chart::EmacsMain -- main loop for Emacs interaction

=head1 SYNOPSIS

 use App::Chart::EmacsMain;
 App::Chart::EmacsMain->main ();

=head1 HOME PAGE

L<http://user42.tuxfamily.org/chart/index.html>

=head1 LICENCE

Copyright 2008, 2009, 2010, 2011, 2014, 2015, 2016, 2017 Kevin Ryde

Chart is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.

Chart is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along with
Chart; see the file F<COPYING>.  Failing that, see
L<http://www.gnu.org/licenses/>.

=cut



( run in 1.464 second using v1.01-cache-2.11-cpan-39bf76dae61 )