annotate lisp/autoarg.el @ 28973:d87cf6d0bd48

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