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

  1. % mousex.sl
  2. % Mouse routines for use inside an X term or Linux Console running 
  3. % Selection.
  4.  
  5. % Mouse actions:
  6. %
  7. % left mouse button:
  8. %
  9. %   If the left button is clicked on the status line of a window, the window 
  10. %   will switch to a different buffer.
  11. %
  12. %   If the button is pressed anywhere else in the window, the cursor will be
  13. %   positioned at the location of the click.
  14. % middle button:
  15. %   
  16. %   On status line: split the window
  17. %   Anywhere else:
  18. %    If the region is highlighted, the region will be copied to the 
  19. %    pastebuffer.  This does not delete the region.
  20. %    Otherwise, the editing point will be moved to the location of the mouse
  21. %    and any contents in the pastebuffer will be pasted there.
  22. %
  23. % Right button:
  24. %   
  25. %   On status line: delete the window.
  26. %   Anywhere else:
  27. %    If a region is highlighted, it will be deleted and a copy put in the 
  28. %    pastebuffer.
  29. %    Otherwise, the mark is set and a region will be defined.
  30. %
  31. % Cut/Paste Tips:
  32. %  
  33. %  To mark and manipulate a region do:
  34. %
  35. %   1. Click the LEFT mouse button at the beginning of the region.
  36. %   2. Move the mouse to the end of the region and click the RIGHT
  37. %      mouse button.  The region should now be marked.
  38. %   3. To delete it and copy it to the paste buffer,  press the RIGHT button 
  39. %      again.  To simply copy it without deleting it, press the MIDDLE button.
  40. %
  41. %   4. To paste from the pastebuffer, move the mouse to where you want to 
  42. %      paste and press the MIDDLE button.
  43.  
  44.  
  45. % enable mouse 
  46. % tt_send ("\e[?9h");
  47. % define hooks to restore the selection state properly (See ../doc/mouse.txt).
  48. % define exit_hook ()
  49. % {
  50. %    tt_send ("\e[?9l");
  51. %    exit_jed ();
  52. % }
  53.  
  54. % define suspend_hook ()
  55. % {
  56. %    tt_send ("\e[?9l");
  57. % }
  58.  
  59. % define resume_hook ()
  60. % {
  61. %    tt_send ("\e[?9h");
  62. % }
  63.  
  64. % define keys
  65. %setkey ("left_button_down", "\e[M ");
  66. %setkey ("middle_button_down", "\e[M!");
  67. %setkey ("right_button_down", "\e[M\"");
  68.  
  69. % returns  values:  line/column of mouse point, number of windows away, and
  70. % flag indicating whether or not the point in on the status line.
  71. % usage:
  72. %   (is_status, nwins, row, column) = whereis_mouse ();
  73. define whereis_mouse (xmouse, ymouse)
  74. {
  75.    variable n = nwindows ();
  76.    variable top, bot, dy, x, y = 0;
  77.    variable is_status = 0;
  78.    
  79.    while (n)
  80.      {
  81.         top = window_info('t');
  82.     bot = window_info('r') + top;
  83.     
  84.     if ((ymouse >= top) and (ymouse < bot))
  85.              { 
  86.          dy = ymouse - (top - 1 + window_line());
  87.          y = whatline () + dy;
  88.          break;
  89.       }
  90.     
  91.           if (bot == ymouse)
  92.       {      
  93.          is_status = 1;
  94.          break;
  95.       }
  96.     
  97.     otherwindow();
  98.     n--;
  99.      }
  100.    
  101.    !if (n) error ("Mouse not in a window.");
  102.    
  103.    x = window_info('c') + xmouse - 1;
  104.    
  105.    loop (n) otherwindow ();
  106.    
  107.    % return :
  108.    return (is_status, nwindows () - n, y, x);
  109. }
  110.       
  111.  
  112. define mouse_next_buffer ()
  113. {
  114.    variable n, buf, cbuf = whatbuf ();
  115.    
  116.    n = buffer_list ();               %/* buffers on stack */
  117.    loop (n)
  118.      {
  119.     =buf;
  120.     n--;
  121.     if (buf[0] == ' ') continue;
  122.     if (buffer_visible (buf)) continue;
  123.     sw2buf (buf);
  124.     loop (n) pop ();
  125.     return;
  126.      }
  127.    error ("All buffers are visible.");
  128. }
  129.  
  130. define left_button_down ()
  131. {
  132.    variable use_status, x, y, n;
  133.    
  134.    variable x = getkey () - ' ';
  135.    variable y = getkey () - ' ';
  136.  
  137.    % error (Sprintf ("x: %d, y: %d", x, y, 2));
  138.    (use_status, n, y, x) = whereis_mouse (x, y);
  139.    
  140.    loop (n) otherwindow ();
  141.    if (use_status)
  142.      {
  143.     mouse_next_buffer ();
  144.     return;
  145.      }
  146.    
  147.    goto_line (y);
  148.    goto_column_best_try (x); pop ();
  149. }
  150.  
  151. define middle_button_down ()
  152. {
  153.    variable use_status, x, y, n;
  154.    
  155.    variable x = getkey () - ' ';
  156.    variable y = getkey () - ' ';
  157.  
  158.    (use_status, n, y, x) = whereis_mouse (x, y);
  159.    
  160.    loop (n) otherwindow ();
  161.    if (use_status)
  162.      {
  163.     splitwindow ();
  164.     return;
  165.      }
  166.    
  167.    if (markp ()) 
  168.      {      
  169.     call ("copy_region");
  170.     message ("Region copied.");
  171.     return;
  172.      }
  173.    
  174.    goto_line (y);
  175.    goto_column (x);
  176.    call ("yank");
  177. }
  178.         
  179. define right_button_down ()
  180. {
  181.    variable use_status, x, y, n;
  182.    
  183.    variable x = getkey () - ' ';
  184.    variable y = getkey () - ' ';
  185.  
  186.    (use_status, n, y, x) = whereis_mouse (x, y);
  187.    
  188.    loop (n) otherwindow ();
  189.    if (use_status)
  190.      {
  191.     call("delete_window");
  192.     return;
  193.      }
  194.    
  195.    if (markp ()) 
  196.      {
  197.     call ("kill_region");
  198.     return;
  199.      }
  200.    
  201.    call ("set_mark_cmd");
  202.    goto_line (y);
  203.    goto_column (x);
  204. }
  205.