summaryrefslogtreecommitdiff
path: root/src/callint.c
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1995-03-08 03:32:30 +0000
committerKarl Heuer <kwzh@gnu.org>1995-03-08 03:32:30 +0000
commit1cf9cfc6636ae2667da810df82d0c5bafa42ab84 (patch)
tree2ad238a573a98c61f00946808032511bffa78e60 /src/callint.c
parent5169b66ddc167f17660453982e73a1c379d2132e (diff)
downloademacs-1cf9cfc6636ae2667da810df82d0c5bafa42ab84.tar.gz
(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.
Diffstat (limited to 'src/callint.c')
-rw-r--r--src/callint.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/callint.c b/src/callint.c
index 0bc1c996366..23907c7f151 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -28,6 +28,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
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 @@ static Lisp_Object preserved_fns;
/* 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 @@ Its numeric meaning is what you would get from `(interactive \"p\")'.")
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 @@ a way to turn themselves off when a mouse command switches windows.");
defsubr (&Sinteractive);
defsubr (&Scall_interactively);
defsubr (&Sprefix_numeric_value);
+ defsubr (&Suniversal_argument);
+ defsubr (&Snegative_argument);
+ defsubr (&Sdigit_argument);
}