comparison src/event-stream.c @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents 1856695b1fa9
children 15872534500d
comparison
equal deleted inserted replaced
152:4c132ee2d62b 153:25f70ba0133c
185 /* #### kludge! */ 185 /* #### kludge! */
186 Lisp_Object Qauto_show_make_point_visible; 186 Lisp_Object Qauto_show_make_point_visible;
187 187
188 /* File in which we write all commands we read; an lstream */ 188 /* File in which we write all commands we read; an lstream */
189 static Lisp_Object Vdribble_file; 189 static Lisp_Object Vdribble_file;
190
191 /* Recent keys ring location; a vector of events or nil-s */
192 Lisp_Object Vrecent_keys_ring;
193 int recent_keys_ring_size;
194 int recent_keys_ring_index;
190 195
191 #ifdef DEBUG_XEMACS 196 #ifdef DEBUG_XEMACS
192 int debug_emacs_events; 197 int debug_emacs_events;
193 #endif 198 #endif
194 199
3225 3230
3226 (We could implement recent_keys_ring and Vthis_command_keys as the same 3231 (We could implement recent_keys_ring and Vthis_command_keys as the same
3227 data structure.) 3232 data structure.)
3228 */ 3233 */
3229 3234
3230 #define RECENT_KEYS_SIZE 100 3235 DEFUN ("recent-keys", Frecent_keys, 0, 1, 0, /*
3231 Lisp_Object recent_keys_ring; 3236 Return a vector of recent keyboard or mouse button events read.
3232 int recent_keys_ring_index; 3237 If NUMBER is non-nil, not more than NUMBER events will be returned.
3233 3238 Change number of events stored using `set-recent-keys-size'.
3234 DEFUN ("recent-keys", Frecent_keys, 0, 0, 0, /* 3239
3235 Return vector of last 100 or so keyboard or mouse button events read.
3236 This copies the event objects into a new vector; it is safe to keep and 3240 This copies the event objects into a new vector; it is safe to keep and
3237 modify them. 3241 modify them.
3238 */ 3242 */
3239 ()) 3243 (number))
3240 { 3244 {
3241 struct gcpro gcpro1; 3245 struct gcpro gcpro1;
3242 Lisp_Object val = Qnil; 3246 Lisp_Object val = Qnil;
3243 int size = XVECTOR (recent_keys_ring)->size; 3247 int nwanted;
3244 int start, nkeys, i, j; 3248 int start, nkeys, i, j;
3245 GCPRO1 (val); 3249 GCPRO1 (val);
3246 3250
3247 if (NILP (vector_data (XVECTOR (recent_keys_ring))[recent_keys_ring_index])) 3251 if (NILP (number))
3252 nwanted = recent_keys_ring_size;
3253 else
3254 {
3255 CHECK_NATNUM (number);
3256 nwanted = XINT (number);
3257 }
3258
3259 /* Create the keys ring vector, if none present. */
3260 if (NILP (Vrecent_keys_ring))
3261 {
3262 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
3263 /* And return nothing in particular. */
3264 return make_vector (0, Qnil);
3265 }
3266
3267 if (NILP (vector_data (XVECTOR (Vrecent_keys_ring))[recent_keys_ring_index]))
3248 /* This means the vector has not yet wrapped */ 3268 /* This means the vector has not yet wrapped */
3249 { 3269 {
3250 nkeys = recent_keys_ring_index; 3270 nkeys = recent_keys_ring_index;
3251 start = 0; 3271 start = 0;
3252 } 3272 }
3253 else 3273 else
3254 { 3274 {
3255 nkeys = size; 3275 nkeys = recent_keys_ring_size;
3256 start = ((recent_keys_ring_index == size) ? 0 : recent_keys_ring_index); 3276 start = ((recent_keys_ring_index == nkeys) ? 0 : recent_keys_ring_index);
3257 } 3277 }
3258 3278
3259 val = make_vector (nkeys, Qnil); 3279 if (nwanted < nkeys)
3280 {
3281 start += nkeys - nwanted;
3282 if (start >= recent_keys_ring_size)
3283 start -= recent_keys_ring_size;
3284 nkeys = nwanted;
3285 }
3286 else
3287 nwanted = nkeys;
3288
3289 val = make_vector (nwanted, Qnil);
3260 3290
3261 for (i = 0, j = start; i < nkeys; i++) 3291 for (i = 0, j = start; i < nkeys; i++)
3262 { 3292 {
3263 Lisp_Object e = vector_data (XVECTOR (recent_keys_ring))[j]; 3293 Lisp_Object e = vector_data (XVECTOR (Vrecent_keys_ring))[j];
3264 3294
3265 if (NILP (e)) 3295 if (NILP (e))
3266 abort (); 3296 abort ();
3267 vector_data (XVECTOR (val))[i] = Fcopy_event (e, Qnil); 3297 vector_data (XVECTOR (val))[i] = Fcopy_event (e, Qnil);
3268 if (++j >= size) 3298 if (++j >= recent_keys_ring_size)
3269 j = 0; 3299 j = 0;
3270 } 3300 }
3271 UNGCPRO; 3301 UNGCPRO;
3272 return (val); 3302 return (val);
3303 }
3304
3305
3306 DEFUN ("recent-keys-ring-size", Frecent_keys_ring_size, 0, 0, 0, /*
3307 The maximum number of events `recent-keys' can return.
3308 */
3309 ())
3310 {
3311 return make_int (recent_keys_ring_size);
3312 }
3313
3314 DEFUN ("set-recent-keys-ring-size", Fset_recent_keys_ring_size, 1, 1, 0, /*
3315 Set the maximum number of events to be stored internally.
3316 */
3317 (size))
3318 {
3319 Lisp_Object new_vector = Qnil;
3320 int i, j, nkeys, start, min;
3321 struct gcpro gcpro1;
3322 GCPRO1 (new_vector);
3323
3324 CHECK_INT (size);
3325 if (XINT (size) <= 0)
3326 error ("Recent keys ring size must be positive");
3327 if (XINT (size) == recent_keys_ring_size)
3328 return size;
3329
3330 new_vector = make_vector (XINT (size), Qnil);
3331
3332 if (NILP (Vrecent_keys_ring))
3333 {
3334 Vrecent_keys_ring = new_vector;
3335 return size;
3336 }
3337
3338 if (NILP (vector_data (XVECTOR (Vrecent_keys_ring))[recent_keys_ring_index]))
3339 /* This means the vector has not yet wrapped */
3340 {
3341 nkeys = recent_keys_ring_index;
3342 start = 0;
3343 }
3344 else
3345 {
3346 nkeys = recent_keys_ring_size;
3347 start = ((recent_keys_ring_index == nkeys) ? 0 : recent_keys_ring_index);
3348 }
3349
3350 if (XINT (size) > nkeys)
3351 min = nkeys;
3352 else
3353 min = XINT (size);
3354
3355 for (i = 0, j = start; i < min; i++)
3356 {
3357 vector_data (XVECTOR (new_vector))[i]
3358 = vector_data (XVECTOR (Vrecent_keys_ring))[j];
3359 if (++j >= recent_keys_ring_size)
3360 j = 0;
3361 }
3362 recent_keys_ring_size = XINT (size);
3363 recent_keys_ring_index = (i < recent_keys_ring_size) ? i : 0;
3364
3365 Vrecent_keys_ring = new_vector;
3366
3367 UNGCPRO;
3368 return size;
3273 } 3369 }
3274 3370
3275 /* Vthis_command_keys having value Qnil means that the next time 3371 /* Vthis_command_keys having value Qnil means that the next time
3276 push_this_command_keys is called, it should start over. 3372 push_this_command_keys is called, it should start over.
3277 The times at which the command-keys are reset 3373 The times at which the command-keys are reset
3370 } 3466 }
3371 3467
3372 static void 3468 static void
3373 push_recent_keys (Lisp_Object event) 3469 push_recent_keys (Lisp_Object event)
3374 { 3470 {
3375 Lisp_Object e 3471 Lisp_Object e;
3376 = vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index]; 3472
3473 if (NILP (Vrecent_keys_ring))
3474 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
3475
3476 e = vector_data (XVECTOR (Vrecent_keys_ring)) [recent_keys_ring_index];
3377 3477
3378 if (NILP (e)) 3478 if (NILP (e))
3379 { 3479 {
3380 e = Fmake_event (); 3480 e = Fmake_event ();
3381 vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index] = e; 3481 vector_data (XVECTOR (Vrecent_keys_ring)) [recent_keys_ring_index] = e;
3382 } 3482 }
3383 Fcopy_event (event, e); 3483 Fcopy_event (event, e);
3384 if (++recent_keys_ring_index == XVECTOR (recent_keys_ring)->size) 3484 if (++recent_keys_ring_index == recent_keys_ring_size)
3385 recent_keys_ring_index = 0; 3485 recent_keys_ring_index = 0;
3386 } 3486 }
3387 3487
3388 3488
3389 static Lisp_Object 3489 static Lisp_Object
4158 deferror (&Qundefined_keystroke_sequence, "undefined-keystroke-sequence", 4258 deferror (&Qundefined_keystroke_sequence, "undefined-keystroke-sequence",
4159 "Undefined keystroke sequence", Qerror); 4259 "Undefined keystroke sequence", Qerror);
4160 defsymbol (&Qcommand_execute, "command-execute"); 4260 defsymbol (&Qcommand_execute, "command-execute");
4161 4261
4162 DEFSUBR (Frecent_keys); 4262 DEFSUBR (Frecent_keys);
4263 DEFSUBR (Frecent_keys_ring_size);
4264 DEFSUBR (Fset_recent_keys_ring_size);
4163 DEFSUBR (Finput_pending_p); 4265 DEFSUBR (Finput_pending_p);
4164 DEFSUBR (Fenqueue_eval_event); 4266 DEFSUBR (Fenqueue_eval_event);
4165 DEFSUBR (Fnext_event); 4267 DEFSUBR (Fnext_event);
4166 DEFSUBR (Fnext_command_event); 4268 DEFSUBR (Fnext_command_event);
4167 DEFSUBR (Fdiscard_input); 4269 DEFSUBR (Fdiscard_input);
4205 vars_of_event_tty (); 4307 vars_of_event_tty ();
4206 #endif 4308 #endif
4207 4309
4208 4310
4209 recent_keys_ring_index = 0; 4311 recent_keys_ring_index = 0;
4210 recent_keys_ring = make_vector (RECENT_KEYS_SIZE, Qnil); 4312 recent_keys_ring_size = 100;
4211 staticpro (&recent_keys_ring); 4313 Vrecent_keys_ring = Qnil;
4314 staticpro (&Vrecent_keys_ring);
4212 4315
4213 Vthis_command_keys = Qnil; 4316 Vthis_command_keys = Qnil;
4214 staticpro (&Vthis_command_keys); 4317 staticpro (&Vthis_command_keys);
4215 Vthis_command_keys_tail = Qnil; 4318 Vthis_command_keys_tail = Qnil;
4216 4319
4469 Vcontrolling_terminal = Qnil; 4572 Vcontrolling_terminal = Qnil;
4470 staticpro (&Vcontrolling_terminal); 4573 staticpro (&Vcontrolling_terminal);
4471 4574
4472 Vdribble_file = Qnil; 4575 Vdribble_file = Qnil;
4473 staticpro (&Vdribble_file); 4576 staticpro (&Vdribble_file);
4474
4475 4577
4476 #ifdef DEBUG_XEMACS 4578 #ifdef DEBUG_XEMACS
4477 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /* 4579 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /*
4478 If non-zero, display debug information about Emacs events that XEmacs sees. 4580 If non-zero, display debug information about Emacs events that XEmacs sees.
4479 Information is displayed on stderr. 4581 Information is displayed on stderr.