X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/f8e0614ccbf0baa82f441de53fcf651e6610a963..f02566ce1e47303059374c38d995d41e9e724793:/src/keyboard.c?ds=sidebyside diff --git a/src/keyboard.c b/src/keyboard.c index 1cc24f95bd..cac051f788 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -246,9 +246,6 @@ Lisp_Object Vminibuffer_message_timeout; ASCII character. */ int quit_char; -extern Lisp_Object current_global_map; -extern int minibuf_level; - /* If non-nil, this is a map that overrides all other local maps. */ Lisp_Object Voverriding_local_map; @@ -364,6 +361,15 @@ Lisp_Object Vlast_event_frame; X Windows wants this for selection ownership. */ unsigned long last_event_timestamp; +/* If non-nil, active regions automatically become the window selection. */ +Lisp_Object Vselect_active_regions; + +/* The text in the active region prior to modifying the buffer. + Used by the `select-active-regions' feature. */ +Lisp_Object Vsaved_region_selection; + +Lisp_Object Qx_set_selection, QPRIMARY, Qhandle_switch_frame; + Lisp_Object Qself_insert_command; Lisp_Object Qforward_char; Lisp_Object Qbackward_char; @@ -468,8 +474,6 @@ Lisp_Object Qmake_frame_visible; Lisp_Object Qselect_window; Lisp_Object Qhelp_echo; -extern Lisp_Object Qremap; - #if defined (HAVE_MOUSE) || defined (HAVE_GPM) Lisp_Object Qmouse_fixup_help_message; #endif @@ -497,7 +501,6 @@ Lisp_Object Qevent_symbol_elements; Lisp_Object Qmenu_enable; Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; Lisp_Object QCbutton, QCtoggle, QCradio, QClabel; -extern Lisp_Object Qmenu_item; /* An event header symbol HEAD may have a property named Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); @@ -517,17 +520,12 @@ Lisp_Object Qmode_line; Lisp_Object Qvertical_line; Lisp_Object Qvertical_scroll_bar; Lisp_Object Qmenu_bar; -extern Lisp_Object Qleft_margin, Qright_margin; -extern Lisp_Object Qleft_fringe, Qright_fringe; -extern Lisp_Object QCmap; Lisp_Object recursive_edit_unwind (Lisp_Object buffer), command_loop (void); Lisp_Object Fthis_command_keys (void); Lisp_Object Qextended_command_history; EMACS_TIME timer_check (int do_it_now); -extern Lisp_Object Vhistory_length, Vtranslation_table_for_input; - static void record_menu_key (Lisp_Object c); static int echo_length (void); @@ -542,8 +540,6 @@ Lisp_Object Vtimer_idle_list; /* Incremented whenever a timer is run. */ int timers_run; -extern Lisp_Object Vprint_level, Vprint_length; - /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt happens. */ EMACS_TIME *input_available_clear_time; @@ -626,7 +622,7 @@ static Lisp_Object make_lispy_movement (struct frame *, Lisp_Object, unsigned long); #endif static Lisp_Object modify_event_symbol (int, unsigned, Lisp_Object, - Lisp_Object, char **, + Lisp_Object, const char **, Lisp_Object *, unsigned); static Lisp_Object make_lispy_switch_frame (Lisp_Object); static void save_getcjmp (jmp_buf); @@ -650,7 +646,6 @@ static int store_user_signal_events (void); to support it. */ static int cannot_suspend; -extern Lisp_Object Qidentity, Qonly; /* Install the string STR as the beginning of the string of echoing, so that it serves as a prompt for the next character. @@ -1380,7 +1375,7 @@ This also exits all active minibuffers. */) while (INPUT_BLOCKED_P) UNBLOCK_INPUT; - return Fthrow (Qtop_level, Qnil); + Fthrow (Qtop_level, Qnil); } DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", @@ -1391,7 +1386,6 @@ DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, Fthrow (Qexit, Qnil); error ("No recursive edit is in progress"); - return Qnil; } DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", @@ -1402,7 +1396,6 @@ DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, Fthrow (Qexit, Qt); error ("No recursive edit is in progress"); - return Qnil; } #if defined (HAVE_MOUSE) || defined (HAVE_GPM) @@ -1799,9 +1792,35 @@ command_loop_1 (void) Vtransient_mark_mode = Qidentity; if (!NILP (Vdeactivate_mark)) + /* If `select-active-regions' is non-nil, this call to + `deactivate-mark' also sets the PRIMARY selection. */ call0 (Qdeactivate_mark); - else if (current_buffer != prev_buffer || MODIFF != prev_modiff) - call1 (Vrun_hooks, intern ("activate-mark-hook")); + else + { + /* Even if not deactivating the mark, set PRIMARY if + `select-active-regions' is non-nil. */ + if ((EQ (Vselect_active_regions, Qonly) + ? EQ (CAR_SAFE (Vtransient_mark_mode), Qonly) + : (!NILP (Vselect_active_regions) + && !NILP (Vtransient_mark_mode))) + && !EQ (Vthis_command, Qhandle_switch_frame)) + { + int beg = XINT (Fmarker_position (current_buffer->mark)); + int end = XINT (make_number (PT)); + if (beg < end) + call2 (Qx_set_selection, QPRIMARY, + make_buffer_string (beg, end, 0)); + else if (beg > end) + call2 (Qx_set_selection, QPRIMARY, + make_buffer_string (end, beg, 0)); + /* Don't set empty selections. */ + } + + if (current_buffer != prev_buffer || MODIFF != prev_modiff) + call1 (Vrun_hooks, intern ("activate-mark-hook")); + } + + Vsaved_region_selection = Qnil; } finalize: @@ -1838,16 +1857,11 @@ command_loop_1 (void) } } -extern Lisp_Object Qcomposition, Qdisplay; - /* Adjust point to a boundary of a region that has such a property that should be treated intangible. For the moment, we check `composition', `display' and `invisible' properties. LAST_PT is the last position of point. */ -extern Lisp_Object Qafter_string, Qbefore_string; -extern Lisp_Object get_pos_property (Lisp_Object, Lisp_Object, Lisp_Object); - static void adjust_point_for_property (int last_pt, int modified) { @@ -4374,8 +4388,6 @@ struct input_event last_timer_event; ...). Each element has the form (FUN . ARGS). */ Lisp_Object pending_funcalls; -extern Lisp_Object Qapply; - /* Check whether a timer has fired. To prevent larger problems we simply disregard elements that are not proper timers. Do not make a circular timer list for the time being. @@ -4747,7 +4759,7 @@ static const int lispy_accent_codes[] = /* This is a list of Lisp names for special "accent" characters. It parallels lispy_accent_codes. */ -static char *lispy_accent_keys[] = +static const char *lispy_accent_keys[] = { "dead-circumflex", "dead-grave", @@ -4774,7 +4786,7 @@ static char *lispy_accent_keys[] = #ifdef HAVE_NTGUI #define FUNCTION_KEY_OFFSET 0x0 -char *lispy_function_keys[] = +char const *lispy_function_keys[] = { 0, /* 0 */ @@ -4937,9 +4949,9 @@ char *lispy_function_keys[] = 0, /* VK_OEM_102 0xE2 */ "ico-help", /* VK_ICO_HELP 0xE3 */ "ico-00", /* VK_ICO_00 0xE4 */ - 0, /* VK_PROCESSKEY 0xE5 */ + 0, /* VK_PROCESSKEY 0xE5 - used by IME */ "ico-clear", /* VK_ICO_CLEAR 0xE6 */ - "packet", /* VK_PACKET 0xE7 */ + 0, /* VK_PACKET 0xE7 - used to pass unicode chars */ 0, /* 0xE8 */ "reset", /* VK_OEM_RESET 0xE9 */ "jump", /* VK_OEM_JUMP 0xEA */ @@ -4968,7 +4980,7 @@ char *lispy_function_keys[] = /* Some of these duplicate the "Media keys" on newer keyboards, but they are delivered to the application in a different way. */ -static char *lispy_multimedia_keys[] = +static const char *lispy_multimedia_keys[] = { 0, "browser-back", @@ -5032,7 +5044,7 @@ static char *lispy_multimedia_keys[] = the XK_kana_A case below. */ #if 0 #ifdef XK_kana_A -static char *lispy_kana_keys[] = +static const char *lispy_kana_keys[] = { /* X Keysym value */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */ @@ -5071,7 +5083,7 @@ static char *lispy_kana_keys[] = /* You'll notice that this table is arranged to be conveniently indexed by X Windows keysym values. */ -static char *lispy_function_keys[] = +static const char *lispy_function_keys[] = { /* X Keysym value */ @@ -5157,7 +5169,7 @@ static char *lispy_function_keys[] = /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */ #define ISO_FUNCTION_KEY_OFFSET 0xfe00 -static char *iso_lispy_function_keys[] = +static const char *iso_lispy_function_keys[] = { 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */ @@ -5180,14 +5192,14 @@ static char *iso_lispy_function_keys[] = Lisp_Object Vlispy_mouse_stem; -static char *lispy_wheel_names[] = +static const char *lispy_wheel_names[] = { "wheel-up", "wheel-down", "wheel-left", "wheel-right" }; /* drag-n-drop events are generated when a set of selected files are dragged from another application and dropped onto an Emacs window. */ -static char *lispy_drag_n_drop_names[] = +static const char *lispy_drag_n_drop_names[] = { "drag-n-drop" }; @@ -5198,7 +5210,7 @@ Lisp_Object Qup, Qdown, Qbottom, Qend_scroll; Lisp_Object Qtop, Qratio; /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ -Lisp_Object *scroll_bar_parts[] = { +const Lisp_Object *scroll_bar_parts[] = { &Qabove_handle, &Qhandle, &Qbelow_handle, &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio }; @@ -6565,7 +6577,7 @@ reorder_modifiers (Lisp_Object symbol) static Lisp_Object modify_event_symbol (int symbol_num, unsigned int modifiers, Lisp_Object symbol_kind, - Lisp_Object name_alist_or_stem, char **name_table, + Lisp_Object name_alist_or_stem, const char **name_table, Lisp_Object *symbol_table, unsigned int table_size) { Lisp_Object value; @@ -8018,9 +8030,8 @@ static Lisp_Object tool_bar_item_properties; static int ntool_bar_items; -/* The symbols `tool-bar', `:image' and `:rtl'. */ +/* The symbols `:image' and `:rtl'. */ -extern Lisp_Object Qtool_bar; Lisp_Object QCimage; Lisp_Object Qrtl; @@ -8118,7 +8129,6 @@ static void process_tool_bar_item (Lisp_Object key, Lisp_Object def, Lisp_Object data, void *args) { int i; - extern Lisp_Object Qundefined; struct gcpro gcpro1, gcpro2; /* Protect KEY and DEF from GC because parse_tool_bar_item may call @@ -8283,12 +8293,15 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item) return 0; } else if (EQ (key, QChelp)) - /* `:help HELP-STRING'. */ - PROP (TOOL_BAR_ITEM_HELP) = value; + /* `:help HELP-STRING'. */ + PROP (TOOL_BAR_ITEM_HELP) = value; else if (EQ (key, QClabel)) { + const char *bad_label = "!!?GARBLED ITEM?!!"; /* `:label LABEL-STRING'. */ - PROP (TOOL_BAR_ITEM_LABEL) = value; + PROP (TOOL_BAR_ITEM_HELP) = STRINGP (value) + ? value + : make_string (bad_label, strlen (bad_label)); have_label = 1; } else if (EQ (key, QCfilter)) @@ -8324,41 +8337,43 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item) /* Try to make one from caption and key. */ Lisp_Object key = PROP (TOOL_BAR_ITEM_KEY); Lisp_Object capt = PROP (TOOL_BAR_ITEM_CAPTION); - char *label = SYMBOLP (key) ? (char *) SDATA (SYMBOL_NAME (key)) : ""; - char *caption = STRINGP (capt) ? (char *) SDATA (capt) : ""; - char buf[64]; - EMACS_INT max_lbl = 2*tool_bar_max_label_size; + const char *label = SYMBOLP (key) ? (char *) SDATA (SYMBOL_NAME (key)) : ""; + const char *caption = STRINGP (capt) ? (char *) SDATA (capt) : ""; + EMACS_INT max_lbl = 2 * tool_bar_max_label_size; + char *buf = (char *) xmalloc (max_lbl + 1); Lisp_Object new_lbl; + size_t caption_len = strlen (caption); - if (strlen (caption) < max_lbl && caption[0] != '\0') + if (caption_len <= max_lbl && caption[0] != '\0') { strcpy (buf, caption); - while (buf[0] != '\0' && buf[strlen (buf) -1] == '.') - buf[strlen (buf)-1] = '\0'; - if (strlen (buf) <= max_lbl) - caption = buf; + while (caption_len > 0 && buf[caption_len - 1] == '.') + caption_len--; + buf[caption_len] = '\0'; + label = caption = buf; } - if (strlen (caption) <= max_lbl) - label = caption; - if (strlen (label) <= max_lbl && label[0] != '\0') { int i; - if (label != buf) strcpy (buf, label); + if (label != buf) + strcpy (buf, label); - for (i = 0; i < strlen (buf); ++i) - { - if (buf[i] == '-') buf[i] = ' '; - } + for (i = 0; buf[i] != '\0'; ++i) + if (buf[i] == '-') + buf[i] = ' '; label = buf; } - else label = ""; + else + label = ""; new_lbl = Fupcase_initials (make_string (label, strlen (label))); if (SCHARS (new_lbl) <= tool_bar_max_label_size) PROP (TOOL_BAR_ITEM_LABEL) = new_lbl; + else + PROP (TOOL_BAR_ITEM_LABEL) = make_string ("", 0); + free (buf); } /* If got a filter apply it on binding. */ @@ -10245,7 +10260,6 @@ a special event, so ignore the prefix argument and don't clear it. */) register Lisp_Object final; register Lisp_Object tem; Lisp_Object prefixarg; - extern int debug_on_next_call; debug_on_next_call = 0; @@ -10332,13 +10346,12 @@ give to the command you invoke, if it asks for an argument. */) (Lisp_Object prefixarg) { Lisp_Object function; - char buf[40]; int saved_last_point_position; Lisp_Object saved_keys, saved_last_point_position_buffer; Lisp_Object bindings, value; struct gcpro gcpro1, gcpro2, gcpro3; #ifdef HAVE_WINDOW_SYSTEM - /* The call to Fcompleting_read wil start and cancel the hourglass, + /* The call to Fcompleting_read will start and cancel the hourglass, but if the hourglass was already scheduled, this means that no hourglass will be shown for the actual M-x command itself. So we restart it if it is already scheduled. Note that checking @@ -10351,31 +10364,9 @@ give to the command you invoke, if it asks for an argument. */) XVECTOR (this_command_keys)->contents); saved_last_point_position_buffer = last_point_position_buffer; saved_last_point_position = last_point_position; - buf[0] = 0; GCPRO3 (saved_keys, prefixarg, saved_last_point_position_buffer); - if (EQ (prefixarg, Qminus)) - strcpy (buf, "- "); - else if (CONSP (prefixarg) && XINT (XCAR (prefixarg)) == 4) - strcpy (buf, "C-u "); - else if (CONSP (prefixarg) && INTEGERP (XCAR (prefixarg))) - sprintf (buf, "%ld ", (long) XINT (XCAR (prefixarg))); - else if (INTEGERP (prefixarg)) - sprintf (buf, "%ld ", (long) XINT (prefixarg)); - - /* This isn't strictly correct if execute-extended-command - is bound to anything else. Perhaps it should use - this_command_keys? */ - strcat (buf, "M-x "); - - /* Prompt with buf, and then read a string, completing from and - restricting to the set of all defined commands. Don't provide - any initial input. Save the command read on the extended-command - history list. */ - function = Fcompleting_read (build_string (buf), - Vobarray, Qcommandp, - Qt, Qnil, Qextended_command_history, Qnil, - Qnil); + function = call0 (intern ("read-extended-command")); #ifdef HAVE_WINDOW_SYSTEM if (hstarted) start_hourglass (); @@ -11493,11 +11484,11 @@ init_keyboard (void) Emacs on SIGINT when there are no termcap frames on the controlling terminal. */ signal (SIGINT, interrupt_signal); -#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) +#ifndef DOS_NT /* For systems with SysV TERMIO, C-g is set up for both SIGINT and SIGQUIT and we can't tell which one it will give us. */ signal (SIGQUIT, interrupt_signal); -#endif /* HAVE_TERMIO */ +#endif /* not DOS_NT */ } /* Note SIGIO has been undef'd if FIONREAD is missing. */ #ifdef SIGIO @@ -11531,7 +11522,7 @@ init_keyboard (void) event header symbols and put properties on them. */ struct event_head { Lisp_Object *var; - char *name; + const char *name; Lisp_Object *kind; }; @@ -11708,6 +11699,13 @@ syms_of_keyboard (void) Qinput_method_function = intern_c_string ("input-method-function"); staticpro (&Qinput_method_function); + Qx_set_selection = intern_c_string ("x-set-selection"); + staticpro (&Qx_set_selection); + QPRIMARY = intern_c_string ("PRIMARY"); + staticpro (&QPRIMARY); + Qhandle_switch_frame = intern_c_string ("handle-switch-frame"); + staticpro (&Qhandle_switch_frame); + Qinput_method_exit_on_first_char = intern_c_string ("input-method-exit-on-first-char"); staticpro (&Qinput_method_exit_on_first_char); Qinput_method_use_echo_area = intern_c_string ("input-method-use-echo-area"); @@ -12315,6 +12313,23 @@ Help functions bind this to allow help on disabled menu items and tool-bar buttons. */); Venable_disabled_menus_and_buttons = Qnil; + DEFVAR_LISP ("select-active-regions", + &Vselect_active_regions, + doc: /* If non-nil, an active region automatically becomes the window selection. +If the value is `only', only temporarily active regions (usually made +by mouse-dragging or shift-selection) set the window selection. + +This takes effect only when Transient Mark mode is enabled. */); + Vselect_active_regions = Qt; + + DEFVAR_LISP ("saved-region-selection", + &Vsaved_region_selection, + doc: /* Contents of active region prior to buffer modification. +If `select-active-regions' is non-nil, Emacs sets this to the +text in the region before modifying the buffer. The next +`deactivate-mark' call uses this to set the window selection. */); + Vsaved_region_selection = Qnil; + /* Create the initial keyboard. */ initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); init_kboard (initial_kboard);