home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / edt.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  12.8 KB  |  485 lines

  1. %% EDT emulation for JED  -- Application Keypad.
  2. %%
  3. %%  To load this, put the line:  "edt.sl" evalfile
  4. %%   in your jed.rc (.jedrc) file
  5. %%
  6. %% Here the user gets to choose the action of the 'subs' key (Gold-enter)
  7. %% By default, it behaves as EDT.  By putting the next line in JED.RC, this
  8. %% key is bound to a more conventional query replace
  9. %% setkey ("replace_cmd",    "^[OP^[OM");  %% subs (query replace)
  10. %%
  11. %% The default binding for the quote keys (", ') is 'text_smart_quote'.
  12. %% Most users do not seem to like this so it is unset here.
  13.   setkey("self_insert_cmd",    "\"");
  14.   setkey("self_insert_cmd",    "'");
  15. %%
  16. %% In addition, if you want the ^H key to move to the beginning of line
  17. %% then uncomment the next two lines.
  18. %    unsetkey("^H");
  19. %  setkey("beg_of_line",    "^H");  %% beginning of line
  20. %% By default, these are bound
  21. %% to help functions (man page, etc...).
  22.  
  23. %% conventional subs key definition:
  24.   setkey("edt_subs",    "^[OP^[OM");  %% subs (edt style)
  25.  
  26. #ifdef MSDOS OS2
  27. NUMLOCK_IS_GOLD = 1; %% This sets the numlock key on the 'application keypad'
  28. #endif
  29.  
  30.   set_status_line("(Jed %v) EDT: %b   (%m%a%n%o)  %p,%c   Advance   %t", 1);
  31.  
  32. %%
  33. %% Escape sequences for EDT keypad:
  34. %%
  35. %% FP1 = ^[OP       FP2 = ^[OQ      FP3 = ^[OR       PF4 = ^[OS
  36. %%   7 = ^[Ow         8 = ^[Ox        9 = ^[Oy         - = ^[Om
  37. %%   4 = ^[Ot         5 = ^[Ou        6 = ^[Ov         , = ^[Ol
  38. %%   1 = ^[Oq         2 = ^[Or        3 = ^[Os
  39. %%            0 = ^[Op            . = ^[On         enter = ^[OM
  40.  
  41. WANT_EOB = 1;
  42. #ifdef UNIX VMS
  43.   tt_send("\e=");   % turn on application keypad
  44. #endif
  45.  
  46. !if (is_defined("Edt_Loaded"))
  47.    variable Edt_Loaded;
  48.    variable edt_pbuf;    %% a real buffer
  49.    edt_pbuf = " <edt>";
  50.    whatbuf();
  51.    setbuf(edt_pbuf);
  52.    sw2buf(());
  53.  
  54.  
  55. %% unset some of default jed keys--- lose window capability on "^W" one
  56. %% unsetkey ("^W");
  57. %% setkey ("redraw", "^W");
  58.  
  59. %% unsetkey("^K"); unsetkey %%-- unset this, we lose kill line in emacs.sl
  60. unsetkey("^U");             %% emacs.sl rebinds this to digit-arg
  61.  
  62. %% Give user ability to exit via GOLD-Q, GOLD-E
  63.   setkey("exit_jed", "^[OPQ");
  64.   setkey("exit_jed", "^[OPE");
  65. define quit() {exit_jed()}
  66. define exit() {exit_jed()}
  67.  
  68. %%
  69. %%  Gold-Gold to toggle keypad state
  70. %%
  71. #ifdef MSDOS OS2
  72.  unsetkey("^@;");
  73.   setkey("edt_togglekp",  "^@;");    %% IBM F1 key
  74. #endif
  75.  
  76. variable Edt_Keypad;  Edt_Keypad = 1;
  77.  
  78. define edt_togglekp ()
  79. {
  80.    variable on, off;
  81. #ifdef VMS UNIX
  82.    off = "Numeric.";  on =  "Application.";
  83. #else
  84.    on = "Gold ON"; off = "Gold OFF";
  85.    NUMLOCK_IS_GOLD = not(NUMLOCK_IS_GOLD);
  86. #endif
  87.  
  88. #ifdef UNIX VMS
  89.    if (Edt_Keypad) { off; "\e>" } else {on; "\e="}  tt_send(());
  90. #else
  91.    if (Edt_Keypad) off; else on;
  92. #endif
  93.    message(());
  94.    Edt_Keypad = not(Edt_Keypad);
  95. }
  96.  
  97.   setkey("edt_togglekp",    "^[OP^[OP");    %% Gold-Gold toggles keypad
  98. %  setkey("self_insert_cmd", "^I");    %% tab inserts tab.
  99.   setkey("edt_delbol",    "^U");    %% delete to bol
  100.   setkey("edt_help",    "^[OQ");    %% help
  101.   setkey("edt_findnxt",    "^[OR");    %% findnxt
  102.   setkey("edt_ldel",    "^[OS");    %% del l
  103.   setkey("edt_cdel",    "^[Ol");    %% del c
  104.   setkey("edt_wdel",    "^[Om");    %% del w
  105.   setkey("smart_set_mark_cmd",    "^[On");    %% select
  106.   setkey("edt_line",    "^[Op");    %% line
  107.   setkey("edt_word",    "^[Oq");    %% word
  108.   setkey("edt_eol",    "^[Or");    %% eol
  109.   setkey("edt_char",    "^[Os");    %% char
  110.   setkey("edt_advance",    "^[Ot");    %% advance
  111.   setkey("edt_backup",    "^[Ou");    %% backup
  112.   setkey("edt_cut",    "^[Ov");    %% cut
  113.   setkey("edt_page",    "^[Ow");    %% page
  114.   setkey("edt_sect",    "^[Ox");    %% sect
  115.   setkey("edt_append",    "^[Oy");    %% append
  116.   setkey("edt_help",    "^[OP^[OQ");    %% help
  117.   setkey("edt_find",    "^[OP^[OR");    %% find
  118.   setkey("edt_uldel",    "^[OP^[OS");    %% udel l
  119.   setkey("edt_ucdel",    "^[OP^[Ol");    %% udel c
  120.   setkey("edt_uwdel",    "^[OP^[Om");    %% udel w
  121.   setkey("edt_reset",    "^[OP^[On");    %% reset
  122.   setkey("edt_oline",    "^[OP^[Op");    %% open line
  123.   setkey("edt_chgcase",    "^[OP^[Oq");    %% chgcase
  124.   setkey("edt_deleol",    "^[OP^[Or");    %% deleol
  125. %%
  126. %%  There are two possible definitions for the specins key.  Let's choose
  127. %%  the edt one though I prefer the other
  128. %%
  129.   setkey("edt_specins",   "^[OP^[Os");    %% specins
  130. %  setkey("quoted_insert",    "^[OP^[Os");    %% specins
  131.   setkey("eob",        "^[OP^[Ot");    %% bottom
  132.   setkey("beg_of_buffer",    "^[OP^[Ou");    %% top
  133.   setkey("edt_paste",    "^[OP^[Ov");    %% paste
  134.   setkey("evaluate_cmd",    "^[OP^[Ow");    %% cmd
  135.   setkey("format_paragraph", "^[OP^[Ox");    %% fill
  136.   setkey("edt_replace",    "^[OP^[Oy");    %% replace
  137.   setkey("exit_mini",    "^[OM");    %% enter
  138. %%
  139. %% the enter key requires some care--- it MUST be put in the minibuffer
  140. %%   keymap.  But this is not created until AFTER the init files are loaded
  141. %%   so that it inherits user definitions.  The above line puts it in the
  142. %%   global map so that it behaves properly there.  The same applies to
  143. %%   the 'reset' command.
  144. %%
  145. %% The above comment WAS true in versions prior to 0.81.  Now it is possible
  146. %% to achieve the desired effect in the startup_hook.  I think it is time to 
  147. %% think of a way to chain functions.  That is, I would like to define a 
  148. %% function that startup_hook will call without explicitly modifying startup
  149. %% hook and not destroying other hooks in the process.  Thus, startup_hook
  150. %% should consist of a chain of functions to execute.
  151. %%
  152.  if (keymap_p("Mini_Map"))
  153.    { 
  154.       definekey("exit_mini", "^[OM", "Mini_Map");    %% enter
  155.       definekey("edt_reset", "^[OP^[On","Mini_Map"); %% reset
  156.    }
  157. %%
  158. %%  In EDT, a command may be repeated by GOLD number.  Lets have that too
  159. %%
  160.  _for (0, 9, 1) 
  161.     {
  162.        =$0;
  163.        setkey("digit_arg", strcat("\eOP", string($0)));
  164.     }
  165.  
  166. %% These are the keys on the vt220 keyboard
  167.   setkey("edt_find",          "^[[1~");    %%differs from vt220.sl
  168.   setkey("yank",            "^[[2~");    
  169.   setkey("kill_region",        "^[[3~");    
  170.   setkey("smart_set_mark_cmd",        "^[[4~");    
  171.   setkey("page_up",        "^[[5~");    
  172.   setkey("page_down",        "^[[6~");    
  173. %  setkey(evaluate_cmd",        "^[[29~");    
  174.   setkey("emacs_escape_x",    "^[[29~");    
  175.   setkey("edt_help",        "^[[28~");    
  176. %%
  177. %%  Finally some definitions for scrolling the screen left/right
  178. %%
  179.   setkey("beg_of_buffer", "^[OP^[[A");    % gold ^
  180.   setkey("eob",           "^[OP^[[B");    % gold v
  181.   setkey("scroll_left",   "^[OP^[[C");    % gold ->
  182.   setkey("scroll_right",  "^[OP^[[D");    % gold <-
  183.  
  184. %% The major complication is the direction.  Here it is:
  185. variable edt_dir; edt_dir = 1;
  186.  
  187. %!%ADVANCE - (4)
  188. %!%Sets the current direction to forward for the CHAR, WORD, LINE, EOL, PAGE,
  189. %!%SECT, SUBS, FIND, and FNDNXT keys.  ADVANCE means that movement will be
  190. %!%toward the end of the buffer; that is, to the right and down.
  191. define edt_advance()
  192. {
  193.    edt_dir = 1;
  194.   set_status_line("(Jed %v) EDT: %b   (%m%n%o)  %p,%c    Advance   %t", 1);
  195. }
  196.  
  197. %!%BACKUP - (5)
  198. %!%Sets the cursor direction to backward for the CHAR, WORD, LINE, EOL, PAGE,
  199. %!%SECT, SUBS, FIND, and FNDNXT keys.  BACKUP means that movement will be
  200. %!%toward the beginning of the buffer% that is, to the left and up.
  201. define edt_backup()
  202. {
  203.    edt_dir = -1;
  204.   set_status_line("(Jed %v) EDT: %b   (%m%n%o)  %p,%c    Backup    %t", 1);
  205. }
  206.  
  207. %% other buffers:  not buffers but strings except the char buffer which is int
  208. variable edt_wbuf, edt_lbuf, edt_cbuf;
  209. edt_wbuf = Null_String; edt_lbuf = Null_String; edt_cbuf = 0;
  210.  
  211. %% character (un)deletion
  212. define edt_cdel()
  213. {  
  214.    !if (eobp()) { edt_cbuf = what_char(); del(); }
  215. }
  216. define edt_ucdel()
  217. {
  218.    if (edt_cbuf) { insert_char (edt_cbuf); go_left(1); } 
  219. }
  220.  
  221. define edt_word()
  222. {
  223.    if (edt_dir == 1)
  224.      {
  225.     if (eolp()) return(go_right(1));
  226.     skip_word_chars(); skip_non_word_chars();
  227.      }
  228.    else
  229.      {
  230.     if (bolp()) return (go_left(1));
  231.     bskip_non_word_chars(); bskip_word_chars();
  232.      } 
  233. }
  234.  
  235. %!%DEL W - (-)
  236. %!%Deletes text from the cursor to the beginning of the next word, storing the
  237. %!%text in the delete word buffer.
  238. define edt_wdel()
  239. {
  240.    push_mark(); push_mark(); 
  241.    edt_word();            %% use whatever edt_word does as a region
  242.    edt_wbuf = bufsubstr();
  243.    del_region();
  244. }
  245.  
  246. %% another one from Clive Page.
  247. define edt_specins()
  248. {
  249.    insert_char (integer(read_mini("char code (decimal):", "27", Null_String)));
  250. }
  251.  
  252. %!%UND W - (GOLD -) 
  253. %!%Inserts the contents of the delete word buffer directly to the left of the
  254. %!%cursor.
  255. define edt_uwdel()
  256. {
  257.    push_spot(); insert (edt_wbuf); pop_spot();
  258. }
  259.  
  260. %% aparantly deleol also saves what it did in buffer...
  261. define edt_deleol()
  262. {
  263.    push_mark(); push_mark(); eol(); edt_lbuf = bufsubstr(); del_region();
  264. }
  265. define edt_delbol()
  266. {
  267.    push_mark(); push_mark(); bol(); edt_lbuf = bufsubstr(); del_region();
  268. }
  269.  
  270. %% the line
  271.  
  272. %!%DEL L - (PF4) 
  273. %!%Deletes text from the cursor position to the end of the current line, including
  274. %!%the line terminator.  If the cursor is positioned at the beginning of a line,
  275. %!%the entire line is deleted.  The deleted text is saved in the delete line
  276. %!%buffer.
  277. define edt_ldel()
  278. {
  279.    push_mark(); push_mark();
  280.    eol(); go_right(1);
  281.    edt_lbuf = bufsubstr();
  282.    del_region();
  283. }
  284.  
  285. %!%UND L - (GOLD PF4)
  286. %!%Inserts the contents of the delete line buffer directly to the left of the
  287. %!%cursor.
  288. define edt_uldel()
  289. {
  290.    push_spot(); insert (edt_lbuf); pop_spot();
  291. }
  292.  
  293. %!%FIND - (GOLD PF3) 
  294. %!%Searches for an occurrence of a string.  Press the FIND key and then enter the
  295. %!%string using the main keyboard.  End the string by pressing either the ADVANCE
  296. %!%or BACKUP key to set the direction of the search, or the ENTER key to search in
  297. %!%the current direction.
  298. define edt_find()
  299. {
  300.    if (edt_dir == 1) search_forward (); else search_backward ();
  301. }
  302.  
  303. %!%FNDNXT - (PF3)
  304. %!%Searches for the next occurrence of the search string previously entered with
  305. %!%the FIND key.  The direction of the search is the current one (ADVANCE or
  306. %!%BACKUP).
  307. define edt_findnxt()
  308. {
  309.    variable r, found;
  310.    r = 0;
  311.    if (strlen(LAST_SEARCH))
  312.      { 
  313.     if (edt_dir == 1)
  314.       {
  315.          r = right(1);
  316.          found = fsearch(LAST_SEARCH);
  317.       }
  318.     else found = bsearch(LAST_SEARCH);
  319.     !if (found)
  320.       { 
  321.          go_left(r);
  322.          error("Not Found.");
  323.       }
  324.      }
  325.    else error ("Find What?")
  326. }
  327.  
  328. %!%SECT - (8) 
  329. %!%Moves the cursor 16 lines (one section) forward or backward, depending on the
  330. %!%current direction (see ADVANCE and BACKUP).  The cursor is moved to the
  331. %!%beginning of the appropriate line.
  332. define edt_sect()
  333. {
  334.    if (edt_dir == 1) go_down(16); else go_up(16);
  335.    bol();
  336. }
  337.  
  338. define edt_eol()
  339. {
  340.    if (edt_dir == 1)
  341.      {
  342.     if (eolp()) go_down(1);
  343.      }
  344.    else go_up(1);
  345.    eol();
  346. }
  347.  
  348. define edt_line()
  349. {
  350.    if (edt_dir > 0) go_down(1); 
  351.    else if (bolp()) go_up(1);
  352.    bol();
  353. }
  354.  
  355. define edt_char()
  356. {
  357.    if (edt_dir == 1) go_right(1); else go_left(1);
  358. }
  359.  
  360. define edt_oline()
  361. {
  362.    newline(); go_left(1);
  363. }
  364.  
  365. %% reset also pops marks.
  366. define edt_reset()
  367. {
  368.    edt_advance();
  369.    while(markp()) pop_mark(0);
  370.    call ("kbd_quit");
  371. }
  372.  
  373. %% edt page searches for a form feed.  However, real edt allows user to
  374. %% change this.
  375.  
  376. %!%PAGE - (7)
  377. %!%Moves the cursor to the top of a page.  A page is defined by a delimiter
  378. %!%string, which can be set by the SET ENTITY command.  The default page
  379. %!%delimiter is the formfeed character (CTRL/L).
  380. define edt_page()
  381. {
  382.    variable ret, ff;
  383.    ff = char(12);
  384.    if (edt_dir == 1) ret = fsearch(ff); else ret = bsearch(ff);
  385.    if (ret) recenter(1);
  386. }
  387.  
  388. define edt_cut()
  389. {
  390.    variable b;
  391.    !if (dupmark()) return;
  392.    b = whatbuf();
  393.    setbuf(edt_pbuf);
  394.    erase_buffer();
  395.    setbuf(b);
  396.    copy_region(edt_pbuf);
  397.    del_region();
  398. }
  399. define edt_paste() 
  400. {
  401.    insbuf(edt_pbuf);
  402. }
  403.  
  404. %% Although not documented in EDT online help, this deletes the region.
  405. %!%APPEND - (9) 
  406. %!%Moves the select range to the end of the PASTE buffer.  The select range is all
  407. %!%the text between the selected position (see SELECT) and the current cursor
  408. %!%position.  If no SELECT has been made and the cursor is positioned on the
  409. %!%current search string, that string is appended.
  410. define edt_append()
  411. {
  412.    variable b;
  413.    b = whatbuf();
  414.    setbuf(edt_pbuf);
  415.    eob();
  416.    setbuf(b);
  417.    if (dupmark())
  418.      {
  419.     copy_region(edt_pbuf);
  420.     del_region();
  421.      }
  422.    else error("No Region.");
  423. }
  424.  
  425. define edt_replace()
  426. {
  427.    del_region(); edt_paste();
  428. }
  429.  
  430. %% a real edt_subs function
  431. %% deletes search string, substitutes what is in the pastebuffer and finds
  432. %% the next.
  433. define edt_subs()
  434. {
  435.    if (looking_at(LAST_SEARCH))
  436.      {
  437.     deln (strlen(LAST_SEARCH));
  438.     edt_paste();
  439.     !if (looking_at (LAST_SEARCH)) edt_findnxt();
  440.      }
  441.    else error("Select range not active.")
  442. }
  443.  
  444.  
  445. %% a help for the help key
  446. define edt_help()
  447. {
  448.    jed_easy_help("edt.hlp");
  449. }
  450.  
  451. %% Chngcase
  452. define edt_chgcase()
  453. {
  454.    variable n;
  455.    !if (markp())
  456.      {
  457.     push_mark();
  458.     n = strlen(LAST_SEARCH);
  459.     if (n and looking_at(LAST_SEARCH)) go_right(n);
  460.     else if (edt_dir == 1) go_right(1); 
  461.     else go_left(1);
  462.      }
  463.    xform_region('X');
  464. }
  465.  
  466. %% is this a better defn of what edt_replace should be?
  467. %!%REPLACE - (GOLD 9)
  468. %!%Deletes the select range and replaces it with the contents of the PASTE 
  469. %!%buffer.
  470. define edt_replace()
  471. {
  472.    variable n;
  473.    n = strlen(LAST_SEARCH);
  474.  
  475.    if (n and looking_at(LAST_SEARCH)) deln (n);
  476.    else 
  477.      {
  478.     !if (markp()) error("Select range not active.");
  479.     del_region();
  480.      }
  481.    edt_paste();
  482. }
  483.