infomap.c revision 21495
1581Srgrimes/* infomap.c -- Keymaps for Info. */ 2581Srgrimes 3581Srgrimes/* This file is part of GNU Info, a program for reading online documentation 4581Srgrimes stored in Info format. 5581Srgrimes 6581Srgrimes Copyright (C) 1993 Free Software Foundation, Inc. 7581Srgrimes 8581Srgrimes This program is free software; you can redistribute it and/or modify 9581Srgrimes it under the terms of the GNU General Public License as published by 10581Srgrimes the Free Software Foundation; either version 2, or (at your option) 11581Srgrimes any later version. 12581Srgrimes 13581Srgrimes This program is distributed in the hope that it will be useful, 14581Srgrimes but WITHOUT ANY WARRANTY; without even the implied warranty of 15581Srgrimes MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16581Srgrimes GNU General Public License for more details. 17581Srgrimes 18581Srgrimes You should have received a copy of the GNU General Public License 19581Srgrimes along with this program; if not, write to the Free Software 20581Srgrimes Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21581Srgrimes 22581Srgrimes Written by Brian Fox (bfox@ai.mit.edu). */ 23581Srgrimes 24581Srgrimes#include "stdio.h" 25581Srgrimes#include "ctype.h" 26581Srgrimes#include "infomap.h" 27581Srgrimes#include "funs.h" 28581Srgrimes 29581Srgrimes/* Return a new keymap which has all the uppercase letters mapped to run 30581Srgrimes the function info_do_lowercase_version (). */ 31581SrgrimesKeymap 32581Srgrimeskeymap_make_keymap () 33581Srgrimes{ 34581Srgrimes register int i; 35581Srgrimes Keymap keymap; 36581Srgrimes 37581Srgrimes keymap = (Keymap)xmalloc (256 * sizeof (KEYMAP_ENTRY)); 38581Srgrimes 39581Srgrimes for (i = 0; i < 256; i++) 40581Srgrimes { 41581Srgrimes keymap[i].type = ISFUNC; 42581Srgrimes keymap[i].function = (VFunction *)NULL; 43581Srgrimes } 44581Srgrimes 45581Srgrimes for (i = 'A'; i < ('Z' + 1); i++) 46581Srgrimes { 47581Srgrimes keymap[i].type = ISFUNC; 48581Srgrimes keymap[i].function = info_do_lowercase_version; 49581Srgrimes } 50581Srgrimes 51581Srgrimes return (keymap); 52581Srgrimes} 53581Srgrimes 54581Srgrimes/* Return a new keymap which is a copy of MAP. */ 55581SrgrimesKeymap 56581Srgrimeskeymap_copy_keymap (map) 57581Srgrimes Keymap map; 58581Srgrimes{ 59581Srgrimes register int i; 60581Srgrimes Keymap keymap; 61581Srgrimes 62581Srgrimes keymap = keymap_make_keymap (); 63581Srgrimes 64581Srgrimes for (i = 0; i < 256; i++) 65581Srgrimes { 66581Srgrimes keymap[i].type = map[i].type; 67581Srgrimes keymap[i].function = map[i].function; 68581Srgrimes } 69581Srgrimes return (keymap); 70581Srgrimes} 71581Srgrimes 72581Srgrimes/* Free the keymap and it's descendents. */ 73581Srgrimesvoid 74581Srgrimeskeymap_discard_keymap (map) 75581Srgrimes Keymap (map); 76581Srgrimes{ 77581Srgrimes register int i; 78581Srgrimes 79581Srgrimes if (!map) 80581Srgrimes return; 81581Srgrimes 82581Srgrimes for (i = 0; i < 256; i++) 83581Srgrimes { 84581Srgrimes switch (map[i].type) 85581Srgrimes { 86581Srgrimes case ISFUNC: 87581Srgrimes break; 88581Srgrimes 89581Srgrimes case ISKMAP: 90581Srgrimes keymap_discard_keymap ((Keymap)map[i].function); 91581Srgrimes break; 92581Srgrimes 93581Srgrimes } 94581Srgrimes } 95581Srgrimes} 96581Srgrimes 97581Srgrimes/* Initialize the standard info keymaps. */ 98581Srgrimes 99581SrgrimesKeymap info_keymap = (Keymap)NULL; 100581SrgrimesKeymap echo_area_keymap = (Keymap)NULL; 101581Srgrimes 102581Srgrimesvoid 103581Srgrimesinitialize_info_keymaps () 104581Srgrimes{ 105581Srgrimes register int i; 106581Srgrimes Keymap map; 107581Srgrimes 108581Srgrimes if (!info_keymap) 109581Srgrimes { 110581Srgrimes info_keymap = keymap_make_keymap (); 111581Srgrimes info_keymap[ESC].type = ISKMAP; 112581Srgrimes info_keymap[ESC].function = (VFunction *)keymap_make_keymap (); 113581Srgrimes info_keymap[Control ('x')].type = ISKMAP; 114581Srgrimes info_keymap[Control ('x')].function = (VFunction *)keymap_make_keymap (); 115581Srgrimes echo_area_keymap = keymap_make_keymap (); 116581Srgrimes echo_area_keymap[ESC].type = ISKMAP; 117581Srgrimes echo_area_keymap[ESC].function = (VFunction *)keymap_make_keymap (); 118581Srgrimes echo_area_keymap[Control ('x')].type = ISKMAP; 119581Srgrimes echo_area_keymap[Control ('x')].function = 120581Srgrimes (VFunction *)keymap_make_keymap (); 121581Srgrimes } 122581Srgrimes 123581Srgrimes /* Bind numeric arg functions for both echo area and info window maps. */ 124581Srgrimes for (i = '0'; i < '9' + 1; i++) 125581Srgrimes { 126581Srgrimes ((Keymap) info_keymap[ESC].function)[i].function = 127581Srgrimes ((Keymap) echo_area_keymap[ESC].function)[i].function = 128581Srgrimes info_add_digit_to_numeric_arg; 129581Srgrimes } 130581Srgrimes ((Keymap) info_keymap[ESC].function)['-'].function = 131581Srgrimes ((Keymap) echo_area_keymap[ESC].function)['-'].function = 132581Srgrimes info_add_digit_to_numeric_arg; 133581Srgrimes 134581Srgrimes /* Bind the echo area routines. */ 135581Srgrimes map = echo_area_keymap; 136581Srgrimes 137581Srgrimes /* Bind the echo area insert routines. */ 138581Srgrimes for (i = 0; i < 160; i++) 139581Srgrimes if (isprint (i)) 140581Srgrimes map[i].function = ea_insert; 141581Srgrimes 142581Srgrimes map[Control ('a')].function = ea_beg_of_line; 143581Srgrimes map[Control ('b')].function = ea_backward; 144581Srgrimes map[Control ('d')].function = ea_delete; 145581Srgrimes map[Control ('e')].function = ea_end_of_line; 146581Srgrimes map[Control ('f')].function = ea_forward; 147581Srgrimes map[Control ('g')].function = ea_abort; 148581Srgrimes map[Control ('h')].function = ea_rubout; 149581Srgrimes map[Control ('k')].function = ea_kill_line; 150581Srgrimes map[Control ('l')].function = info_redraw_display; 151581Srgrimes map[Control ('q')].function = ea_quoted_insert; 152581Srgrimes map[Control ('t')].function = ea_transpose_chars; 153581Srgrimes map[Control ('u')].function = info_universal_argument; 154581Srgrimes map[Control ('y')].function = ea_yank; 155581Srgrimes 156581Srgrimes map[LFD].function = ea_newline; 157581Srgrimes map[RET].function = ea_newline; 158581Srgrimes map[SPC].function = ea_complete; 159581Srgrimes map[TAB].function = ea_complete; 160581Srgrimes map['?'].function = ea_possible_completions; 161581Srgrimes map[DEL].function = ea_rubout; 162581Srgrimes 163581Srgrimes /* Bind the echo area ESC keymap. */ 164581Srgrimes map = (Keymap)echo_area_keymap[ESC].function; 165581Srgrimes 166581Srgrimes map[Control ('g')].function = ea_abort; 167581Srgrimes map[Control ('v')].function = ea_scroll_completions_window; 168581Srgrimes map['b'].function = ea_backward_word; 169581Srgrimes map['d'].function = ea_kill_word; 170581Srgrimes map['f'].function = ea_forward_word; 171581Srgrimes#if defined (NAMED_FUNCTIONS) 172581Srgrimes /* map['x'].function = info_execute_command; */ 173581Srgrimes#endif /* NAMED_FUNCTIONS */ 174581Srgrimes map['y'].function = ea_yank_pop; 175581Srgrimes map['?'].function = ea_possible_completions; 176581Srgrimes map[TAB].function = ea_tab_insert; 177581Srgrimes map[DEL].function = ea_backward_kill_word; 178581Srgrimes 179581Srgrimes /* Bind the echo area Control-x keymap. */ 180581Srgrimes map = (Keymap)echo_area_keymap[Control ('x')].function; 181581Srgrimes 182581Srgrimes map['o'].function = info_next_window; 183581Srgrimes map[DEL].function = ea_backward_kill_line; 184581Srgrimes 185581Srgrimes /* Bind commands for Info window keymaps. */ 186581Srgrimes map = info_keymap; 187581Srgrimes map[TAB].function = info_move_to_next_xref; 188581Srgrimes map[LFD].function = info_select_reference_this_line; 189581Srgrimes map[RET].function = info_select_reference_this_line; 190581Srgrimes map[SPC].function = info_scroll_forward; 191581Srgrimes map[Control ('a')].function = info_beginning_of_line; 192581Srgrimes map[Control ('b')].function = info_backward_char; 193581Srgrimes map[Control ('e')].function = info_end_of_line; 194581Srgrimes map[Control ('f')].function = info_forward_char; 195581Srgrimes map[Control ('g')].function = info_abort_key; 196581Srgrimes map[Control ('h')].function = info_get_help_window; 197581Srgrimes map[Control ('l')].function = info_redraw_display; 198581Srgrimes map[Control ('n')].function = info_next_line; 199581Srgrimes map[Control ('p')].function = info_prev_line; 200581Srgrimes map[Control ('r')].function = isearch_backward; 201581Srgrimes map[Control ('s')].function = isearch_forward; 202581Srgrimes map[Control ('u')].function = info_universal_argument; 203581Srgrimes map[Control ('v')].function = info_scroll_forward; 204581Srgrimes map[','].function = info_next_index_match; 205581Srgrimes 206581Srgrimes for (i = '1'; i < '9' + 1; i++) 207581Srgrimes map[i].function = info_menu_digit; 208581Srgrimes map['0'].function = info_last_menu_item; 209581Srgrimes 210581Srgrimes map['<'].function = info_first_node; 211581Srgrimes map['>'].function = info_last_node; 212581Srgrimes map['?'].function = info_get_help_window; 213581Srgrimes map['['].function = info_global_prev_node; 214581Srgrimes map[']'].function = info_global_next_node; 215581Srgrimes 216581Srgrimes map['b'].function = info_beginning_of_node; 217581Srgrimes map['d'].function = info_dir_node; 218581Srgrimes map['e'].function = info_end_of_node; 219581Srgrimes map['f'].function = info_xref_item; 220581Srgrimes map['g'].function = info_goto_node; 221581Srgrimes map['h'].function = info_get_info_help_node; 222581Srgrimes map['i'].function = info_index_search; 223581Srgrimes map['l'].function = info_history_node; 224581Srgrimes map['m'].function = info_menu_item; 225581Srgrimes map['n'].function = info_next_node; 226581Srgrimes map['p'].function = info_prev_node; 227581Srgrimes map['q'].function = info_quit; 228581Srgrimes map['r'].function = info_xref_item; 229581Srgrimes map['s'].function = info_search; 230581Srgrimes map['t'].function = info_top_node; 231581Srgrimes map['u'].function = info_up_node; 232581Srgrimes map[DEL].function = info_scroll_backward; 233581Srgrimes 234581Srgrimes /* Bind members in the ESC map for Info windows. */ 235581Srgrimes map = (Keymap)info_keymap[ESC].function; 236581Srgrimes map[Control ('f')].function = info_show_footnotes; 237581Srgrimes map[Control ('g')].function = info_abort_key; 238581Srgrimes map[TAB].function = info_move_to_prev_xref; 239581Srgrimes map[Control ('v')].function = info_scroll_other_window; 240581Srgrimes map['<'].function = info_beginning_of_node; 241581Srgrimes map['>'].function = info_end_of_node; 242581Srgrimes map['b'].function = info_backward_word; 243581Srgrimes map['f'].function = info_forward_word; 244581Srgrimes map['r'].function = info_move_to_window_line; 245581Srgrimes map['v'].function = info_scroll_backward; 246581Srgrimes#if defined (NAMED_FUNCTIONS) 247581Srgrimes map['x'].function = info_execute_command; 248581Srgrimes#endif /* NAMED_FUNCTIONS */ 249581Srgrimes 250581Srgrimes /* Bind members in the Control-X map for Info windows. */ 251581Srgrimes map = (Keymap)info_keymap[Control ('x')].function; 252581Srgrimes 253581Srgrimes map[Control ('b')].function = list_visited_nodes; 254581Srgrimes map[Control ('c')].function = info_quit; 255581Srgrimes map[Control ('f')].function = info_view_file; 256581Srgrimes map[Control ('g')].function = info_abort_key; 257581Srgrimes map[Control ('v')].function = info_view_file; 258581Srgrimes map['0'].function = info_delete_window; 259581Srgrimes map['1'].function = info_keep_one_window; 260581Srgrimes map['2'].function = info_split_window; 261581Srgrimes map['^'].function = info_grow_window; 262581Srgrimes map['b'].function = select_visited_node; 263581Srgrimes map['k'].function = info_kill_node; 264581Srgrimes map['o'].function = info_next_window; 265581Srgrimes map['t'].function = info_tile_windows; 266581Srgrimes map['w'].function = info_toggle_wrap; 267581Srgrimes} 268581Srgrimes 269581Srgrimes/* Strings which represent the sequence of characters that the arrow keys 270581Srgrimes produce. If these keys begin with ESC, and the second character of the 271581Srgrimes sequence does not conflict with an existing binding in the Meta keymap, 272581Srgrimes then bind the keys to do what C-p, C-n, C-f, and C-b do. */ 273581Srgrimesextern char *term_ku, *term_kd, *term_kr, *term_kl; 274581Srgrimes 275581Srgrimes