home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-27 | 27.5 KB | 1,052 lines |
- # $Header: P:/source/ppee/macros/msword.pev 1.36 20 Aug 1990 18:13:28 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: msword.pel $: Key bindings for Microsoft Word compatability
-
- ##
- ## msword() - define MS Word key bindings
- ##
- local extended = FALSE
- local wordDefStr = "<|\\(|\\)|,"
- local previous_mst, previous_win_flags
-
-
- global function msword() {
-
- emulation_mode = "msword"
- execute_event_handler(EVENT_EMULATION_CHANGED)
-
- current_keymap = create_keymap(factory_keymap)
- toggle_file_backup( TRUE )
- previous_win_flags = default_window_flags
- default_buffer_tabs = "5 10"
- default_window_flags = 0x6091
- if ( !and( window_flags, WINDOW_SYSTEM )) {
- window_flags = 0x6091
- search_flags = \
- + SEARCH_MAXIMAL_MATCH \
- + SEARCH_FORWARD \
- + SEARCH_REGEX \
- + SEARCH_ADVANCE \
- + SEARCH_HIGHLIGHT
- buffer_tabs = "5 10"
- }
- toggle_dialog( TRUE )
- default_wp_left_margin = 9
- default_wp_right_margin = 75
- reset_visibles()
- msw_visibles()
- # attach_event_handler(EVENT_KEYPRESS,function_id("msw_check_key"))
- previous_mst = mouse_selection_type
- mouse_selection_type = INCLUSIVE_SELECTION
- attach_event_handler(EVENT_EMULATION_CHANGED,function_id("msw_restore"))
-
- #--------------------------------------------------------------
- # Mouse commands
- #--------------------------------------------------------------
- assign_mouse_buttons()
-
- #--------------------------------------------------------------
- # Arrow Keys
- #--------------------------------------------------------------
- assign_key( "<Left>", "msw_left")
- assign_key( "<Right>", "msw_right")
- assign_key( "<Up>", "msw_up")
- assign_key( "<Down>", "msw_down")
- assign_key( "<Ctrl-Left>", "prev_word")
- assign_key( "<Ctrl-Right>", "next_word")
-
- #--------------------------------------------------------------
- # Function Keys
- #--------------------------------------------------------------
- assign_key( "<F1>", "next_window")
- assign_key( "<F2>", "prev_window") # non-standard
- assign_key( "<F3>", "buffer_list") # non-standard
- assign_key( "<F4>", "playback") # non-standard
- assign_key( "<F5>", "toggle_insert_mode")
- assign_key( "<F6>", "msw_toggle_inclusive_block")
- assign_key( "<F7>", "msw_prev_word")
- assign_key( "<F8>", "msw_next_word")
- assign_key( "<F9>", "mark_paragraph")
- assign_key( "<F10>", "invoke_function")
- assign_key( "<Shift-F1>", "undo")
- assign_key( "<Shift-F2>", "redo") # non-standard
- assign_key( "<Shift-F3>", "record_key")
- assign_key( "<Shift-F4>", "msw_search_again")
- assign_key( "<Shift-F5>", "replace_again") # non-standard
- assign_key( "<Shift-F6>", "msw_toggle_column_block")
- assign_key( "<Shift-F7>", "wp") # non-standard
- assign_key( "<Shift-F8>", "compile_buffer") # non-standard
- assign_key( "<Shift-F9>", "display_errors") # non-standard
- assign_key( "<Shift-F10>", "goto_next_error") # non-standard
- assign_key( "<Ctrl-F1>", "toggle_window_zoom")
- assign_key( "<Ctrl-F2>", "next_buffer_key") # non-standard
- assign_key( "<Ctrl-F3>", "prev_buffer_key") # non-standard
- assign_key( "<Ctrl-F4>", "msw_reverse")
- assign_key( "<Ctrl-F5>", "optional_function toggle_drawing")
- assign_key( "<Ctrl-F6>", "delete_tiled_window")
- assign_key( "<Ctrl-F7>", "edit_file_key")
- assign_key( "<Ctrl-F8>", "print_buffer")
- assign_key( "<Ctrl-F9>", "delete_buffer_key")
- assign_key( "<Ctrl-F10>", "msw_save_buffer")
- assign_key( "<Alt-F1>", "tabs")
- # assign_key( "<Alt-F2>", "beep")
- assign_key( "<Alt-F3>", "copy_to_scrap_key")
- # assign_key( "<Alt-F4>", "beep")
- assign_key( "<Alt-F7>", "learn_key" )
- assign_key( "<Alt-F9>", "delete_window_and_buffer" )
-
- #--------------------------------------------------------------
- # Misc. Keys
- #--------------------------------------------------------------
- assign_key( "<Space>", "indent_outdent_space" )
- assign_key( "#10", "auto_indent_nl" ) # Ctrl-J or Ctrl-Enter
- assign_key( "#13", "auto_indent_cr" ) # Ctrl-M or Enter
- assign_key( "<Esc>", "escape_hit")
- assign_key( "<Alt-H>", "help")
- assign_key( "<Alt-M>", "mark_matching")
- assign_key( "<Alt-P>", "insert_quoted_key")
- assign_key( "<Alt-V>", "print_version")
- assign_key( "<Alt-X>", "beep")
- assign_key( "<Del>", "cut")
- assign_key( "<Ins>", "insert_scrap")
- assign_key( "<Shift-Tab>", "outdent_tab_maybe")
- assign_key( "<Tab>", "indent_tab_maybe")
- assign_key( "`", "expand_template")
- }
-
-
- # escape_hit()
- #
- # This is the function that presents the "main" Word menu to the
- # user when the Ecs key is pressed. It serves as a central
- # jumping-off point to the various Word features
-
- function escape_hit(){
- local selected
-
- selected = tolower(mouse_confirm( \
- "CMD: Help Jump Library Options Print Quit Replace Search Transfer Undo Window", \
- "HhJjLlOoPpQqRrSsTtUuWw"))
- message("")
- if (selected == "h")
- help()
- else
- if (selected == "j")
- jump_menu()
- else
- if (selected == "l")
- library_menu()
- else
- if (selected == "o")
- option_menu()
- else
- if (selected == "p")
- print_menu()
- else
- if (selected == "q")
- msw_quit()
- else
- if (selected == "r")
- replace_menu()
- else
- if (selected == "s")
- search_menu()
- else
- if (selected == "t")
- transfer_menu()
- else
- if (selected == "u")
- undo()
- else
- if (selected == "w")
- window_menu()
- }
-
-
- # jump_menu()
- #
- # This function allows the user to move directly to a line, page or
- # mark by number. Pages for our purposes here are units of 66
- # lines.
-
- local function jump_menu(){
- local selected, jumpNum, escaped
-
- selected = tolower(mouse_confirm("Jump to: Line Page Mark","LlPpMm"))
- if (selected == "l"){
- do {
- jumpNum = prompt("Line Number: ",current_line)
- escaped = (and(current_key,255) == 27)
- jumpNum = atoi(jumpNum)
- } while( jumpNum == 0 && !escaped )
- if( !escaped ){
- goto_line(jumpNum)
- }
- } else if (selected == "p"){
- do {
- jumpNum = prompt("Page Number: ",current_line / 66 + 1)
- escaped = (and(current_key,255) == 27)
- jumpNum = atoi(jumpNum) * 66
- } while( jumpNum == 0 && !escaped )
- if( !escaped ){
- goto_line(jumpNum)
- }
- } else if (selected == "m"){
- do {
- jumpNum = prompt("Mark Number: ",pick_unused_mark() - 1)
- escaped = (and(current_key,255) == 27)
- jumpNum = atoi(jumpNum)
- } while( jumpNum == 0 && !escaped )
- if( !escaped ){
- goto_mark(jumpNum)
- }
- }
- }
-
-
- # library_menu()
- #
- # This function presents the library menu to the user. Most of
- # Word's library functions have no logical equivalent and the menu
- # is therefore rather spartan. The "Run" command, unlike Word's,
- # ALWAYS defaults to the value of the comspec variable rather than
- # the last value used. All previous values used are available,
- # however, using the prompt history mechanism (up arrow).
-
- local function library_menu(){
- local selected, cmdStr, escaped
-
- selected = tolower(mouse_confirm("Library: Autosort Run","AaRr"))
- if (selected == "a"){
- if (region_type()){
- filter("sort")
- } else {
- warning("No selection defined.")
- }
- } else if (selected == "r") {
- cmdStr = prompt_history("SYSTEM","Command Line: ",ENV["COMSPEC"])
- if (and(current_key,0x00FF) != 0x1b)
- system(cmdStr)
- }
- }
-
-
- # option_menu()
- #
- # This function allows setting of options for windows, and various
- # other features. Rather than presenting these as a screen full of
- # selections, a series of menus allows selecting of the desired
- # option. If the categories, window and general do not seem
- # logically organized, it is because it follows Word's organization
- # as much as possible. The setup() function is also thrown in here
- # rather than duplicating Word's color selection and other odds and
- # ends. Most of the options selected outside of the setup()
- # function are transient and apply only to the current session. The
- # exceptions are those things that affect window_flags when state
- # saving is in effect.
-
- local function option_menu(){
- local selected
-
- selected = tolower(mouse_confirm("OPTIONS: Window General Setup","WwGgSs"))
- if (selected == "s") {
- setup()
- } else if( selected == "g" ) {
- general_option_menu()
- } else if( selected == "w" ) {
- window_option_menu()
- }
- }
-
-
- # general_option_menu()
- #
- # This function, called by option_menu(), allows switching between
- # 25 and 43/50 line mode, setting cursor speed, as well as making
- # line numbers and borders visible.
-
- local function general_option_menu(){
- local selected
-
- selected = tolower(mouse_confirm("GENERAL OPTIONS: Display mode Cursor speed Line numbers Show borders","SsCcDdLl"))
- if (selected == "s") {
- show_borders()
- } else if( selected == "d" ) {
- set_display()
- } else if( selected == "c" ) {
- set_cursor()
- } else if( selected == "l" ) {
- show_numbers()
- }
- }
-
-
- # set_display()
- #
- # This function allows the user to select numerically between
- # display modes. No attempt is made to ensure that these modes are
- # available.
-
- local function set_display() {
- local selected
-
- selected = mouse_confirm("DISPLAY MODE: 1) 25 lines, 2) 43/50 lines","12")
- toggle_display(atoi(selected) - 1)
- }
-
-
- # set_cursor()
- #
- # This function allows selecting a cursor speed from 1 to 6. This
- # number is used to set the keyboard repeat rate on AT class
- # machines. The delay is always set to 2. Since Word allows cursor
- # speeds from 1 to 9 with 9 being the fastest, the sense of the
- # value normally supplied to keyboard_speed() is reversed. 6 is the
- # fastest and 1 is the slowest.
-
- local function set_cursor() {
- local selected
-
- selected = mouse_confirm("CURSOR SPEED: ( 1-6 )","123456")
- keyboard_speed(7-selected,2)
- }
-
-
- # show_borders()
- #
- # This function allows toggling on and off borders using a yes or no
- # prompt. The change is immediately visible. When the desired
- # state is reached, pressing [Enter] accepts that setting.
-
- local function show_borders() {
- local selected
-
- do {
- selected = tolower(mouse_confirm("SHOW BORDERS: " \
- yesno_prompt_string(and(window_flags,WINDOW_BORDER)),"YyNn\r"))
- if (and(current_key,0x00ff) != 0x1b && selected != "\r") {
- if (selected == "y") {
- toggle_borders(TRUE)
- } else if (selected == "n"){
- toggle_borders(FALSE)
- }
- }
- } while ( and(current_key,0x00ff) != 0x1b && selected != "\r")
- }
-
-
- # show_numbers()
- #
- # This function allows toggling on and off line numbers using a yes
- # or no prompt. The change is immediately visible. When the
- # desired state is reached, pressing [Enter] accepts that setting.
-
- local function show_numbers() {
- local selected
-
- do {
- selected = tolower(mouse_confirm("SHOW LINE NUMBERS: " \
- yesno_prompt_string(linenumber_format),"YyNn\r"))
- if (and(current_key,0x00ff) != 0x1b && selected != "\r") {
- if (selected == "y") {
- toggle_linenumbers(TRUE)
- } else if (selected == "n"){
- toggle_linenumbers(FALSE)
- }
- }
- } while ( and(current_key,0x00ff) != 0x1b && selected != "\r")
- }
-
-
- # yesno_prompt_string()
- #
- # This is the function that produces the yes or no string used by
- # various other prompts. A value is passed as an argument,
- # evaluates it to TRUE or FALSE and returns the appropriate string.
-
- local function yesno_prompt_string(value) {
- local yesStr = "(Yes) No ", noStr = " Yes (No) "
-
- return (value ? yesStr :noStr)
- }
-
-
- # window_option_menu()
- #
- # This function allows turning on and off the display of the ruler
- # and setting which of the non-printing symbols are made visible.
-
- local function window_option_menu(){
- local selected
-
- selected = tolower(mouse_confirm("WINDOW OPTIONS: Show ruler Non-printing symbols", \
- "NnSs"))
- if (selected == "s") {
- show_ruler()
- } else if( selected == "n" ) {
- set_symbols()
- }
- }
-
-
- # show_ruler()
- #
- # This function allows toggling on and off the ruler using a yes or
- # no prompt. The change is immediately visible. When the desired
- # state is reached, pressing [Enter] accepts that setting.
-
- local function show_ruler() {
- local selected
-
- do {
- selected = tolower(mouse_confirm("SHOW RULER: " \
- yesno_prompt_string(and( window_flags, WINDOW_RULER )),"YyNn\r"))
- if (and(current_key,0x00ff) != 0x1b && selected != "\r") {
- if (selected == "y") {
- window_flags = set_flag_bits(window_flags, \
- WINDOW_RULER, WINDOW_RULER )
- } else if (selected == "n"){
- window_flags = set_flag_bits(window_flags, \
- WINDOW_RULER, 0)
- }
- }
- } while ( and(current_key,0x00ff) != 0x1b && selected != "\r")
- }
-
-
- # set_symbols()
- #
- # This function allows selecting whether All Partial or None of the
- # non-printing symbols show on the screen using Word's symbol set.
-
- local function set_symbols() {
- local selected
-
- selected = tolower(mouse_confirm("NON-PRINTING SYMBOLS: None Partial All", \
- "NnPpAa"))
- if (selected == "n") {
- reset_visibles()
- visible_end_buffer = ""
- default_visible_end_buffer = ""
- } else if( selected == "p" ) {
- reset_visibles()
- msw_part_visibles()
- } else if( selected == "a" ) {
- reset_visibles()
- msw_visibles()
- }
- }
-
-
- # print_menu()
- #
- # This function allows the user to specify whether to print the file
- # to the print device, print it to a file or to change the print
- # device.
-
- local function print_menu() {
- local selected
-
- selected = tolower(mouse_confirm("Print: Print File Options","PpFfOo"))
- if (selected == "p") {
- print_buffer()
- } else if( selected == "f" ) {
- msw_write_file()
- } else if( selected == "o" ) {
- print_options()
- }
- }
-
-
- # print_options()
- #
- # This function displays and allows selection of the print options.
- # The only option available is to change the print device. If a
- # selection has been defined, SPE will always print just the
- # selection.
-
- local function print_options() {
- print_device = prompt("PRINT DEVICE: ",print_device)
- }
-
-
- # msw_quit()
- #
- # This is the function that executes when Quit has been selected
- # from the main menu. It checks to see that each file has been
- # written to a file, if the user desires, before exiting.
-
- function msw_quit(){
- local cw = current_window;
- local win = current_window
-
- win = next_window();
-
- do {
- next_window()
- if (buffer_is_modified()) {
- confirm_save()
- } else {
- buffer_flags = and(buffer_flags,not(BUFFER_MODIFIED))
- }
- if (and(current_key,0x00FF) == 0x1b)
- return
- } while (win != current_window)
- if (cw)
- current_window = cw;
- while (buffers_modified) {
- next_buffer()
- if (buffer_is_modified()) {
- confirm_save()
- } else {
- buffer_flags = and(buffer_flags,not(BUFFER_MODIFIED))
- }
- if (and(current_key,0x00FF) == 0x1b)
- return
- }
- quit()
- }
-
-
- # replace_menu()
- #
- # This function obtains the search and replacement strings and
- # options.
-
- local function replace_menu(){
- local searchStr, replaceStr
-
- searchStr = prompt_history("SEARCH","Replace: ","")
- if ( and(current_key,0x00FF) != 0x1b && searchStr != "") {
- replaceStr = prompt_history("REPLACE","With: ","")
- if ( and(current_key,0x00FF) != 0x1b) {
- if (search_options()){
- if (and(search_flags,SEARCH_FORWARD))
- replace_forward(searchStr,replaceStr)
- else
- replace_backward(searchStr,replaceStr)
- }
- }
- }
- }
-
-
- # search_prompt_string()
- #
- # This function returns a string for display which indicates case
- # sensitivity and direction of such as currently specified by the
- # search_flags variable.
-
- local function search_prompt_string(){
- local forwardStr = "(Forward) Backward ", backStr = " Forward (Backward) ", \
- ignoreStr = "(Ignore) Sensitive ", sensitiveStr = " Ignore (Sensitive) ", \
- promptStr = "Direction: "
-
- promptStr = promptStr (and(search_flags,SEARCH_FORWARD) \
- ? forwardStr \
- : backStr) " Case: " \
- (and(search_flags,SEARCH_IGNORE_CASE) \
- ? ignoreStr \
- : sensitiveStr)
- return promptStr
- }
-
-
- # search_options()
- #
- # This function displays the current settings of the search flags
- # with regard to direction and case sensitivity, and allows the user
- # to change the settings. The user accepts the current settings by
- # pressing [Enter].
-
- local function search_options(){
- local selected, save_level = message_level
-
- message_level = 2
- do {
- selected = tolower(confirm(search_prompt_string(),"SsBbIiFf\r"))
- if (and(current_key,0x00ff) != 0x1b && selected != "\r") {
- if (selected == "f") {
- toggle_search_forward(TRUE)
- } else if (selected == "b"){
- toggle_search_forward(FALSE)
- } else if (selected == "i"){
- toggle_search_case(TRUE)
- } else if (selected == "s"){
- toggle_search_case(FALSE)
- }
- }
- } while ( and(current_key,0x00ff) != 0x1b && selected != "\r")
- if (region_type())
- toggle_search_block(TRUE)
- else
- toggle_search_block(FALSE)
- message_level = save_level
- return ( and(current_key,0x00ff) != 0x1b )
- }
-
-
- # search_menu()
- #
- # This function collects the search string and options.
-
- local function search_menu(){
- local searchStr, repaceStr, found
-
- searchStr = prompt_history("SEARCH","Search for: ","")
- if ( and(current_key,0x00FF) != 0x1b && searchStr != "") {
- if (search_options()) {
- if (and(search_flags,SEARCH_FORWARD))
- found = search_forward(searchStr)
- else
- found = search_backward(searchStr)
- if ( found )
- attach_event_handler(EVENT_KEYPRESS, \
- function_id("msw_search_restore"))
- }
- }
- }
-
-
- # transfer_menu()
- #
- # This function presents the user with the transfer menu to allow
- # loading saving and merging files.
-
- local function transfer_menu(){
- local selected, escaped, OutputName
-
- selected = tolower(mouse_confirm("Transfer: Load Merge Save","LlMmSs"))
- if (selected == "l"){
- edit_file_key()
- } else if( selected == "m" ){
- read_file_key()
- }
- if( selected == "s" ){
- OutputName = prompt_history("TRANSFER","Transfer Save: ", buffer_filename)
- if ( and(current_key,0x00FF) != 0x1b ) {
- buffer_filename = OutputName
- buffer_name = path_fname(buffer_filename) \
- path_ext(buffer_filename)
- msw_save_buffer()
- }
- }
- }
-
-
- # window_menu()
- #
- # This function provides access to various windowing functions. The
- # user can split the current window to create a new one, close it or
- # move it.
-
- local function window_menu(){
- local selected, escaped, orient, where, pstr
-
- selected = tolower(mouse_confirm("Window: Split Close Move","CcSsMm"))
- if (selected == "c"){
- if (buffer_views() == 1) {
- if (buffer_is_modified())
- confirm_save()
- if ( and(current_key,0x00FF) != 0x1b )
- delete_buffer()
- }
- if ( and(current_key,0x00FF) != 0x1b )
- delete_tiled_window()
- } else if( selected == "s" ){
- orient = tolower(mouse_confirm("Window Split: Horizontal Vertical","HhVv"))
- escaped = ( and(current_key,0x00FF) == 0x1b )
- if( !escaped ){
- pstr = (orient == "h") ? "At line: " : "At column: "
- do {
- where = prompt(pstr,"")
- escaped = ( and(current_key,0x00FF) == 0x1b )
- where = atoi(where)
- } while (where == 0 && !escaped)
- if( !escaped ){
- if (orient == "h"){
- split_window_horizontal(where)
- } else
- split_window_vertical(where)
- }
- }
- } else
- if (selected == "m") {
- adjust_window()
- }
- }
-
-
- # msw_toggle_inclusive_block
- #
- # This is the function that allows the user to make EXTENDED
- # selctions.
-
- function msw_toggle_inclusive_block(){
- if( region_type() == INCLUSIVE_SELECTION){
- if (extended) {
- raise_anchor()
- extended = FALSE
- } else {
- extended = TRUE
- }
- } else {
- if (!region_type()) {
- set_inclusive_mark()
- extended = TRUE
- } else
- raise_anchor()
- }
- }
-
-
- # msw_toggle_column_block()
- #
- # This function allows toggling a column selection on or off.
-
- function msw_toggle_column_block(){
- if( region_type() == COLUMN_SELECTION){
- raise_anchor()
- extended = FALSE
- } else {
- set_column_mark()
- extended = TRUE
- }
- }
-
-
- # msw_reverse()
- #
- # This function allows changing the case of a character or
- # selection.
-
- function msw_reverse() {
-
- if ( region_type() ) {
- reverse()
- } else {
- drop_anchor(INCLUSIVE_SELECTION)
- reverse()
- raise_anchor()
- }
- }
-
-
- # confirm_save()
- #
- # This function asks the user if he or she wishes to save the
- # changes to the current buffer. The user may elect to save, not
- # save, or bail out.
-
- function confirm_save() {
- if (toupper(mouse_confirm(sprintf("%s not saved. Enter Y to save, N to lose changes, Esc to cancel",
- buffer_name),"YyNn")) == "Y") {
- msw_save_buffer()
- } else {
- if (and(current_key,0x00FF) != 0x1b)
- buffer_flags = and(buffer_flags,not(BUFFER_MODIFIED))
- else
- return FALSE
- }
- return TRUE
- }
-
-
- # msw_save_buffer()
- #
- # This function displays the file size after saving the file to
- # disk.
-
- function msw_save_buffer() {
- if (filemode(buffer_filename) != -1 && buffer_is_modified())
- backup_file(buffer_filename)
- write_buffer()
- message("%d bytes saved",filesize(buffer_filename))
- }
-
-
- # msw_part_visibles()
- #
- # This function sets the primary non-printing characters
-
- function msw_part_visibles() {
- default_visible_newlines = ""
- default_visible_end_buffer = ""
- visible_newlines = ""
- visible_end_buffer = ""
- }
-
-
- # msw_visibles()
- #
- # This function sets all of the non-printing characters displayed by
- # Word.
-
- function msw_visibles(){
- msw_part_visibles()
- default_visible_spaces = "·"
- default_visible_tabs = ""
- visible_spaces = "·"
- visible_tabs = ""
- }
-
-
- # msw_check_key()
- #
- # This function is an event handler to check each key that is
- # pressed. If the key is bound to the insert_key() function the
- # block marking is removed. This means largely ASCII keys will have
- # this action.
-
- function msw_check_key(){
- if (region_type() == 1)
- if (keymap_binding(int_to_key(current_key)) == "insert_key")
- raise_anchor()
- }
-
-
- # msw_next_word()
- #
- # This function not only moves to the next word, it also highlights
- # it. It honors an extended selection, as well.
-
- function msw_next_word(){
- local words = 2
-
- if (!region_type()){
- words = 1
- }
- else
- if (!extended) {
- if ( prev_command == function_id("msw_prev_word"))
- words = 1
- raise_anchor()
- }
- if (!region_type()) {
- next_word(words,wordDefStr)
- set_exclusive_mark()
- prev_word(1,wordDefStr)
- } else
- next_word(1,wordDefStr)
- }
-
-
- # msw_next_word()
- #
- # This function not only moves to the next word, it also highlights
- # it. It honors an extended selection, as well.
-
- function msw_prev_word(){
- local words = 2
-
- if (!region_type() ){
- words = 1
- }
- else
- if (!extended) {
- if (prev_command == function_id("msw_next_word"))
- words = 1
- raise_anchor()
- }
- if (!region_type()) {
- prev_word(words,wordDefStr)
- set_exclusive_mark()
- next_word(1,wordDefStr)
- } else
- prev_word(1,wordDefStr)
- }
-
-
- # msw_restore()
- #
- # This function is an event handler to restore things to their
- # previous or vanilla state when the user changes emulations.
-
- function msw_restore(){
- mouse_selection_type = previous_mst
- default_window_flags = previous_win_flags
- delete_event(EVENT_KEYPRESS,function_id("msw_check_key"))
- delete_event(EVENT_EMULATION_CHANGED,function_id("msw_restore"))
- reset_visibles()
- }
-
-
- # msw_left()
- #
- # This function moves left unless it is at the beginning of the
- # line. In that case it moves to the last character of the
- # preceding line.
-
- function msw_left(){
- if (current_column == 1)
- prev_char()
- else
- left()
- }
-
-
- # msw_right()
- #
- # This function moves right unless it is at the end of the line. In
- # that case it moves to the first character of the preceding line.
-
- function msw_right(){
- if (current_column > current_line_width)
- next_char()
- else
- right()
- }
-
-
- # msw_up()
- #
- # This function moves the cursor to the preceding line. If the
- # cursor is positioned beyond the end of the line, it moves to the
- # end of the line.
-
- local line_position = 0
-
- function msw_up(){
- local line_length
-
- up()
- line_length = current_line_width + 1
- if (prev_key == current_key){
- current_column = ( line_position > line_length) ? \
- line_length : line_position
- } else {
- line_position = current_column
- if (current_column > line_length)
- current_column = line_length
- }
- }
-
-
- # msw_down()
- #
- # This function moves the cursor to the following line. If the
- # cursor is positioned beyond the end of the line, it moves to the
- # end of the line.
-
- function msw_down(){
- local line_length
-
- down()
- line_length = current_line_width + 1
- if (prev_key == current_key){
- current_column = ( line_position > line_length) ? \
- line_length : line_position
- } else {
- line_position = current_column
- if (current_column > line_length)
- current_column = line_length
- }
- }
-
-
- # mouse_confirm()
- #
- # This function is like the confirm() function except that it allows
- # mouse input to indicate the desired response.
-
- function mouse_confirm(promptStr, keyStr)
- {
- local ch, ok, old_win
-
- message(promptStr)
- do {
- ch = getkey()
- if ((ch == LEFT_PRESS || ch == LEFT_CLICK) && dialog_window){
- old_win = current_window
- current_window = dialog_window
- if (mouse_event_y == window_y0){
- ch = cap_near_mouse()
- }
- if (old_win)
- current_window = old_win
- flush_keyboard()
- } else {
- ch = chr(and(ch,0x00ff))
- }
- if (!(ok = cindex(keyStr chr(0x1b),ch)))
- beep()
- } while (!ok)
- if (ch == chr(0x1b))
- message("Command canceled.")
- else
- message("")
- return ch
- }
-
-
- # cap_near_mouse()
- #
- # This function looks for an uppercase character or digit at or
- # preceding the position where the mouse was clicked. It returns
- # that character if found and gives up (returning null string) if a
- # colon or beginning or the screen is reached.
-
- function cap_near_mouse(){
- local ch, x_loc
-
- x_loc = mouse_event_x
- do {
- window_cursor_x = x_loc
- ch = read_window(1)
- x_loc--
- } while (ch != ":" && x_loc > window_x0 && !isupper(ch) && !isdigit(ch))
- if (isupper(ch) || isdigit(ch))
- return ch
- else
- return ""
- }
-
-
- # msw_write_file()
- #
- # This function is used by the Print File option to allow printing
- # the current contents of the buffer to a different filename without
- # saving the buffer to its original file or changing the original
- # filename.
-
- function msw_write_file(){
- local filename, ok
-
- filename = prompt("Write to file: ")
- if (filemode(filename) == -1) {
- ok = mouse_confirm("File exists. Enter Y to overwrite N to abandon." \
- "YyNn")
- if (tolower(ok) == "n")
- return
- }
- message("%d bytes written.",write_buffer(filename))
- }
-
- function msw_search_restore(){
- delete_event(EVENT_KEYPRESS,function_id("msw_search_restore"))
- raise_anchor()
- }
-
-
- function msw_search_again() {
- if ( search_again() )
- display_update()
- attach_event_handler(EVENT_KEYPRESS, \
- function_id("msw_search_restore"))
- }