Mercurial > emacs
annotate lisp/double.el @ 7777:c48a233494e1
(lunar-phase): Revised to use the rewritten and new fcns.
author | Edward M. Reingold <reingold@emr.cs.iit.edu> |
---|---|
date | Fri, 03 Jun 1994 20:25:44 +0000 |
parents | 89ed0051e237 |
children | 049bc48732d6 |
rev | line source |
---|---|
6000 | 1 ;;; double.el - Support for keyboard remapping with double clicking. |
2 | |
6001 | 3 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
6000 | 4 |
5 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk> | |
6 ;; Keywords: i18n | |
7 | |
6001 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
6000 | 11 ;; it under the terms of the GNU General Public License as published by |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
6001 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
6000 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
6001 | 19 |
6000 | 20 ;; You should have received a copy of the GNU General Public License |
6001 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
6000 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; This mode is intended for use with languages that adds a small | |
27 ;; number of extra letters not available on the keyboard. | |
28 ;; | |
29 ;; Examples includes Scandinavian and German with an US keyboard. | |
30 ;; | |
31 ;; The idea is that certain keys are overloaded. When you press it | |
32 ;; once it will insert one string, and when you press it twice the | |
33 ;; string will be replaced by another. This can be used for mapping | |
34 ;; keys on a US keyboard to generate characters according to the local | |
35 ;; keyboard convention when pressed once, and according to US keyboard | |
36 ;; convetion when pressed twice. | |
37 ;; | |
38 ;; To use this mode, you must define the variable `double-map' and | |
39 ;; then enable double mode with `M-x double-mode'. Read the | |
40 ;; documentation for both of them. | |
41 ;; | |
42 ;; The default mapping is for getting Danish/Norwegian keyboard layout | |
43 ;; using ISO Latin 1 on a US keyboard. | |
44 ;; | |
45 ;; Requires FSF Emacs 19.20 or later. | |
46 ;; | |
47 ;; Imprtant node: While I would like to hear comments, bug reports, | |
48 ;; suggestions, please do @strong{not} expect me to put other mappings | |
49 ;; that the default into this file. There are billions and billions | |
50 ;; of such mappings, and just supporting the most common would | |
51 ;; increase the size of this nice small file manyfold. | |
52 | |
53 ;;; ChangeLog: | |
54 | |
55 ;; * 1994-02-03 Per Abrahamsen | |
56 ;; Created. | |
57 | |
58 ;;; Code: | |
59 | |
60 (defvar double-map | |
61 '((?\; "\346" ";") | |
62 (?\' "\370" "'") | |
63 (?\[ "\345" "[") | |
64 (?\: "\306" ":") | |
65 (?\" "\330" "\"") | |
66 (?\{ "\305" "{")) | |
67 "Alist of key translations activated by double mode. | |
68 | |
69 Each entry is a list with three elements: | |
70 1. The key activating the translation. | |
71 2. The string to be inserted when the key is pressed once. | |
72 3. The string to be inserted when the key is pressed twice.") | |
73 | |
74 ;;; Read Event | |
75 | |
76 (defvar double-last-event nil) | |
77 ;; The last key that generated a double key event. | |
78 | |
79 (defun double-read-event (prompt) | |
80 ;; Read an event | |
81 (if isearch-mode (isearch-update)) | |
82 (if prompt | |
83 (prog2 (message "%s%c" prompt double-last-event) | |
84 (read-event) | |
85 (message "")) | |
86 (read-event))) | |
87 | |
7279
89ed0051e237
(double-translate-key): Changed 'delete to 127 to make
Richard M. Stallman <rms@gnu.org>
parents:
6001
diff
changeset
|
88 (global-set-key [ignore] '(lambda () (interactive))) |
6000 | 89 |
90 (or (boundp 'isearch-mode-map) | |
91 (load-library "isearch")) | |
92 | |
7279
89ed0051e237
(double-translate-key): Changed 'delete to 127 to make
Richard M. Stallman <rms@gnu.org>
parents:
6001
diff
changeset
|
93 (define-key isearch-mode-map [ignore] |
6000 | 94 (function (lambda () (interactive) (isearch-update)))) |
95 | |
96 (defun double-translate-key (prompt) | |
97 ;; Translate input events using double map. | |
98 (let ((key last-input-char)) | |
99 (cond (unread-command-events | |
100 ;; Artificial event, ignore it. | |
101 (vector key)) | |
102 ((eq key 'magic-start) | |
103 ;; End of generated event. See if he will repeat it... | |
104 (let ((new (double-read-event prompt)) | |
105 (entry (assoc double-last-event double-map))) | |
106 (if (eq new double-last-event) | |
107 (progn | |
108 (setq unread-command-events | |
109 (append (make-list (1- (length (nth 1 entry))) | |
7279
89ed0051e237
(double-translate-key): Changed 'delete to 127 to make
Richard M. Stallman <rms@gnu.org>
parents:
6001
diff
changeset
|
110 127) |
6000 | 111 (nth 2 entry) |
112 '(magic-end))) | |
113 (vector 127)) | |
114 (setq unread-command-events (list new)) | |
7279
89ed0051e237
(double-translate-key): Changed 'delete to 127 to make
Richard M. Stallman <rms@gnu.org>
parents:
6001
diff
changeset
|
115 [ignore]))) |
6000 | 116 ((eq key 'magic-end) |
117 ;; End of double event. Ignore. | |
7279
89ed0051e237
(double-translate-key): Changed 'delete to 127 to make
Richard M. Stallman <rms@gnu.org>
parents:
6001
diff
changeset
|
118 [ignore]) |
6000 | 119 (t |
120 ;; New key. | |
121 (let ((exp (nth 1 (assoc key double-map)))) | |
122 (setq double-last-event key) | |
123 (setq unread-command-events | |
124 (append (substring exp 1) '(magic-start))) | |
125 (vector (aref exp 0))))))) | |
126 | |
127 ;;; Key Translation Map | |
128 | |
129 (defvar default-key-translation-map | |
130 (or key-translation-map (make-sparse-keymap)) | |
131 "Key translation you want to have effect, regardless of double mode. | |
132 This will default to the value of `key-translation-map' when double was | |
133 first loaded.") | |
134 | |
135 (make-variable-buffer-local 'key-translation-map) | |
136 | |
137 (defun double-setup () | |
138 ;; Setup key-translation-map as indicated by `double-map'. | |
139 (setq key-translation-map (copy-keymap default-key-translation-map)) | |
140 (mapcar (function (lambda (entry) | |
141 (define-key key-translation-map (vector (nth 0 entry)) | |
142 'double-translate-key))) | |
143 (append double-map '((magic-start) (magic-end))))) | |
144 | |
145 ;;; Mode | |
146 | |
147 (defvar double-mode nil) | |
148 ;; Indicator for the double mode. | |
149 (make-variable-buffer-local 'double-mode) | |
150 | |
151 (or (assq 'double-mode minor-mode-alist) | |
152 (setq minor-mode-alist | |
153 (cons '(double-mode (" " double-mode-name)) minor-mode-alist))) | |
154 | |
155 (defvar double-mode-name "Double") | |
156 ;; Name of current double mode. | |
157 (make-variable-buffer-local 'double-mode-name) | |
158 | |
159 ;;;###autoload | |
160 (defun double-mode (arg) | |
161 "Toggle double mode. | |
162 With prefix arg, turn double mode on iff arg is positive. | |
163 | |
164 When double mode is on, some keys will insert will insert different | |
165 strings when pressed twice. See variable `double-map' for details." | |
166 (interactive "P") | |
167 (if (or (and (null arg) double-mode) | |
168 (<= (prefix-numeric-value arg) 0)) | |
169 ;; Turn it off | |
170 (if double-mode | |
171 (progn | |
172 (let ((double-map)) | |
173 (double-setup)) | |
174 (setq double-mode nil) | |
175 (set-buffer-modified-p (buffer-modified-p)))) | |
176 ;;Turn it on | |
177 (if double-mode | |
178 () | |
179 (double-setup) | |
180 (setq double-mode t) | |
181 (set-buffer-modified-p (buffer-modified-p))))) | |
182 | |
183 (provide 'double) | |
184 | |
185 ;;; double.el ends here | |
186 |