# HG changeset patch # User Karl Heuer # Date 794633550 0 # Node ID 40a1812dcbad87f9f85d8cdfd2602a93e4227762 # Parent d2971946a3d2464734625be5aadc63b329ff2179 (current_prefix_partial): New var. (Funiversal_argument): New function, formerly inlined in keyboard.c. (Fnegative_argument, Fdigit_argument): Likewise. (clear_prefix_arg): Moved here from keyboard.c. Don't clear the internal state if we're still building a prefix arg. (finalize_prefix_arg, describe_prefix_arg): Moved from keyboard.c. (syms_of_callint): defsubr the new lisp-callable functions. diff -r d2971946a3d2 -r 40a1812dcbad src/callint.c --- a/src/callint.c Wed Mar 08 03:31:18 1995 +0000 +++ b/src/callint.c Wed Mar 08 03:32:30 1995 +0000 @@ -28,6 +28,7 @@ extern char *index (); +int current_prefix_partial; Lisp_Object Vprefix_arg, Vcurrent_prefix_arg, Qminus, Qplus; Lisp_Object Qcall_interactively; Lisp_Object Vcommand_history; @@ -47,6 +48,48 @@ /* Marker used within call-interactively to refer to point. */ static Lisp_Object point_marker; + +void +clear_prefix_arg () +{ + if (!current_perdisplay) + abort (); + Vprefix_arg = Qnil; + if (!current_prefix_partial) + { + current_perdisplay->prefix_factor = Qnil; + current_perdisplay->prefix_value = Qnil; + current_perdisplay->prefix_sign = 1; + current_perdisplay->prefix_partial = 0; + } +} + +void +finalize_prefix_arg () +{ + if (!NILP (current_perdisplay->prefix_factor)) + Vprefix_arg = Fcons (current_perdisplay->prefix_factor, Qnil); + else if (NILP (current_perdisplay->prefix_value)) + Vprefix_arg = (current_perdisplay->prefix_sign > 0 ? Qnil : Qminus); + else if (current_perdisplay->prefix_sign > 0) + Vprefix_arg = current_perdisplay->prefix_value; + else + XSETINT (Vprefix_arg, -XINT (current_perdisplay->prefix_value)); + current_perdisplay->prefix_partial = 0; +} + +static void +describe_prefix_arg () +{ + if (INTEGERP (Vprefix_arg)) + message ("Arg: %d", Vprefix_arg); + else if (CONSP (Vprefix_arg)) + message ("Arg: [%d]", XCONS (Vprefix_arg)->car); + else if (EQ (Vprefix_arg, Qminus)) + message ("Arg: -"); +} + + /* This comment supplies the doc string for interactive, for make-docfile to see. We cannot put this in the real DEFUN due to limits in the Unix cpp. @@ -652,6 +695,65 @@ return val; } +DEFUN ("universal-argument", Funiversal_argument, Suniversal_argument, 0, 0, "", + "Begin a numeric argument for the following command.\n\ +Digits or minus sign following \\[universal-argument] make up the numeric argument.\n\ +\\[universal-argument] following the digits or minus sign ends the argument.\n\ +\\[universal-argument] without digits or minus sign provides 4 as argument.\n\ +Repeating \\[universal-argument] without digits or minus sign\n\ + multiplies the argument by 4 each time.") + () +{ + if (!current_prefix_partial) + { + /* First C-u */ + XSETFASTINT (current_perdisplay->prefix_factor, 4); + current_perdisplay->prefix_value = Qnil; + current_perdisplay->prefix_sign = 1; + current_perdisplay->prefix_partial = 1; + } + else if (!NILP (current_perdisplay->prefix_factor)) + { + /* Subsequent C-u */ + XSETINT (current_perdisplay->prefix_factor, + XINT (current_perdisplay->prefix_factor) * 4); + current_perdisplay->prefix_partial = 1; + } + else + { + /* Terminating C-u */ + finalize_prefix_arg (); + describe_prefix_arg (); + } +} + +DEFUN ("negative-argument", Fnegative_argument, Snegative_argument, 0, 0, "", + "Begin a negative numeric argument for the next command.\n\ +\\[universal-argument] following digits or minus sign ends the argument.") + () +{ + current_perdisplay->prefix_factor = Qnil; + current_perdisplay->prefix_sign *= -1; + current_perdisplay->prefix_partial = 1; +} + +DEFUN ("digit-argument", Fdigit_argument, Sdigit_argument, 0, 0, "", + "Part of the numeric argument for the next command.\n\ +\\[universal-argument] following digits or minus sign ends the argument.") + () +{ + int c; + if (!(INTEGERP (last_command_char) + && (c = (XINT (last_command_char) & 0177)) >= '0' && c <= '9')) + error("digit-argument must be bound to a digit key"); + current_perdisplay->prefix_factor = Qnil; + if (NILP (current_perdisplay->prefix_value)) + XSETFASTINT (current_perdisplay->prefix_value, 0); + XSETINT (current_perdisplay->prefix_value, + XINT (current_perdisplay->prefix_value) * 10 + (c - '0')); + current_perdisplay->prefix_partial = 1; +} + syms_of_callint () { point_marker = Fmake_marker (); @@ -732,4 +834,7 @@ defsubr (&Sinteractive); defsubr (&Scall_interactively); defsubr (&Sprefix_numeric_value); + defsubr (&Suniversal_argument); + defsubr (&Snegative_argument); + defsubr (&Sdigit_argument); }