jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

New CUA mode


On Fri, May 02, 2003 at 11:40:45AM +0200, Guido Gonzato wrote:

> ... I believe your CUA
> should replace the very basic CUA mode that Jed ships with: ...

So here it comes (you find it also on the JMR (jed modes repository)):

 cua.sl  % The updated cua-emulation mode enhanced windows and unix-desktop
         % compatibility of the superb jed programmers editor
 cuamisc.sl % Functions needed for cua mode but usefull also without it.
            % So they are in an extra file to be evaluable also without
	    % setting the emulation mode to cua
 cua.hlp % the basic help file shown with help() if cua.sl was evaluated

I would be gratefull for anyone that could test and comment (especially
(but not only) wjed-users).

John, is there a chance to have it in the next distribution?
 
BTW: 
This is just the basic (and most stable) part of my "cua-suite", 
on JMR you find also
 cuamark.sl % a replacement for wmark.sl that works with multiple cutbuffers
            % (aka yankpop.sl)
 cuamouse.sl % a mouse interface that is more compatible to "normal"
             % applications than the mouse.sl that ships with jed
	     % highly configurable but rather complex

Günter

-- 
Milde at ife.et.tu-dresden.de
%   CUA (Windows/Mac/CDE/KDE-like) bindings for Jed.
%
%   Reuben Thomas (rrt@xxxxxxxx)
%   modified by Guenter Milde <g.milde at web.de>
%
%   Versions:
%   1   first version by Guenter Milde <g.milde at web.de>
%   1.1 single ESC-keypress aborts functions (optional)
%
%   USAGE:
%
%   put somewhere in your path and uncomment the line
%   %  () = evalfile ("cua");            % CUA-like key bindings
%   in your .jedrc/jed.rc file
%
%   ESC-problem: unfortunately, some function keys return "\e\e<something>"
%   as keystring. To have a single ESC-press aborting, insert
%      autoload("one_press_escape", "cuamisc");
%      one_press_escape();
%   into your .jedrc. (Attention, except for xjed, this is an experimental
%   feature that might e.g. couse problems with functions that use getkey(),
%   as e.g. isearch)
%
%   Enhancements (optional helper modes from http://jedmodes.sf.net/):
%    cuamouse.sl: cua-like mouse bindings
%    cuamark.sl:  cua-like marking/copy/paste using yp_yank (a ring of 
%                 kill-buffers)
%    numbuf.sl:   fast switch between buffers via ALT + Number
%    print.sl:    printing
%    ch_table.sl: popup_buffer with character table (special chars)

% --- Requirements ------------------------------------------------------

require("cuamisc");   % "Outsourced" helper functions
require("keydefs");   % Key definitions for Unix and DOS/Windos
if(strlen(expand_jedlib_file("cuamark.sl"))) % non standard mode
  require("cuamark");
else
  require("wmark");   % cua-like marking, standard version
require("recent");    % save a list of recent files

% --- Variables --------------------------------------------------------
set_status_line(" %b  mode: %m %n  (%p)   %t ", 1);
menu_set_menu_bar_prefix ("Global", " ");

Help_File = "cua.hlp";

%--- Keybindings --------------------------------------------------------

% This key will be used by the extension modes (e.g. c_mode.sl) to bind
% additional functions to
_Reserved_Key_Prefix = "^E";  % Extended functionality :-)

% ESC (unfortunately, some Function keys return "\e\e something")
% see USAGE at top for workaround
setkey ("escape_cmd", "\e\e\e");              % Triple-Esc -> abort
definekey ("exit_menubar", "\e\e\e", "menu"); % close menus

% % The default binding for the quote keys (", ') is 'text_smart_quote'.
% % Most users do not seem to like this so it is unset here.
% setkey("self_insert_cmd", "\"");
% setkey("self_insert_cmd", "'");

% Function keys
setkey("help_prefix",             Key_F1);
%setkey("help_for_word_at_point", Key_Shift_F1); % with hyperhelp mode
setkey("save_buffer",             Key_F2);
setkey("write_buffer",            Key_Shift_F2); % save as
setkey("find_file",               Key_F3);
setkey("close_buffer",            Key_Shift_F3);
setkey("onewindow",               Key_F5);
setkey("onewindow",               Key_F5);
setkey("splitwindow",             Key_Shift_F5);
setkey("next_buffer",             Key_F6);
setkey("smart_set_mark_cmd",      Key_F7);

% The "named" keys
setkey("backward_delete_char_untabify",    Key_BS);
setkey("delete_cmd",                       Key_Del);
setkey("beg_of_line",                      Key_Home);
setkey("eol_cmd",                          Key_End);
setkey("page_up",                          Key_PgUp);
setkey("page_down",                        Key_PgDn);
setkey("cua_bdelete_word",                 Key_Ctrl_BS);
setkey("delete_word",                      Key_Ctrl_Del);
setkey("beg_of_buffer",                    Key_Ctrl_Home);
setkey("eob; recenter(window_info('r'));", Key_Ctrl_End);
setkey("bskip_word",                       Key_Ctrl_Left);
setkey("skip_word",                        Key_Ctrl_Right);
setkey("forward_paragraph",                Key_Ctrl_Up);
setkey("backward_paragraph",               Key_Ctrl_Down);
%setkey("pop_mark(0)",                     Key_Ctrl_Up);
%setkey("push_mark",                       Key_Ctrl_Down);  % define region

% The Control Chars
unset_ctrl_keys();                         % unset to get a clear start
#ifdef UNIX
enable_flow_control(0);  %turns off ^S/^Q processing (Unix only)
#endif

setkey("mark_buffer",		"^A");   % mark All
%setkey("dabbrev",              "^A");	 % abbreviation expansion
%setkey("format_paragraph",	"^B");   % (ide default)
setkey("smart_set_mark_cmd",	"^B");   % Begin region
setkey("yp_copy_region_as_kill","^C");   % Copy (cua default)
set_abort_char('');                    % "logout"
% ^E ==  _Reserved_Key_Prefix              Extra functionality
% ^F map: 				   Find
setkey("search_backward", 	"^FB");
setkey("isearch_backward",	"^F^B");
setkey("toggle_case_search", 	"^FC");
setkey("re_search_forward", 	"^FE");  % rEgexp search
setkey("search_forward",	"^FF");
setkey("isearch_forward",	"^F^F");
setkey("re_search_backward",	"^FG");
setkey("isearch_forward",	"^FI");  % Incremental search
setkey("occur", 		"^FO");  % find all Occurences
setkey("query_replace_match", 	"^FP");  % regexp rePlace
setkey("replace_cmd", 		"^FR");

setkey("goto_line_cmd", 	"^G");   % Goto line
% set_abort_char('');                  % Jed Default, now on ^D
% ^H map: 				   Help ...
setkey("apropos", 		"^HA");
setkey("describe_function", 	"^HF");
setkey("help",   		"^HH");
setkey("info_mode", 		"^HI");
setkey("showkey", 		"^HK");
setkey("describe_mode", 	"^HM");
setkey ("unix_man",	      	"^HU");
setkey("describe_variable", 	"^HV");
setkey("where_is", 		"^HW");
setkey("select_menubar", 	"^H?");

setkey("indent_region_or_line", "^I");   % Key_Tab: indent_line
% setkey("self_insert_cmd", 	"^I");
% setkey("",		   	"^J");   % Free!
setkey("del_eol",		"^K");   % Kill line
setkey("repeat_search",		"^L");
%  ^M = Key_Return
setkey("next_buffer",      	"^N");   % Next buffer
setkey("find_file",		"^O");   % Open file (cua default)
%setkey ("print_buffer", 	"^P");   % Print (with print.sl)
setkey("exit_with_query",  	"^Q");   % Quit
%setkey("exit_jed",  		"^Q");   % Quit (without asking)
% ^R: 					   Rectangles
setkey("copy_rect",		"^RC");
setkey("insert_rect",		"^RV");
setkey("kill_rect",		"^RX");  % delete and copy to rect-buffer
setkey("open_rect",		"^R ");  % ^R Space: insert whitespace
setkey("blank_rect",		"^RY");  % delete (replace with spaces)
setkey("blank_rect",		"^R" + Key_Del);
setkey("save_buffer",		"^S");   % Save 
%setkey("transpose_chars",  "^T");
% 				 ^T      % still free
setkey("yp_yank",              	"^V");   % insert/paste
setkey("delbuf(whatbuf)",     	"^W");
setkey("yp_kill_region",        "^X");   % cut
setkey("redo",		        "^Y");
setkey("undo",		        "^Z");

runhooks ("keybindings_hook", "cua");    % eventual modifications

% --- menu additions --------------------------------------------------

define cua_load_popup_hook (menubar)
{
   menu_delete_item ("Global.&File.&Close");
   menu_insert_item("&Save", "Global.&File", "&Close", "delbuf(whatbuf)");
   if(strlen(expand_jedlib_file("print.sl"))) % non standard mode
     {
     menu_insert_item("Canc&el Operation", "Global.&File", "&Print", 
		      "print_buffer");
     menu_insert_separator("Canc&el Operation", "Global.&File");
     }
   menu_insert_item (3, "Global.&Search",
		     "&Incremental Search Forward", "isearch_forward");
   menu_insert_item (4, "Global.&Search",
		     "In&cremental Search Backward", "isearch_backward");
   menu_insert_item ("&Replace", "Global.&Search",
		     "Toggle &Case Search", "toggle_case_search");
   menu_insert_separator ("&Replace", "Global.&Search");
}
append_to_hook ("load_popup_hooks", &cua_load_popup_hook);

% signal the success in loading the cua emulation:
_Jed_Emulation = "cua";

Basic Commands in CUA mode:
File:    Region:   Search/Replace:     Edit:                Emergency:
^Q exit  ^C copy   ^FF find forward    ^A Abbreviations     ^H/F1 help
^O open  ^X kill    ^L find next       ^B format paragraph  ^Z 	  undo
^S save	 ^V paste  ^FE regexp search   ^K kill line	    ^G 	  abort
^P print    	   ^FR replace	       ^J goto line	    
% cuamisc.sl: helper functions for the cua suite
%
% "Outsourced" from cua.sl, so they can be used by other emulations as well.
% Author: Guenter Milde <g.milde@xxxxxx>

%!%+
%\function{cua_delete_word}
%\synopsis{Delete the current word (or a defined region)}
%\usage{ Void cua_delete_word ()}
%\description
%   cua_delete_word is somewhat context sensitive:
%    * Delete from the current position to the end of a word.
%    * If there is just whitespace following the editing point, delete it.
%    * If there is any other non-word char, delete just one char.
%    * If a region is defined, delete it (instead of the above actions).
%   This way, you can do a "piecewise" deletion by repeatedly pressing
%   the same key-combination.
%\notes
%   This is actually the ide_delete_word function form Guido Gonzatos
%   ide.sl mode, put here to be usable also with other emulations.
%\seealso{delete_word, delete_cmd, cua_kill_region}
%!%-
public define cua_delete_word ()		% ^T, Key_Ctrl_Del
{
   !if (markp)
     {
	variable p = POINT;
	push_mark ();
	skip_chars (get_word_chars());
	if (POINT == p) skip_chars (" \n\t");
	if (POINT == p) go_right (1);
     }
  del_region ();
}

% Context sensitive backwards deleting, again taken from ide.sl
define cua_bdelete_word ()              % Key_Ctrl_BS
{
  variable p = _get_point ();
  push_mark ();
  bskip_chars ("a-zA-Z0-9");
  if (_get_point () == p) bskip_chars (" \n\t");
  if (_get_point () == p) go_left (1);
  del_region ();
}

%!%+
%\function{next_buffer}
%\synopsis{Cycle through the list of buffers}
%\usage{Void next_buffer ()}
%\description
%   Switches to the next in the list of buffers.
%\notes
%   (This is the same function as mouse_next_buffer in mouse.sl)
%\seealso{buffer_list, list_buffers}
%!%-
public define next_buffer ()
{
   variable n, buf, cbuf = whatbuf ();

   n = buffer_list ();		       %/* buffers on stack */
   loop (n)
     {
	buf = ();
	n--;
	if (buf[0] == ' ') % hidden buffers like " <mini>"
	  continue;
	sw2buf (buf);
	_pop_n (n);
	return;
     }
}

%!%+
%\function{redo}
%\synopsis{Undo the last undo}
%\usage{Void redo()}
%\description
%   Undo the last undo. This works only one step, however
%   as any undo is appended to the end of the undo buffer, you can
%   actually roll the whole history back.
%\seealso{undo}
%!%-
public define redo ()
{
   ERROR_BLOCK {call("undo");};
   call("kbd_quit");
}

%!%+
%\function{repeat_search}
%\synopsis{continue searching with last searchstring}
%\usage{define repeat_search ()}
%\seealso{LAST_SEARCH, search_forward, search_backward}
%!%-
public define repeat_search ()
{
   go_right (1);
   !if (fsearch(LAST_SEARCH)) error ("Not found.");
}

%!%+
%\function{toggle_case_search}
%\synopsis{toggle the CASE_SEARCH variable}
%\usage{Void toggle_case_search ()}
%\seealso{CASE_SEARCH}
%!%-
public define toggle_case_search ()
{
   if (CASE_SEARCH)
     {
	CASE_SEARCH = 0;
	message("Case Search Off");
     }
   else
     {
	CASE_SEARCH = 1;
	message("Case Search On");
     }
}

% Indent the current line or (if defined) the region
public define indent_region_or_line ()
{
   !if(is_visible_mark)
     indent_line;
   else
     {
	check_region (1);                  % make sure the mark comes first
	variable End_Line = what_line;
	exchange_point_and_mark();         % now point is at start of region
	while (what_line <= End_Line)
	  {indent_line; down_1;}
	pop_mark (0);
	pop_spot;
      }
}

%!%+
%\function{exit_with_query}
%\synopsis{ask y or n before really exit jed saving buffers}
%\usage{Void exit_with_query()}
%\description
%   Paranoia function:
%   When you bind a "one shoot" key combination to exit jed, you might
%   want an additional chance to abort if only pressing the keys by accident.
%   However, if we used the _jed_exit_hooks, the query would also occure if
%   jed is terminated e.g. from the window manager.
%
%\seealso{exit_jed, quit_jed, get_y_or_n}
%!%-
public define exit_with_query ()
{
   if (get_y_or_n("Really quit jed"))
     exit_jed();
}

% --- Use the ESC key as abort character (still experimental)

%!%+
%\function{meta_escape_cmd}
%\synopsis{Distinguish the ESC key from other keys starting with "\e"}
%\usage{Void meta_escape_cmd()}
%\description
% If there is input pending (i.e. if the keycode is multi-character),
% "\e" will be put back to the input stream. Otherwise (if the
% ESC key is pressed, "\e\e\e" is pushed back. With ALT_CHAR = 27, the Alt key
% can be used as Meta-key as usual (i.e. press both ALT + <some-key> to get
% the equivalent of the ESC <some-key> key sequence.
%\seealso{escape_cmd, one_press_escape, kbd_quit, map_input, setkey}
define meta_escape_cmd ()
{
   if (input_pending(0))
     ungetkey (27);
   else
     buffer_keystring("\e\e\e");
}

%!%+
%\function{escape_cmd}
%\synopsis{Escape from a command/aktion}
%\usage{ escape_cmd()}
%\description
%   Undo/Stop an action. If a region is defined, undefine it. Else 
%   call kbd_quit.
%\seealso{kbd_quit}
%!%-
define escape_cmd()
{
  if (is_visible_mark)
    pop_mark(0);
  else
    call ("kbd_quit");
}

%!%+
%\function{one_press_escape}
%\synopsis{Redefine the ESC key to issue "\e\e\e"}
%\usage{ one_press_escape()}
%\description
%   Dependend on the jed-version, either x_set_keysym or 
%   meta_escape_cmd is used to map the ESC key to "\e\e\e"
%\example
% To let the ESC key abort functions but retain bindings for
% keystrings that start with "\e" do
%#v+
%    one_press_escape();
%    setkey ("escape_cmd", "\e\e\e");     % Triple-Esc -> abort
%#v-
%\seealso{escape_cmd, meta_escape_cmd, setkey, x_set_keysym}
%!%-
define one_press_escape()
{
   if (is_defined("x_set_keysym"))
     runhooks("x_set_keysym", 0xFF1B, 0, "\e\e\e");   % one-press-escape
   else
     {
	map_input(27, 155);  % \d155 = \x9B is ESC with high bit set
	setkey ("meta_escape_cmd", "\d155");
     }
}

provide ("cuamisc");


[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]