! Page 58 ! Go to start of a certain line in the current buffer ! ! Parameters: ! ! line_parameter Line number to move to - input procedure eve_line (line_parameter) local loc$line_number, ! Local copy of line_parameter this_position, ! Marker for current cursor position last_line; ! Number of lines in buffer, including eob_text on_error message (fao ("Cannot move to line !SL", loc$line_number)); position (this_position); return; endon_error; this_position := mark (none); if not (eve$prompt_number (line_parameter, loc$line_number, "Line number: ", "No line number given")) then return; endif; if loc$line_number <= 0 then message (fao ("Cannot move to line !SL", loc$line_number)); return; endif; last_line := get_info (current_buffer, eve$kt_record_count) + 1; ! include eob_text if loc$line_number > last_line then if last_line > 0 then message (fao ("Buffer has only !SL line!%S", last_line)); else message ("Buffer is empty"); endif; else position (beginning_of (current_buffer)); move_vertical (loc$line_number - 1); ! already at line 1 eve$position_in_middle (mark (none)); endif; endprocedure ; ! Provides a hook for user-written procedures such as auto-indent. procedure eve$split_line split_line; endprocedure !+ ! FIX_CRLFS.TPU - Routine to turn CRLFs into line breaks ! and remove leading CRs and trailing CRLFs !- procedure eve_fix_crlfs LOCAL the_range, save_position, crlf_count ; on_error if (ERROR <> tpu$_STRNOTFOUND) then message("Error (" + str(ERROR) + ") at line " + str(ERROR_LINE)); return; endif; endon_error; ! mark where we started so we can come back to it. save_position := mark(none); message("Converting CR's&LF's in buffer "+ get_info(current_buffer,"name")); crlf_count := 0; ! ! First remove the CRLFs. If they are not at the EOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(13)+ascii(10), FORWARD); exitif (the_range = 0); erase(the_range); crlf_count := crlf_count+1; position(beginning_of(the_range)); if (current_character <> "") then split_line; endif; endloop; ! ! Next remove naked LFs. If they are not at the EOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(10), FORWARD); exitif (the_range = 0); erase(the_range); crlf_count := crlf_count+1; position(beginning_of(the_range)); if (current_character <> "") then split_line; endif; endloop; ! ! Finally, remove naked CRs. If they are not at the BOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(13), FORWARD); exitif (the_range = 0); position(end_of(the_range)); if (current_offset <> 0) then split_line; endif; crlf_count := crlf_count+1; erase(the_range); endloop; position(save_position); message(fao("Converted CR's & LF's at !UL positions",crlf_count)); endprocedure ; procedure eve_next_line if (current_direction = reverse) then if (current_offset = 0) then move_vertical(-1); else move_horizontal(-current_offset); endif; else move_horizontal(-current_offset); move_vertical(1); endif; endprocedure procedure eve$fill_line (insert_space) local loc_buffer, ! Current buffer loc_left_margin, ! Left margin of loc_buffer loc_right_margin, ! Right margin of loc_buffer space_position, ! Marker for current cursor position this_column, ! Current column hot_column, ! Column at start of hot zone words, ! Number of words in hot zone line_position, ! Previous position in current line spaces, ! Number of spaces between words start_of_line; ! Column at start of new line loc_buffer := current_buffer; loc_left_margin := get_info (loc_buffer, eve$kt_left_margin); loc_right_margin := get_info (loc_buffer, eve$kt_right_margin); if (loc_right_margin - loc_left_margin) <= eve$x_hot_zone_size then hot_column := loc_right_margin; else hot_column := loc_right_margin - eve$x_hot_zone_size; endif; space_position := mark (none); this_column := get_info (loc_buffer, eve$kt_offset_column); if (this_column <= hot_column) then if insert_space then copy_text (" "); endif; return; endif; loc_right_margin := loc_right_margin + 1; line_position := mark (none); loop this_column := get_info (loc_buffer, eve$kt_offset_column); exitif this_column <= loc_right_margin; line_position := mark (none); spaces := 0; exitif eve$start_of_word = 0; spaces := eve$backup_over_whitespace; words := words + 1; endloop; ! No sense splitting at the beginning of the line this_column := get_info (loc_buffer, eve$kt_offset_column); if this_column = loc_left_margin then position (line_position); endif; erase_character (spaces); eve$split_line; if loc_left_margin > 1 then eve$to_column (loc_left_margin); endif; start_of_line := get_info (loc_buffer, eve$kt_offset_column); position (space_position); this_column := get_info (loc_buffer, eve$kt_offset_column); if this_column > loc_right_margin then if words > 1 then eve$fill_line (insert_space); else eve$split_line; if loc_left_margin > 1 then eve$to_column (loc_left_margin); endif; endif; else if insert_space and (this_column <> start_of_line) then copy_text (" "); endif; endif; endprocedure ! ! ! EDT Delete to the end of the line ! procedure eve_delete_to_eol !gold kp2 ( delete to end of line) !The below line works because the erase_character will stop at the end of line ! we will only pick up from the current point to the end of the line unless ! we are already on the end of line. In this case we are supposed to deleted ! the line terminator plus the entire next line. ! local this_range; if current_offset = length (current_line) then move_vertical(1); !move to begining of next line if mark(none) <> end_of (current_buffer) then move_horizontal (-current_offset);!goto begining of line this_range := search_quietly(remain,forward); eve$x_restore_line := eve$erase_text(this_range,eve$x_line_buffer, FALSE); endif; else this_range := search_quietly(remain,forward); eve$x_restore_line := eve$erase_text(this_range,eve$x_line_buffer, FALSE); endif; endprocedure !+ ! NUMBER_LINES.TPU - Routine to add line numbers to a buffer !- procedure eve_number_lines local loc_line_number,prompt,answer; prompt := "Ok to put numbers in file? "; answer := read_line(prompt); edit(answer,UPPER); if (answer = "YES") or (answer = "Y") then loc_line_number := 1; position(beginning_of(current_buffer)); loop if (((loc_line_number / 250) * 250) = loc_line_number) then message("Numbering line " + str(loc_line_number)); endif; exitif (mark(none) = end_of(current_buffer)); eveplus_insert_text(fao("!6UL ", loc_line_number)); loc_line_number := loc_line_number + 1; move_horizontal(-current_offset); move_vertical(1); endloop; else return; endif; endprocedure procedure eve_unumber_lines local prompt,answer,number_pattern,number_range; prompt := "Ok to un-number file? "; answer := read_line(prompt); edit(answer,UPPER); if (answer = "YES") or (answer = "Y") then position(beginning_of(current_buffer)); loop exitif (mark(none) = end_of(current_buffer)); number_pattern := span(eve$x_digit_characters); number_range := search(number_pattern,forward); erase(number_range); eve$compress_whitespace; move_horizontal(-current_offset); move_vertical(1); endloop; endif; endprocedure ! Set status line of a window to include buffer name and mode indications. ! Used primarily to indicate insert/overstrike and forward/reverse toggling. ! ! Parameters: ! ! this_window Window whose status line is being set - input ! !!!!!!!! !!!!!!!!modified to output the current keymap name... !!!!!!!! ! procedure eve$set_status_line (this_window) local loc_buffer, ! Current buffer mode_string, ! String version of current mode direction_string, ! String version of current direction buffer_name, ! String containing name of current buffer keypad_name, ! MOD-- string to indicate current keypad this_keymap, ! eve$x_max_buffer_name_length, eve$x_max_keypad_name_length; ! Don't add a status line to windows without a status line loc_buffer := get_info (this_window, eve$kt_buffer); if (loc_buffer = 0) or (get_info (this_window, "status_line") = 0) then return; endif; if get_info (loc_buffer, eve$kt_mode) = insert then mode_string := "Insert "; else mode_string := "Overstrike"; endif; if get_info (loc_buffer, "direction") = reverse then direction_string := "Reverse"; else direction_string := "Forward"; endif; buffer_name := get_info (loc_buffer, eve$kt_name); eve$x_max_buffer_name_length := 30; if length (buffer_name) > eve$x_max_buffer_name_length then buffer_name := substr (buffer_name, 1, eve$x_max_buffer_name_length); else buffer_name := buffer_name + substr (eve$kt_spaces, 1, eve$x_max_buffer_name_length - length (buffer_name)); endif; this_keymap := " "; this_keymap := get_info (current_buffer,"key_map_list"); keypad_name := " "; ! fix spawn from debug bug keypad_name := get_info(KEY_MAP,"first","tpu$key_map_list"); !if (this_keymap = "TPU$KEY_MAP_LIST") then ! keypad_name := get_info (KEY_MAP,"first","tpu$key_map_list"); !else ! keypad_name := get_info (KEY_MAP,"first","tpu$list_key_map_list"); !endif; eve$x_max_keypad_name_length := 12; if length (keypad_name) > eve$x_max_keypad_name_length then keypad_name := substr (keypad_name, 1, eve$x_max_keypad_name_length); else keypad_name := keypad_name + substr (eve$kt_spaces, 1, eve$x_max_keypad_name_length - length (keypad_name)); endif; set (status_line, this_window, reverse, " Buffer " + buffer_name + " " + keypad_name + " " + mode_string + " " + direction_string); endprocedure ! Page 21 ! Set status line of a window to include buffer name and mode indications. ! Page 22 ! Update the status line in all windows mapped to the current buffer procedure eve$update_status_lines local loc_buffer, ! Current buffer loop_window; ! Window currently being checked in loop loc_buffer := current_buffer; if get_info (loc_buffer, "map_count") > 1 then loop_window := get_info (window, eve$kt_first); loop exitif loop_window = 0; if get_info (loop_window, eve$kt_buffer) = loc_buffer then eve$set_status_line (loop_window); endif; loop_window := get_info (window, "next"); endloop; else eve$set_status_line (current_window); endif; endprocedure !Last Modified: 24-JAN-1989 15:43:02.03, By: FLEMING procedure eve$get_map_status_field (the_length,the_format) ! procedure to include keymap name in status line per pp G-7, G-8 local this_keymap,keypad_name; on_error [otherwise]:; endon_error; the_length := 12; ! assume max of 12 char for keymap name the_format := "!AS"; !specify FAO format this_keymap := get_info (current_buffer,"key_map_list"); keypad_name := " "; if (this_keymap = "TPU$KEY_MAP_LIST") then keypad_name := get_info (KEY_MAP,"first","tpu$key_map_list"); else keypad_name := get_info (KEY_MAP,"first","tpu$list_key_map_list"); endif; return fao(the_format,keypad_name); endprocedure !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Modified to include column number. Use fao code from EVE1.0. 5-8-88 GAF.! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! procedure eve_what_line ! What line am I on? local saved_mark, ! marker - current position text_mark, ! marker - after snapping to text this_line_position, ! marker - position at start of this_line total_lines, ! integer - total lines in buffer high_line, ! integer - high line limit for binary search low_line, ! integer - low line limit for binary search low_position, ! marker - beginning of low line this_line, ! integer - line number of current guess eob_flag, ! boolean - true if at eob percent, ! integer - percent of way through buffer column_number; ! integer - column in line cursor is on on_error [TPU$_CONTROLC]: eve$$restore_position (saved_mark); ! restore free cursor position eve$learn_abort; abort; [OTHERWISE]: eve$$restore_position (saved_mark); endon_error; ! Initialization saved_mark := mark (FREE_CURSOR); position (search (ANCHOR, FORWARD)); ! snap the cursor (move_vertical pads) text_mark := mark (NONE); total_lines := get_info (current_buffer, "record_count"); high_line := total_lines + 1; if text_mark = end_of (current_buffer) then if text_mark = beginning_of (current_buffer) then eve$message (EVE$_BUFEMPTY); position (saved_mark); ! no learn_abort here return (FALSE); else eob_flag := TRUE; low_line := total_lines; low_position := end_of (current_buffer); endif; else low_line := 1; low_position := beginning_of (current_buffer); endif; ! Binary search loop exitif high_line - low_line <= 1; this_line := (high_line + low_line) / 2; position (low_position); move_vertical (this_line - low_line); if mark (FREE_CURSOR) > saved_mark then high_line := this_line; else low_line := this_line; low_position := mark (FREE_CURSOR); if mark (FREE_CURSOR) = saved_mark then high_line := this_line; endif; endif; endloop; ! TPU will truncate numbers on division; make it round instead percent := (((low_line * 1000) / total_lines) + 5) / 10; ! Display message and return to original position if eob_flag then eve$message (EVE$_WHATEOBLINE, 0, total_lines); else column_number := current_column; ! eve$message (EVE$_WHATLINE, 0, low_line, total_lines, percent); ! Display message and return to original position message (fao ("You are on line !SL out of !SL (!SL%) Column !SL", low_line, total_lines, percent,column_number)); endif; position (saved_mark); return (TRUE); endprocedure;