d40ce24e46e74fe89e1c9776733766f88b431100
[lice.git] / src / callint.lisp
blobd40ce24e46e74fe89e1c9776733766f88b431100
1 ;;; Call a Lisp function interactively.
3 (defvar *prefix-arg* nil
4 "The value of the prefix argument for the next editing command.
5 It may be a number, or the symbol `-' for just a minus sign as arg,
6 or a list whose car is a number for just one or more C-u's
7 or nil if no argument has been specified.
9 You cannot examine this variable to find the argument for this command
10 since it has been set to nil by the time you can look.
11 Instead, you should use the variable `current-prefix-arg', although
12 normally commands can get this prefix argument with (interactive \"P\").")
14 (defvar *last-prefix-arg* nil
15 "The value of the prefix argument for the previous editing command.
16 See `prefix-arg' for the meaning of the value.")
18 (defvar *current-prefix-arg* nil
19 "The value of the prefix argument for this editing command.
20 It may be a number, or the symbol `-' for just a minus sign as arg,
21 or a list whose car is a number for just one or more C-u's
22 or nil if no argument has been specified.
23 This is what `(interactive \"P\")' returns.")
25 (defvar *command-history* nil
26 "List of recent commands that read arguments from terminal.
27 Each command is represented as a form to evaluate.")
29 (defun call-interactively (function &optional record-flag (keys *this-command-keys*))
30 "Call FUNCTION, reading args according to its interactive calling specs.
31 Return the value FUNCTION returns.
32 The function contains a specification of how to do the argument reading.
33 In the case of user-defined functions, this is specified by placing a call
34 to the function `interactive' at the top level of the function body.
35 See `interactive'.
37 Optional second arg RECORD-FLAG non-nil
38 means unconditionally put this command in the command-history.
39 Otherwise, this is done only if an arg is read using the minibuffer.
41 Optional third arg KEYS, if given, specifies the sequence of events to
42 supply, as a vector, if the command inquires which events were used to
43 invoke it. If KEYS is omitted or nil, the return value of
44 `*this-command-keys-vector*' is used."
45 (setf function (lookup-command function))
46 (check-type function command)
48 (let ((args (mapcar (lambda (a)
49 (if (listp a)
50 (apply (gethash (first a) *command-arg-type-hash*) (cdr a))
51 (funcall (gethash a *command-arg-type-hash*))))
52 (command-args function))))
53 ;; XXX: Is this a sick hack? We need to reset the
54 ;; prefix-arg at the right time. After the command
55 ;; is executed we can't because the universal
56 ;; argument code sets the prefix-arg for the next
57 ;; command. The Right spot seems to be to reset it
58 ;; once a command is about to be executed, and
59 ;; after the prefix arg has been gathered to be
60 ;; used in the command. Which is right here.
61 (setf *prefix-arg* nil)
62 ;; Note that we use the actual function. If the
63 ;; function is redefined, the command will
64 ;; continue to be defined and will call the
65 ;; function declared above, not the redefined one.
66 (apply (command-fn function) args)))
68 (defun prefix-numeric-value (prefix)
69 "Return numeric meaning of raw prefix argument RAW.
70 A raw prefix argument is what you get from :raw-prefix.
71 Its numeric meaning is what you would get from :prefix."
72 ;; TODO
73 (cond ((null prefix)
75 ((eq prefix '-)
76 -1)
77 ((and (consp prefix)
78 (integerp (car prefix)))
79 (car prefix))
80 ((integerp prefix)
81 prefix)
82 (t 1)))