28908
|
1 ;;; autoarg.el --- make digit keys supply prefix args
|
|
2
|
|
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Dave Love <fx@gnu.org>
|
|
6 ;; Created: 1998-09-04
|
|
7 ;; Keywords: abbrev, emulations
|
|
8
|
|
9 ;; Autoarg Mode is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; Autoarg Mode is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;; This provides `autoarg-mode', a global minor mode meant to emulate
|
|
27 ;; a facility reported from Twenex Emacs whereby digit keys supplied
|
|
28 ;; prefix args rather than self inserting, with a digit sequence
|
|
29 ;; terminated by space acting to insert the digits.
|
|
30
|
|
31 ;; The bindings of DIGIT and C-DIGIT are swapped and a command bound
|
|
32 ;; to SPC deals with a numeric prefix arg or acts normally without
|
|
33 ;; such an arg. (In the absence of a suitable terminal, you'd
|
|
34 ;; probably want to swap DIGIT and M-DIGIT.) See the mode doc.
|
|
35
|
|
36 ;; You probably don't really want to use this.
|
|
37
|
|
38 ;;; Code:
|
|
39
|
|
40 ;;;###autoload
|
|
41 (defcustom autoarg-mode nil
|
|
42 "Toggle Autoarg mode.
|
|
43
|
|
44 You must modify via \\[customize] for this variable to have an effect."
|
|
45 :set (lambda (symbol vaautoarg-mode (or value 0)))
|
|
46 :initialize 'custom-initialize-default
|
|
47 :type 'boolean
|
|
48 :group 'editing
|
|
49 :require 'autoarg)
|
|
50 ;; If you wanted a local mode:
|
|
51 ;; (make-variable-buffer-local 'autoarg-mode)
|
|
52
|
|
53 (defvar autoarg-mode-map (make-sparse-keymap)
|
|
54 "Keymap for Autoarg Mode.")
|
|
55
|
|
56 ;; Loop over digit characters to set up keymap.
|
|
57 (let ((i ?0))
|
|
58 (while (<= i ?9)
|
|
59 (define-key autoarg-mode-map `[,i] 'digit-argument)
|
|
60 (define-key autoarg-mode-map `[(control ,i)] 'self-insert-command)
|
|
61 (setq i (1+ i))))
|
|
62 (define-key autoarg-mode-map " " 'autoarg-terminate)
|
|
63 ;; Logical additions:
|
|
64 ;; (define-key autoarg-mode-map [?-] 'negative-argument)
|
|
65 ;; (define-key autoarg-mode-map [(control ?-)] 'self-insert-command)
|
|
66 ;; A sensible/addition?
|
|
67 ;; (define-key autoarg-mode-map [?\r] 'autoarg-terminate)
|
|
68
|
|
69 ;;;###autoload
|
|
70 (defun autoarg-mode (&optional arg)
|
|
71 "Toggle Autoarg mode minor mode globally.
|
|
72 With ARG, turn Autoarg mode on if ARG is positive, off otherwise.
|
|
73 \\<autoarg-mode-map>
|
|
74 In Autoarg mode digits are bound to `digit-argument' -- i.e. they
|
|
75 supply prefix arguments as C-DIGIT and M-DIGIT normally do -- and
|
|
76 C-DIGIT inserts DIGIT. \\[autoarg-terminate] terminates the prefix sequence
|
|
77 and inserts the digits of the autoarg sequence into the buffer.
|
|
78 Without a numeric prefix arg the normal binding of \\[autoarg-terminate] is
|
|
79 invoked, i.e. what it would be with Autoarg mode off.
|
|
80
|
|
81 For example:
|
|
82 `6 9 \\[autoarg-terminate]' inserts `69' into the buffer, as does `C-6 C-9'.
|
|
83 `6 9 a' inserts 69 `a's into the buffer.
|
|
84 `6 9 \\[autoarg-terminate] \\[autoarg-terminate]' inserts `69' into the buffer and
|
|
85 then invokes the normal binding of \\[autoarg-terminate].
|
|
86 `C-u \\[autoarg-terminate]' invokes the normal binding of \\[autoarg-terminate] four times.
|
|
87
|
|
88 \\{autoarg-mode-map}"
|
|
89 (interactive "P")
|
|
90 (let ((old-mode autoarg-mode))
|
|
91 (setq autoarg-mode (if (null arg)
|
|
92 (not autoarg-mode)
|
|
93 (> (prefix-numeric-value arg) 0))))
|
|
94 (if (interactive-p)
|
|
95 (message "Autoarg mode %sabled" (if autoarg-mode "en" "dis"))))
|
|
96
|
|
97 (add-to-list 'minor-mode-alist '(autoarg-mode " Aarg"))
|
|
98 (add-to-list 'minor-mode-map-alist (cons 'autoarg-mode autoarg-mode-map))
|
|
99
|
|
100 (defun autoarg-terminate (n)
|
|
101 "Maybe terminate a digit prefix sequence.
|
|
102
|
|
103 With a non-negative numeric prefix arg, insert the digits comprising
|
|
104 the arg into the current buffer. Otherwise use the binding of the key
|
|
105 which invoked this function, excluding the Autoarg keymap."
|
|
106 (interactive "P")
|
|
107 (if (numberp n)
|
|
108 (insert (number-to-string n))
|
|
109 (let* ((autoarg-mode nil) ; hide the bindings
|
|
110 (binding (key-binding (this-single-command-keys))))
|
|
111 (if binding (call-interactively binding)))))
|
|
112
|
|
113 (provide 'autoarg)
|
|
114
|
|
115 ;;; autoarg.el ends here
|