Mercurial > emacs
changeset 12266:bdc0826013e0
(universal-argument-map): New var.
(universal-argument, negative-argument, digit-argument):
Use overriding-terminal-local-map.
(prefix-arg-internal, describe-arg): Functions deleted.
(universal-argument-more, universal-argument-minus): New functions.
(universal-argument-other-key): New function.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 16 Jun 1995 06:14:44 +0000 |
parents | 1d2296cfa1e3 |
children | e3421dcda014 |
files | lisp/simple.el |
diffstat | 1 files changed, 63 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/simple.el Fri Jun 16 06:10:21 1995 +0000 +++ b/lisp/simple.el Fri Jun 16 06:14:44 1995 +0000 @@ -935,6 +935,25 @@ (t (set-window-start (display-buffer buffer) 1)))))))) +(defconst universal-argument-map + (let ((map (make-sparse-keymap))) + (define-key map [t] 'universal-argument-other-key) + (define-key map [switch-frame] nil) + (define-key map [?\C-u] 'universal-argument-more) + (define-key map [?-] 'universal-argument-minus) + (define-key map [?0] 'digit-argument) + (define-key map [?1] 'digit-argument) + (define-key map [?2] 'digit-argument) + (define-key map [?3] 'digit-argument) + (define-key map [?4] 'digit-argument) + (define-key map [?5] 'digit-argument) + (define-key map [?6] 'digit-argument) + (define-key map [?7] 'digit-argument) + (define-key map [?8] 'digit-argument) + (define-key map [?9] 'digit-argument) + map) + "Keymap used while processing \\[universal-argument].") + (defun universal-argument () "Begin a numeric argument for the following command. Digits or minus sign following \\[universal-argument] make up the numeric argument. @@ -942,69 +961,59 @@ \\[universal-argument] without digits or minus sign provides 4 as argument. Repeating \\[universal-argument] without digits or minus sign multiplies the argument by 4 each time." - (interactive nil) - (let ((factor 4) - key) -;; (describe-arg (list factor) 1) - (setq key (read-key-sequence nil t)) - (while (equal (key-binding key) 'universal-argument) - (setq factor (* 4 factor)) -;; (describe-arg (list factor) 1) - (setq key (read-key-sequence nil t))) - (prefix-arg-internal key factor nil))) + (interactive) + (setq prefix-arg (list 4)) + (setq overriding-terminal-local-map universal-argument-map)) -(defun prefix-arg-internal (key factor value) - (let ((sign 1)) - (if (and (numberp value) (< value 0)) - (setq sign -1 value (- value))) - (if (eq value '-) - (setq sign -1 value nil)) -;; (describe-arg value sign) - (while (equal key "-") - (setq sign (- sign) factor nil) -;; (describe-arg value sign) - (setq key (read-key-sequence nil t))) - (while (and (stringp key) - (= (length key) 1) - (not (string< key "0")) - (not (string< "9" key))) - (setq value (+ (* (if (numberp value) value 0) 10) - (- (aref key 0) ?0)) - factor nil) -;; (describe-arg value sign) - (setq key (read-key-sequence nil t))) - (setq prefix-arg - (cond (factor (list factor)) - ((numberp value) (* value sign)) - ((= sign -1) '-))) - ;; Calling universal-argument after digits - ;; terminates the argument but is ignored. - (if (eq (key-binding key) 'universal-argument) - (progn - (describe-arg value sign) - (setq key (read-key-sequence nil t)))) - (setq unread-command-events (listify-key-sequence key)))) +;; A subsequent C-u means to multiply the factor by 4 if we've typed +;; nothing but C-u's; otherwise it means to terminate the prefix arg. +(defun universal-argument-more (arg) + (interactive "P") + (if (consp arg) + (setq prefix-arg (list (* 4 (car arg)))) + (setq prefix-arg arg) + (setq overriding-terminal-local-map nil))) -(defun describe-arg (value sign) - (cond ((numberp value) - (message "Arg: %d" (* value sign))) - ((consp value) - (message "Arg: [%d]" (car value))) - ((< sign 0) - (message "Arg: -")))) +(defun negative-argument (arg) + "Begin a negative numeric argument for the next command. +\\[universal-argument] following digits or minus sign ends the argument." + (interactive "P") + (cond ((integerp arg) + (setq prefix-arg (- arg))) + ((eq arg '-) + (setq prefix-arg nil)) + (t + (setq prefix-arg '-)))) (defun digit-argument (arg) "Part of the numeric argument for the next command. \\[universal-argument] following digits or minus sign ends the argument." (interactive "P") - (prefix-arg-internal (char-to-string (logand last-command-char ?\177)) - nil arg)) + (let ((digit (- (logand last-command-char ?\177) ?0))) + (cond ((integerp arg) + (setq prefix-arg (+ (* arg 10) + (if (< arg 0) (- digit) digit)))) + ((eq arg '-) + ;; Treat -0 as just -, so that -01 will work. + (setq prefix-arg (if (zerop digit) '- (- digit)))) + (t + (setq prefix-arg digit))))) -(defun negative-argument (arg) - "Begin a negative numeric argument for the next command. -\\[universal-argument] following digits or minus sign ends the argument." +;; For backward compatibility, minus with no modifiers is an ordinary +;; command if digits have already been entered. +(defun universal-argument-minus (arg) (interactive "P") - (prefix-arg-internal "-" nil arg)) + (if (integerp arg) + (universal-argument-other-key arg) + (negative-argument arg))) + +;; Anything else terminates the argument and is left in the queue to be +;; executed as a command. +(defun universal-argument-other-key (arg) + (interactive "P") + (setq prefix-arg arg) + (setq unread-command-events (list last-input-event)) + (setq overriding-terminal-local-map nil)) (defun forward-to-indentation (arg) "Move forward ARG lines and position at first nonblank character."