!       ABEL_INFO.TPU
!
!       Table of Contents as of 27-Mar-1988
!
!       Procedure name              Page    Description
!       --------------              ----    -----------
!
!       eve_where                      1    Where am I?
!       eve_describe_key               2    Display comment assoc'd with key
!       eve_display_character          3    Display current character statistics
!       eve_list_commands              5    List commands

!                                                                       Page 1


procedure eve_where                     ! Where am I?

! Gives location information for the current window/buffer.  By default shows
! the line number you're on out of the total number, and which screen column
! (not character number) you're on.  If you use the /full qualifier, you will
! see much more detailed and cryptic information (screen offset, character
! number, shift, etc).
!
! Qualifiers:
!   /full           boolean     give full position information
!
! Source:
!   Eveplus

local
    cur_buf,                            ! current buffer
    cur_win,                            ! current window
    full_buffer,                        ! full buffer stats
    full_window,                        ! full window stats
    this_line,                          ! line number of current line
    percent;                            ! % of way through buffer

cur_buf := current_buffer;
cur_win := current_window;

this_line := eve$what_line;             ! Find current line number in buffer
total_lines := get_info(cur_buf,"record_count");
percent :=                              ! Calculate % (round)
    (((this_line * 1000) / total_lines)+5)/10;

if abl$q_full then
    full_buffer := fao("Buffer ln !SL of !SL (!SL%), ofs !SL, ofs col !SL",
        this_line,
        total_lines,
        percent,
        get_info(cur_buf,"offset"),
        get_info(cur_buf,"offset_column"));
    full_window := fao("Window row !SL, col !SL, shf !SL",
        get_info(cur_win,"current_row"),
        get_info(cur_win,"current_column"),
        get_info(cur_win,"shift_amount"));
    message(full_buffer +
        substr(eve$x_spaces,1,80-length(full_buffer)-length(full_window)) +
        full_window);
else
    message(fao("Line !SL of !SL (!SL%), screen column !SL",this_line,
        total_lines, percent,get_info(cur_win,"current_column")));
endif;
endprocedure


!                                                                       Page 2


procedure eve_describe_key              ! Display comment assoc'd with key

! This procedure will prompt for a key stroke or shift sequence and look
! up the comment that was attributed to the keystroke when  it was defined.
! If there was no comment given, the message "Key Has No Function..." is
! displayed in the message area at the bottom of the screen.  Otherwise,
! the key's function is displayed.  This function assumes that there will
! always be some sort of comment given when keys are defined to user
! procedures.  This may not be an acurate assumption in all circumstances.
! The value of this function depends on the descriptive nature of the names
! of user routines.  It should be noted that this works on DEFINE KEY
! operations also.  So use the whole function name to get the best
! description.
!
! Source:
!   Eveplus

local
    key_to_describe,
    key_description;

message("Press key to describe:");
key_to_describe := read_key;
key_description := lookup_key(key_to_describe,comment);
if key_description <> ""
   then
      message("Function description:  " + key_description);
   else
      message("Key has no function...");
endif;
endprocedure;


!                                                                       Page 3


procedure eve_display_character         ! Display current character statistics

! This procedure writes a one line message describing the current character
! in terms of octal, decimal, hexadecimal and (sometimes ) '^' notation.
!
! Source:
!   Eveplus

local
    i,
    cc;

!
! handle end-of-buffer condition
!
if mark( none ) = end_of( current_buffer ) then
    message( 'At end of buffer, no current character' );
    return;
endif;
!
! Convert the character to an integer the hard way (no builtin yet)
!
i := 0; loop;
    exitif i > 255;
    exitif current_character = ascii(i);
    i := i + 1;
endloop;
  if i > 255 then i := 0; endif;        ! on overflow, reset to null
!
! Provide ^ notation for ascii control characters
!
if i < 32 then
    cc := ', ^' + ascii(i+64);
else
    cc := '';
endif;
!
! Format and output the results
!
message(fao("Current character is '!AS', octal=!OB, decimal=!-!UB, " +
                "hex=!-!XB!AS", current_character, i, cc ) );

endprocedure

!                                                                       Page 5


procedure eve_list_commands             ! List commands
    ($starting_with)

! Display list of Abel commands
!
! Qualifiers:
!   /qualifiers     boolean     include qualifiers of commands
!
! Globals:
!   abl$qualifier_definition
!
! Source:
!   Eveplus/Eva

local
    the_names,
    column_width,
    total_width,
    how_many_columns,
    qualifier_definition,
    starting_with,
    command,                                ! the old command in choice buffer
    new_command,                            ! the new command
    temp;

on_error
endon_error;

!
! Get list of all matching procedure names
!
!eve$prompt_string($starting_with,starting_with,"List commands starting with? ",
!   "All commands will be returned");
starting_with := $starting_with;
edit(starting_with,trim);
translate(starting_with,"_"," ");
the_names := expand_name("eve_"+starting_with, procedures) + " ";
!
! Put all matching commands in the choice buffer
!
position(eve$choice_buffer);
erase(eve$choice_buffer);
loop
    exitif (the_names = eve$x_null);
    temp := index (the_names, " ");
    copy_text (substr (the_names, 1, temp));
    !
    ! If also displaying qualifiers, find qualifier definition
    !
    if abl$q_qualifiers then
        qualifier_definition := "abl$qd_"+substr(the_names,5,temp-5);
        qualifier_definition := expand_name(qualifier_definition,variables);
        if error = tpu$_multiplenames then
            message("Multiple names returned for " +
                substr(the_names,5,temp-5));
            return 0;
        endif;
        if error <> tpu$_nonames then
            execute("abl$qualifier_definition := " + qualifier_definition);
            copy_text(substr(eve$x_spaces,1,28-length(current_line))
                + abl$qualifier_definition);
        endif;
    endif;
    !
    ! Get rid of Eve command name that we just processed
    !
    the_names := substr(the_names, temp+1, length(the_names));
    split_line;
    erase_line;
endloop;
!
! Get rid of "eve_" in front of all the command names and "_"'s imbedded in
! the command names (but not those in the qualifiers)
!
position(beginning_of(current_buffer));
loop
    command := eveplus_search_quietly(line_begin & "eve_" & scan(" "), forward);
    exitif command = 0;
    position(command);
    new_command := substr(command,5,255);
    translate(new_command," ","_");
    erase(command);
    copy_text(new_command);
endloop;
!
! Sort commands
!
abl$extended_sort_buffer(current_buffer,1,30,abl$sort_ascending);
!
! Format command list if not showing qualifiers
!
if not abl$q_qualifiers then
    eve$format_choices
endif;
!
! Move choice buffer to show buffer and display it
!
position(show_buffer);
erase(show_buffer);
copy_text(eve$choice_buffer);
position(beginning_of(show_buffer));
map (info_window, show_buffer);
eve$update_status_lines;
abort;
endprocedure


procedure eve_help ($the_topic)

! Top-level help command.  Calls eve$help_keypad for keypad help,
! otherwise provides help on Eve commands.
!
! Parameters:
!   $the_topic      string      topic from command line - input
!
! Qualifiers:
!   /keypress       boolean     allow user to get help on a key

local
    the_topic,
    old_text_mode,
    unmap_when_thru;

if abl$q_keypress then
    help_char := eve$prompt_key
        ("Press key that you want help on (Return to leave help): ");
    the_topic := eve$lookup_comment (help_char);
    if the_topic = "return" then
        return 1
    endif;
    the_topic := "commands " + the_topic;
else
    the_topic := $the_topic;
endif;
map(info_window,help_buffer);
eve$update_status_lines;
old_text_mode := get_info(info_window,"text");
set(text,info_window,no_translate);
help_text("abelhelp",the_topic,on,help_buffer);
set(text,info_window,old_text_mode);
unmap(info_window);
endprocedure


!procedure eve_show                      ! Show information about buffers
!
!! Show information about all non-system buffers, one at a time.
!! Ask if user wants more information after each buffer.
!
!local this_position,            ! Marker for current cursor position
!      this_window,              ! Current window
!      this_buffer,              ! Current buffer
!      buffer_to_show,           ! Buffer passed to eve$show_buffer_info
!      window_to_show,           ! Window passed to eve$show_buffer_info
!      next_buffer,              ! Next candidate buffer
!      show_key,                 ! String associated with key read after prompt
!      throw_away;               ! Result of eve$prompt_key - to resume editing
!
!this_position := mark (none);
!this_buffer := current_buffer;
!this_window := current_window;
!buffer_to_show := current_buffer;
!window_to_show := current_window;
!next_buffer := get_info (buffers, "last");
!map (info_window, show_buffer);
!set (status_line, info_window, reverse,
!     " Show buffer (" + eve$x_version + ")");
!
!loop
!    exitif next_buffer = 0;
!    if (next_buffer <> this_buffer) and
!       (get_info (next_buffer, "system") = 0) then
!        erase (show_buffer);
!        eve$show_buffer_info (buffer_to_show, window_to_show);
!        if buffer_to_show = this_buffer then
!            window_to_show := 0;
!        endif;
!        update (info_window);
!        show_key := eve$lookup_comment (eve$prompt_key
!            ("Press Do for more information, Return to resume editing: "));
!        if show_key = "do" then
!            buffer_to_show := next_buffer;
!        else
!            unmap (info_window);
!            position (this_window);
!            return;
!        endif;
!    endif;
!    next_buffer := get_info (buffers, "previous");
!endloop;
!
!erase (show_buffer);
!eve$show_buffer_info (buffer_to_show, window_to_show);
!update (info_window);
!throw_away := eve$prompt_key ("Press any key to resume editing: ");
!unmap (info_window);
!position (this_window);
!
!endprocedure;
!
!
!
!
!procedure eve$show_buffer_info          ! Gather info about given buffer
!    (this_buffer, this_window)
!
!! Main routine called by show command.  Append information about the given
!! buffer to the end of the show_buffer.  Mapping, erasing, etc. are
!! handled in eve_show.
!!
!! Parameters:
!!
!!       this_buffer             Buffer being inquired about - input
!!       this_window             Window being inquired about - input
!
!local input_file_name,          ! String with input file name for this_buffer
!      output_file_name,         ! String with output file name for this_buffer
!      how_many_records,         ! Number of records in this_buffer
!      record_text,              ! String for display of how_many_records
!      this_window_shift,        ! Shift amount for this_window
!      what_tab_stops;           ! String or integer with tab stop settings
!
!on_error
!! Trap messages with tpu$_nonames and tpu$_multiplenames
!endon_error;
!
!position (end_of (show_buffer));
!set (insert, show_buffer);      ! should be insert anyway, but just in case...
!
!copy_text (fao (" Information about buffer !AS",
!                get_info (this_buffer, "name")));
!eve$letter_wrap (27);
!split_line;
!split_line;
!
!copy_text (" Input file:  ");
!input_file_name := get_info (this_buffer, "file_name");
!if input_file_name = eve$x_null then
!    copy_text ("none");
!else
!    copy_text (input_file_name);
!    eve$letter_wrap (15);
!endif;
!split_line;
!
!copy_text (" Output file: ");
!output_file_name := get_info (this_buffer, "output_file");
!if (output_file_name = 0)
!!or (get_info (this_buffer, "no_write"))
!then
!    copy_text ("none");
!else
!    copy_text (output_file_name);
!    eve$letter_wrap (15);
!endif;
!split_line;
!split_line;
!
!if get_info (this_buffer, "modified") then
!    copy_text ("     Modified                   ")
!else
!    copy_text ("     Not modified               ");
!endif;
!copy_text (fao ("Left margin set to !SL",
!                get_info (this_buffer, "left_margin")));
!split_line;
!
!if get_info (current_buffer, "mode") = insert then
!    copy_text ("     Insert mode                ");
!else
!    copy_text ("     Overstrike mode            ");
!endif;
!copy_text (fao ("Right margin set to !SL",
!                get_info (this_buffer, "right_margin")));
!split_line;
!
!if get_info (this_buffer, "direction") = forward then
!    copy_text ("     Forward direction          ");
!else
!    copy_text ("     Reverse direction          ");
!endif;
!
!if this_window <> 0 then
!    copy_text (fao ("Window width set to !SL",
!               get_info (this_window, "width")));
!endif;
!split_line;
!
!how_many_records := get_info (this_buffer, "record_count");
!if how_many_records > 0 then
!    record_text := fao ("     !SL line!%S", how_many_records);
!else
!    record_text := "     No lines";
!endif;
!copy_text (record_text);
!if length (record_text) >= 32 then
!    copy_text ("  ");
!else
!    copy_text (substr (eve$x_spaces, 1, 32 - length (record_text)));
!endif;
!
!if this_window <> 0 then
!    this_window_shift := get_info (this_window, "shift_amount");
!    if this_window_shift > 0 then
!        copy_text (fao ("Window shifted right by !SL columns",
!                        this_window_shift));
!    endif;
!endif;
!split_line;
!split_line;
!
!what_tab_stops := get_info (this_buffer, "tab_stops");
!if get_info (what_tab_stops, "type") = integer then
!    copy_text (fao (" Tab stops set every !SL columns", what_tab_stops));
!else
!    copy_text (fao (" Tab stops set at columns !AS", what_tab_stops));
!    eve$letter_wrap (27);
!endif;
!split_line;
!
!! Move to choice buffer to work with mark names
!
!eve$expand_to_choices (expand_name ("eve$mark_", variables));
!loop
!    exitif mark (none) = end_of (eve$choice_buffer);
!    execute ("eve$x_buffer_of_mark:=get_info(" + current_line +
!             ",'buffer')");
!    if eve$x_buffer_of_mark = this_buffer then
!        erase_character (9);
!        move_vertical (1);
!    else
!        erase_line;
!    endif;
!endloop;
!
!if get_info (eve$choice_buffer, "record_count") = 0 then
!    position (end_of (show_buffer));
!    copy_text (" No marks");
!else
!    eve$format_choices;
!    position (end_of (show_buffer));
!    copy_text (" Marks: ");
!    split_line;
!    split_line;
!    copy_text (eve$choice_buffer);
!endif;
!
!if current_offset > 0 then
!    split_line;
!endif;
!
!endprocedure;
!
!
