% jltools.sl -*- SLang -*- % % Defines some Jed/IDE tools. For Jed 0.99.16 % % Written by Jørgen Larsen % % Last modified: 2003/1/30 % % -------------------------------------------------------------------------------- % The following public functions are defined: % % jl_function_help display the Jed/SLang help text for the item at the cursor. % % open_file_at_cursor Switch to the buffer associated with the file % whose name the cursor points to. % % ide_mark_matching Place the cursor on a delimiter and call `ide_mark_matching()'. % Then use the pair of matching delimiters to define a region. % (Adapted from php_mark_matching ().) % % % xform_region_or_word if no region is defined then let current word be a region; % then apply xform_region (from site.sl) % % % set_project_file Define a project file (PF). % find_project_file Switch to the buffer with the PF. % % A PF is a text file which contains the names of the files % that you use in a given project (the PF can contain lots % of other informations than just file names). If the % functions `find_project_file' and `open_file_at_cursor' % are bound to easy key combinations, you now have a fast % and efficient method for switching to any file associated % with your current project. % % % The following functions are redefined: % % ide_page_up Tries to have the cursor stay at the same position on the screen. % ide_page_down do. % % ide_skip_word Redefined so that they use the definition of % ide_bskip_word a "word" from the codepage file. % ide_delete_word % ide_bdelete_word % ide_select_word (doesn't print a message!) % % % ide_uppercase_region redefined using xform_region_or_word % ide_lowercase_region % capitalize_word % % % ------------------------------------------------------------------------------- % % setkey ("enlargewin", "\e+"); % Alt-+ (or ESC-+) setkey ("evaluate_cmd", "\eZ"); % SLang command setkey ("emacs_escape_x", "\eX"); % Alt-X (or ESC-X); default: emacs_escape_x = \ex ! % Key definitons for operations on rectangles. % Key combinations Alt-KH Alt-KC and Alt-KY (or ESC-KH ESC-KC and ESC-KY) % have similar meanings for rectangles % as Ctrl-KH Ctrl-KC and Ctrl-KY have for regions: setkey ("copy_rect", "\eKH"); % Alt-KH setkey ("insert_rect", "\eKC"); % Alt-KC setkey ("kill_rect", "\eKY"); % Alt-KY setkey ("open_rect", "\eK "); % Alt-KSpace setkey ("double_line", Key_F12); setkey ("jl_function_help", Key_Ctrl_F1); % Ctrl-F1 setkey ("open_file_at_cursor", "\e^M"); % Alt-Return (or ESC-Return) setkey ("find_project_file", "^Q^Q"); % Ctrl-QQ setkey ("find_project_file", "^QQ"); setkey ("set_project_file", "^Q^P"); % Ctrl-QP setkey ("ide_mark_matching", "^K^M"); % Ctrl-KM setkey ("ide_mark_matching", "^KM"); setkey ("goto_match", "^Q^M"); % Ctrl-QM setkey ("goto_match", "^QM"); % ( goto_match is also bound to Ctrl-\ ) require ("searchx"); setkey ("searchx (1)", "^QF"); % Ctrl-QF is search forward setkey ("searchx (1)", "^Q^F"); setkey ("searchx (-1)", "^Qf"); % Ctrl-Q f is search backward setkey ("searchx_toggle", "^Q^L"); setkey ("searchx_toggle", "^QL"); setkey ("repeat_searchx", "^L"); setkey ("replacex", "^Q^A"); setkey ("replacex", "^QA"); #ifdef UNIX setkey ("newline", "\eOM"); % ESC O M = NumericKeyPadEnter #endif % % ------------------------------------------------------------------------------- % Defining/redefining functions: % New versions of page_up and page_down: % % Ideally the cursor should stay at the same position on the screen; % this is but a crude approximation ... define ide_page_down () % Key_PgDown { ide_set_bookmark (); variable row = what_line; variable col = what_column (); call ("page_down"); goto_line (row + window_info ('r') - 1 ); () = goto_column_best_try (col); } define ide_page_up () % Key_PgUp { ide_set_bookmark (); variable row = what_line; variable col = what_column (); call ("page_up"); goto_line (row - window_info ('r') + 1 ); () = goto_column_best_try (col); } public define ide_mark_matching () % ^K^M { push_spot (); if ( find_matching_delimiter (0) ) { pop_spot (); push_visible_mark (); () = find_matching_delimiter (0); check_region (0); () = find_matching_delimiter (0); ide_begin_block (); () = find_matching_delimiter (0); go_right_1 (); } else pop_spot (); } %% %% Redefinitions of the commands for skipping and deleting words: %% % ide_skip_word should move the cursor % to the first "letter" of the next word: public define ide_skip_word () % ^F { variable p = _get_point (); skip_word_chars (); skip_non_word_chars (); if (_get_point () == p) skip_chars ("\t\n "); } % and ide_bskip_word should be the opposite of "ide_skip_word": public define ide_bskip_word () % ^A { variable p = _get_point (); bskip_non_word_chars (); bskip_word_chars (); if (_get_point () == p) bskip_chars ("\n\t "); } % ide_delete_word should delete trailing spaces: public define ide_delete_word () % ^T { variable p = _get_point (), l = what_line (); push_mark (); skip_word_chars (); skip_chars (" "); if (_get_point () == p) skip_chars ("\t\n "); if ((_get_point () == p) and (what_line () ==l)) go_right_1; del_region (); } % similarly for ide_bdelete_word : public define ide_bdelete_word () % Alt-BkSp { variable p = _get_point (); push_mark (); bskip_word_chars (); bskip_chars (" "); if (_get_point () == p) bskip_chars ("\n\t "); if (_get_point () == p) go_left_1; del_region (); } % this function returns 1 if the current char is a word char (and 0 otherwise): static define word_char_p () { push_spot (); what_column (); skip_word_chars (); ( ) != what_column (); pop_spot (); } public define ide_select_word () % ^KT, Borland IDE facility { !if (word_char_p ()) return; bskip_word_chars (); ide_begin_block (); skip_word_chars (); ide_end_block (); } % modified from site.sl public define xform_region_or_word () % parameter on stack { push_spot (); if (markp ()) { xform_region (( )); } else if (word_char_p ()) { bskip_word_chars (); push_mark (); skip_word_chars (); xform_region (( )); } pop_spot (); } public define ide_uppercase_region () % ^KU { xform_region_or_word ('u'); } public define ide_lowercase_region () % ^KL { xform_region_or_word ('d'); } public define capitalize_word () { xform_region_or_word ('c'); } %% This function returns the "word" which the cursor points to. %% A "word" consists of symbols from the alphabet `s' static define get_chars_at_cursor (s) { push_spot (); bskip_chars (s); % left limit push_mark (); skip_chars (s); % right limit bufsubstr (); % this is the return value pop_mark_0 (); pop_spot (); } %% This function displays the help text for the S-Lang/Jed function %% whose name the cursor points to. %% public define jl_function_help () % IDE keybinding: Ctrl-F1 { help_for_function (get_chars_at_cursor ("-0-9a-zA-Z_")); } %% This function switches to the buffer associated %% with the file whose name the cursor is pointing to. public define open_file_at_cursor () % IDE keybinding: Alt-Return { variable fn, dir; (,dir,,) = getbuf_info (); #ifdef UNIX fn = expand_filename (dir + get_chars_at_cursor ("-0-9a-zA-Z_!%+~./")); "/"; #else fn = expand_filename (dir + get_chars_at_cursor ("-0-9a-zA-Z_!%+~./:\\")); "\\:"; #endif !if (1 == file_status (fn)) error (strcat ("File ",fn," not found")); () = find_file (fn); } %% Variables and functions for easy management of "project files": %% %% the variable `project_file_name' holds the name of the current project file static variable project_file_name = ""; define set_project_file (); % preliminary definition %% This function switches to the buffer with the current project file %% (or it prompts for a name). %% The function should be bound to an easy key combination. public define find_project_file () % IDE keybinding: ^Q^Q { if (strlen (project_file_name)) { () = find_file (project_file_name); message (strcat ("Project file ", project_file_name)); } else set_project_file (); } %% This function prompts for a project file name. public define set_project_file () % IDE keybinding: ^Q^P { project_file_name = read_with_completion ("Set project file:", "", "", 'f'); find_project_file (); } provide ("jltools");