aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2000-06-02 13:07:26 +0000
committerDave Love2000-06-02 13:07:26 +0000
commitc33277213f7f9c67029daf9debe712eb80cfec3f (patch)
tree3569bdd6f1947e117bc9aa90ae7029f1f4520287
parent4bc7a5430d99b6d406a864ab84f45956356388ff (diff)
downloademacs-c33277213f7f9c67029daf9debe712eb80cfec3f.tar.gz
emacs-c33277213f7f9c67029daf9debe712eb80cfec3f.zip
Rewritten to use define-minor-mode.
(autoarg-kp-digits, autoarg-kp-mode-map): New variable. (autoarg-kp-mode, autoarg-kp-digit-argument): New command.
-rw-r--r--lisp/autoarg.el103
1 files changed, 67 insertions, 36 deletions
diff --git a/lisp/autoarg.el b/lisp/autoarg.el
index 47f1ba5b2a0..3e8e99192b5 100644
--- a/lisp/autoarg.el
+++ b/lisp/autoarg.el
@@ -1,6 +1,6 @@
1;;; autoarg.el --- make digit keys supply prefix args 1;;; autoarg.el --- make digit keys supply prefix args
2 2
3;; Copyright (C) 1998 Free Software Foundation, Inc. 3;; Copyright (C) 1998, 2000 Free Software Foundation, Inc.
4 4
5;; Author: Dave Love <fx@gnu.org> 5;; Author: Dave Love <fx@gnu.org>
6;; Created: 1998-09-04 6;; Created: 1998-09-04
@@ -37,40 +37,62 @@
37 37
38;; You probably don't really want to use this. 38;; You probably don't really want to use this.
39 39
40;; Also provides `autoarg-kp-mode' which is similar, but leaves the
41;; digit keys alone and redefines the `keypad' keys, `kp-1' &c as
42;; digit arguments. (Use `NumLock' if necessary to generate kp-N.)
43;; You're more likely to want to use this.
44
40;;; Code: 45;;; Code:
41 46
42;;;###autoload 47(defvar autoarg-mode-map
43(defcustom autoarg-mode nil 48 (let ((map (make-sparse-keymap)))
44 "Toggle Autoarg mode. 49 ;; Loop over digit characters to set up keymap.
45 50 (dotimes (i 10)
46You must modify via \\[customize] for this variable to have an effect." 51 (define-key map `[,(+ ?0 i)] 'digit-argument)
47 :set (lambda (symbol value) (autoarg-mode (or value 0))) 52 (define-key map `[(control ,(+ ?0 i))] 'self-insert-command))
48 :initialize 'custom-initialize-default 53 (define-key map " " 'autoarg-terminate)
49 :type 'boolean 54 map)
50 :group 'editing 55 "Keymap for Autoarg mode.")
51 :require 'autoarg) 56
52;; If you wanted a local mode:
53;; (make-variable-buffer-local 'autoarg-mode)
54
55(defvar autoarg-mode-map (make-sparse-keymap)
56 "Keymap for Autoarg Mode.")
57
58;; Loop over digit characters to set up keymap.
59(let ((i ?0))
60 (while (<= i ?9)
61 (define-key autoarg-mode-map `[,i] 'digit-argument)
62 (define-key autoarg-mode-map `[(control ,i)] 'self-insert-command)
63 (setq i (1+ i))))
64(define-key autoarg-mode-map " " 'autoarg-terminate)
65;; Logical additions: 57;; Logical additions:
66;; (define-key autoarg-mode-map [?-] 'negative-argument) 58;; (define-key autoarg-mode-map [?-] 'negative-argument)
67;; (define-key autoarg-mode-map [(control ?-)] 'self-insert-command) 59;; (define-key autoarg-mode-map [(control ?-)] 'self-insert-command)
68;; A sensible/addition? 60;; A sensible/addition?
69;; (define-key autoarg-mode-map [?\r] 'autoarg-terminate) 61;; (define-key autoarg-mode-map [?\r] 'autoarg-terminate)
70 62
63(defvar autoarg-kp-digits
64 (let (alist)
65 (dotimes (i 10 alist)
66 (push (cons (intern (format "kp-%d" i)) i) alist))))
67
68(defun autoarg-kp-digit-argument (arg)
69 "Part of the numeric argument for the next command, like `digit-argument'."
70 (interactive "P")
71 (let ((digit (cdr (assq last-command-char autoarg-kp-digits))))
72 (cond ((integerp arg)
73 (setq prefix-arg (+ (* arg 10)
74 (if (< arg 0) (- digit) digit))))
75 ((eq arg '-)
76 ;; Treat -0 as just -, so that -01 will work.
77 (setq prefix-arg (if (zerop digit) '- (- digit))))
78 (t
79 (setq prefix-arg digit))))
80 (setq universal-argument-num-events (length (this-command-keys)))
81 (setq overriding-terminal-local-map universal-argument-map))
82
83(defvar autoarg-kp-mode-map
84 (let ((map (make-sparse-keymap)))
85 ;; Loop over digit characters to set up keymap.
86 (dotimes (i 10)
87 (let ((sym (intern (format "kp-%d" i))))
88 (define-key map (vector sym) 'autoarg-kp-digit-argument)))
89 (define-key map [kp-subtract] 'negative-argument)
90 map)
91 "Keymap for Autoarg-KP mode.")
92
71;;;###autoload 93;;;###autoload
72(defun autoarg-mode (&optional arg) 94(define-minor-mode autoarg-mode
73 "Toggle Autoarg mode minor mode globally. 95 "Toggle Autoarg minor mode globally.
74With ARG, turn Autoarg mode on if ARG is positive, off otherwise. 96With ARG, turn Autoarg mode on if ARG is positive, off otherwise.
75\\<autoarg-mode-map> 97\\<autoarg-mode-map>
76In Autoarg mode digits are bound to `digit-argument' -- i.e. they 98In Autoarg mode digits are bound to `digit-argument' -- i.e. they
@@ -88,20 +110,29 @@ then invokes the normal binding of \\[autoarg-terminate].
88`C-u \\[autoarg-terminate]' invokes the normal binding of \\[autoarg-terminate] four times. 110`C-u \\[autoarg-terminate]' invokes the normal binding of \\[autoarg-terminate] four times.
89 111
90\\{autoarg-mode-map}" 112\\{autoarg-mode-map}"
91 (interactive "P") 113 (global . nil) " Aarg" autoarg-mode-map)
92 (let ((old-mode autoarg-mode))
93 (setq autoarg-mode (if (null arg)
94 (not autoarg-mode)
95 (> (prefix-numeric-value arg) 0))))
96 (if (interactive-p)
97 (message "Autoarg mode %sabled" (if autoarg-mode "en" "dis"))))
98 114
99(add-to-list 'minor-mode-alist '(autoarg-mode " Aarg")) 115;;;###autoload
100(add-to-list 'minor-mode-map-alist (cons 'autoarg-mode autoarg-mode-map)) 116(define-minor-mode autoarg-kp-mode
117 "Toggle Autoarg-KP minor mode globally.
118With ARG, turn Autoarg mode on if ARG is positive, off otherwise.
119\\<autoarg-kp-mode-map>
120This is similar to \\[autoarg-mode] but rebinds the keypad keys `kp-1'
121&c to supply digit arguments.
122
123\\{autoarg-kp-mode-map}"
124 (global . nil) " Aakp" autoarg-kp-mode-map
125 (if autoarg-kp-mode
126 (dotimes (i 10)
127 (let ((sym (intern (format "kp-%d" i))))
128 (define-key universal-argument-map (vector sym)
129 'autoarg-kp-digit-argument)))
130 (dotimes (i 10)
131 (let ((sym (intern (format "kp-%d" i))))
132 (define-key universal-argument-map (vector sym) nil)))))
101 133
102(defun autoarg-terminate (n) 134(defun autoarg-terminate (n)
103 "Maybe terminate a digit prefix sequence. 135 "Maybe terminate a digit prefix sequence.
104
105With a non-negative numeric prefix arg, insert the digits comprising 136With a non-negative numeric prefix arg, insert the digits comprising
106the arg into the current buffer. Otherwise use the binding of the key 137the arg into the current buffer. Otherwise use the binding of the key
107which invoked this function, excluding the Autoarg keymap." 138which invoked this function, excluding the Autoarg keymap."