Mercurial > emacs
annotate lisp/emulation/edt.el @ 807:4f28bd14272c
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Thu, 16 Jul 1992 21:47:34 +0000 |
parents | 6fb68a1460a6 |
children | e694e0879463 |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; edt.el --- EDT emulation in Emacs |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
3 ;; Author: Mike Clarkson <mike@yetti.UUCP> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
4 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
5 ;; Created: 27 Aug 1986 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
6 ;; Last-Modified: 09 May 1991 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
7 |
57 | 8 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
9 ;; It started from public domain code by Mike Clarkson | |
10 ;; but has been greatly altered. | |
11 | |
12 ;; This file is part of GNU Emacs. | |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
16 ;; the Free Software Foundation; either version 2, or (at your option) |
57 | 17 ;; any later version. |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
28 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
29 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
30 ;; Here's my EDT emulation for GNU Emacs that is based on the EDT emulation |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
31 ;; for Gosling's Emacs sent out on the net a couple of years ago by Lynn Olson |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
32 ;; at Tektronics. This emulation was widely distributed as the file edt.ml |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
33 ;; in the maclib directory of most Emacs distributions. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
34 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
35 ;; I will gladly take all criticisms and complaints to heart, and will fix what |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
36 ;; bugs I can find. As this is my first Emacs Lisp hack, you may have to root |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
37 ;; out a few nasties hidden in the code. Please let me know if you find any |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
38 ;; (sorry, no rewards :-). I would also be interested if there are better, |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
39 ;; cleaner, faster ways of doing some of the things that I have done. |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
40 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
41 ;; You must understand some design considerations that I had in mind. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
42 ;; The intention was not really to "emulate" EDT, but rather to take advantage |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
43 ;; of the years of EDT experience that had accumulated in my right hand, |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
44 ;; while at the same time taking advantage of EMACS. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
45 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
46 ;; Some major differences are: |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
47 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
48 ;; HELP is describe-key; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
49 ;; GOLD/HELP is describe-function; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
50 ;; FIND is isearch-forward/backward; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
51 ;; GOLD/HELP is occur-menu, which finds all instances of a search string; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
52 ;; ENTER is other-window; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
53 ;; SUBS is subprocess-command. Note that you have to change this |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
54 ;; to `shell' if you are running Un*x; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
55 ;; PAGE is next-paragraph, because that's more useful than page. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
56 ;; SPECINS is copy-to-killring; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
57 ;; GOLD/GOLD is mark-section-wisely, which is my command to mark the |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
58 ;; section in a manner consistent with the major-mode. It |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
59 ;; uses mark-defun for emacs-lisp, lisp, mark-c-function for C, |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
60 ;; and mark-paragraph for other modes. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
61 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
62 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
63 ;; Some subtle differences are: |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
64 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
65 ;; APPEND is append-to-buffer. One doesn't append to the kill ring |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
66 ;; much and SPECINS is now copy-to-killring; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
67 ;; REPLACE is replace-regexp; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
68 ;; FILL is fill-region-wisely, which uses indent-region for C, lisp |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
69 ;; emacs-lisp, and fill-region for others. It asks if you |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
70 ;; really want to fill-region in TeX-mode, because I find this |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
71 ;; to be very dangerous. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
72 ;; CHNGCASE is case-flip for the character under the cursor only. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
73 ;; I felt that case-flip region is unlikely, as usually you |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
74 ;; upcase-region or downcase region. Also, unlike EDT it |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
75 ;; is independent of the direction you are going, as that |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
76 ;; drives me nuts. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
77 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
78 ;; I use Emacs definition of what a word is. This is considerably different |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
79 ;; from what EDT thinks a word is. This is not good for dyed-in-the-wool EDT |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
80 ;; fans, but is probably preferable for experienced Emacs users. My assumption |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
81 ;; is that the former are a dying breed now that GNU Emacs has made it to VMS, |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
82 ;; but let me know how you feel. Also, when you undelete a word it leave the |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
83 ;; point at the end of the undeleted text, rather than the beginning. I might |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
84 ;; change this as I'm not sure if I like this or not. I'm also not sure if I |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
85 ;; want it to set the mark each time you delete a character or word. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
86 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
87 ;; Backspace does not invoke beginning-of-line, because ^H is the help prefix, |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
88 ;; and I felt it should be left as such. You can change this if you like. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
89 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
90 ;; The ADVANCE and BACKUP keys do not work as terminators for forward or |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
91 ;; backward searches. In Emacs, all search strings are terminated by return. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
92 ;; The searches will however go forward or backward depending on your current |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
93 ;; direction. Also, when you change directions, the mode line will not be |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
94 ;; updated immediately, but only when you next execute an emacs function. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
95 ;; Personally, I consider this to be a bug, not a feature. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
96 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
97 ;; This should also work with VT-2xx's, though I haven't tested it extensively |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
98 ;; on those terminals. It assumes that the CSI-map of vt_200.el has been |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
99 ;; defined. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
100 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
101 ;; There are also a whole bunch of GOLD letter, and GOLD character bindings: |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
102 ;; look at edtdoc.el for them, or better still, look at the edt.el lisp code, |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
103 ;; because after all, in the true Lisp tradition, the source code is *assumed* |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
104 ;; to be self-documenting :-) |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
105 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
106 ;; Mike Clarkson, ...!allegra \ BITNET: mike@YUYETTI or |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
107 ;; CRESS, York University, ...!decvax \ SYMALG@YUSOL |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
108 ;; 4700 Keele Street, ...!ihnp4 > !utzoo!yetti!mike |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
109 ;; North York, Ontario, ...!linus / |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
110 ;; CANADA M3J 1P3. ...!watmath / Phone: +1 (416) 736-2100 x 7767 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
111 ;; |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
112 ;; Note that I am not on ARPA, and must gateway any ARPA mail through BITNET or |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
113 ;; UUCP. If you have a UUCP or BITNET address please use it for communication |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
114 ;; so that I can reach you directly. If you have both, the BITNET address |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
115 ;; is preferred. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
116 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
117 ;;; Code: |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
660
diff
changeset
|
118 |
57 | 119 (require 'keypad) |
120 | |
121 (defvar edt-last-deleted-lines "" | |
199 | 122 "Last text deleted by an EDT emulation `line-delete' command.") |
57 | 123 (defvar edt-last-deleted-words "" |
199 | 124 "Last text deleted by an EDT emulation `word-delete' command.") |
57 | 125 (defvar edt-last-deleted-chars "" |
199 | 126 "Last text deleted by an EDT emulation `character-delete' command.") |
57 | 127 |
128 (defun delete-current-line (num) | |
129 "Delete one or specified number of lines after point. | |
130 This includes the newline character at the end of each line. | |
199 | 131 They are saved for the EDT `undelete-lines' command." |
57 | 132 (interactive "p") |
133 (let ((beg (point))) | |
134 (forward-line num) | |
135 (if (not (eq (preceding-char) ?\n)) | |
136 (insert "\n")) | |
137 (setq edt-last-deleted-lines | |
138 (buffer-substring beg (point))) | |
139 (delete-region beg (point)))) | |
140 | |
141 (defun delete-to-eol (num) | |
142 "Delete text up to end of line. | |
143 With argument, delete up to to Nth line-end past point. | |
199 | 144 They are saved for the EDT `undelete-lines' command." |
57 | 145 (interactive "p") |
146 (let ((beg (point))) | |
147 (forward-char 1) | |
148 (end-of-line num) | |
149 (setq edt-last-deleted-lines | |
150 (buffer-substring beg (point))) | |
151 (delete-region beg (point)))) | |
152 | |
153 (defun delete-current-word (num) | |
154 "Delete one or specified number of words after point. | |
199 | 155 They are saved for the EDT `undelete-words' command." |
57 | 156 (interactive "p") |
157 (let ((beg (point))) | |
158 (forward-word num) | |
159 (setq edt-last-deleted-words | |
160 (buffer-substring beg (point))) | |
161 (delete-region beg (point)))) | |
162 | |
163 (defun edt-delete-previous-word (num) | |
164 "Delete one or specified number of words before point. | |
199 | 165 They are saved for the EDT `undelete-words' command." |
57 | 166 (interactive "p") |
167 (let ((beg (point))) | |
168 (forward-word (- num)) | |
169 (setq edt-last-deleted-words | |
170 (buffer-substring (point) beg)) | |
171 (delete-region beg (point)))) | |
172 | |
173 (defun delete-current-char (num) | |
174 "Delete one or specified number of characters after point. | |
199 | 175 They are saved for the EDT `undelete-chars' command." |
57 | 176 (interactive "p") |
177 (setq edt-last-deleted-chars | |
178 (buffer-substring (point) (min (point-max) (+ (point) num)))) | |
179 (delete-region (point) (min (point-max) (+ (point) num)))) | |
180 | |
181 (defun delete-previous-char (num) | |
182 "Delete one or specified number of characters before point. | |
199 | 183 They are saved for the EDT `undelete-chars' command." |
57 | 184 (interactive "p") |
185 (setq edt-last-deleted-chars | |
186 (buffer-substring (max (point-min) (- (point) num)) (point))) | |
187 (delete-region (max (point-min) (- (point) num)) (point))) | |
188 | |
189 (defun undelete-lines () | |
199 | 190 "Yank lines deleted by last EDT `line-delete' command." |
57 | 191 (interactive) |
192 (insert edt-last-deleted-lines)) | |
193 | |
194 (defun undelete-words () | |
199 | 195 "Yank words deleted by last EDT `word-delete' command." |
57 | 196 (interactive) |
197 (insert edt-last-deleted-words)) | |
198 | |
199 (defun undelete-chars () | |
199 | 200 "Yank characters deleted by last EDT `character-delete' command." |
57 | 201 (interactive) |
202 (insert edt-last-deleted-chars)) | |
203 | |
204 (defun next-end-of-line (num) | |
205 "Move to end of line; if at end, move to end of next line. | |
206 Accepts a prefix argument for the number of lines to move." | |
207 (interactive "p") | |
208 (forward-char) | |
209 (end-of-line num)) | |
210 | |
211 (defun previous-end-of-line (num) | |
212 "Move EOL upward. | |
213 Accepts a prefix argument for the number of lines to move." | |
214 (interactive "p") | |
215 (end-of-line (- 1 num))) | |
216 | |
217 (defun forward-to-word (num) | |
218 "Move to next word-beginning, or to Nth following word-beginning." | |
219 (interactive "p") | |
220 (forward-word (1+ num)) | |
221 (forward-word -1)) | |
222 | |
223 (defun backward-to-word (num) | |
224 "Move back to word-end, or to Nth word-end seen." | |
225 (interactive "p") | |
226 (forward-word (- (1+ num))) | |
227 (forward-word 1)) | |
228 | |
229 (defun backward-line (num) | |
230 "Move point to start of previous line. | |
231 Prefix argument serves as repeat-count." | |
232 (interactive "p") | |
233 (forward-line (- num))) | |
234 | |
235 (defun scroll-window-down (num) | |
236 "Scroll the display down a window-full. | |
237 Accepts a prefix argument for the number of window-fulls to scroll." | |
238 (interactive "p") | |
239 (scroll-down (- (* (window-height) num) 2))) | |
240 | |
241 (defun scroll-window-up (num) | |
242 "Scroll the display up a window-full. | |
243 Accepts a prefix argument for the number of window-fulls to scroll." | |
244 (interactive "p") | |
245 (scroll-up (- (* (window-height) num) 2))) | |
246 | |
247 (defun next-paragraph (num) | |
248 "Move to beginning of the next indented paragraph. | |
249 Accepts a prefix argument for the number of paragraphs." | |
250 (interactive "p") | |
251 (while (> num 0) | |
252 (next-line 1) | |
253 (forward-paragraph) | |
254 (previous-line 1) | |
255 (if (eolp) (next-line 1)) | |
256 (setq num (1- num)))) | |
257 | |
258 (defun previous-paragraph (num) | |
259 "Move to beginning of previous indented paragraph. | |
260 Accepts a prefix argument for the number of paragraphs." | |
261 (interactive "p") | |
262 (while (> num 0) | |
263 (backward-paragraph) | |
264 (previous-line 1) | |
265 (if (eolp) (next-line 1)) | |
266 (setq num (1- num)))) | |
267 | |
268 (defun move-to-beginning () | |
269 "Move cursor to the beginning of buffer, but don't set the mark." | |
270 (interactive) | |
271 (goto-char (point-min))) | |
272 | |
273 (defun move-to-end () | |
274 "Move cursor to the end of buffer, but don't set the mark." | |
275 (interactive) | |
276 (goto-char (point-max))) | |
277 | |
278 (defun goto-percent (perc) | |
279 "Move point to ARG percentage of the buffer." | |
280 (interactive "NGoto-percentage: ") | |
281 (if (or (> perc 100) (< perc 0)) | |
282 (error "Percentage %d out of range 0 < percent < 100" perc) | |
283 (goto-char (/ (* (point-max) perc) 100)))) | |
284 | |
285 (defun update-mode-line () | |
199 | 286 "Ensure mode-line reflects all changes." |
57 | 287 (set-buffer-modified-p (buffer-modified-p)) |
288 (sit-for 0)) | |
289 | |
290 (defun advance-direction () | |
291 "Set EDT Advance mode so keypad commands move forward." | |
292 (interactive) | |
293 (setq edt-direction-string " ADVANCE") | |
294 (define-key function-keymap "\C-c" 'isearch-forward) ; PF3 | |
295 (define-key function-keymap "8" 'scroll-window-up) ; "8" | |
296 (define-key function-keymap "7" 'next-paragraph) ; "7" | |
297 (define-key function-keymap "1" 'forward-to-word) ; "1" | |
298 (define-key function-keymap "2" 'next-end-of-line) ; "2" | |
299 (define-key function-keymap "3" 'forward-char) ; "3" | |
300 (define-key function-keymap "0" 'forward-line) ; "0" | |
301 (update-mode-line)) | |
302 | |
303 (defun backup-direction () | |
304 "Set EDT Backup mode so keypad commands move backward." | |
305 (interactive) | |
306 (setq edt-direction-string " BACKUP") | |
307 (define-key function-keymap "\C-c" 'isearch-backward) ; PF3 | |
308 (define-key function-keymap "8" 'scroll-window-down) ; "8" | |
309 (define-key function-keymap "7" 'previous-paragraph) ; "7" | |
310 (define-key function-keymap "1" 'backward-to-word) ; "1" | |
311 (define-key function-keymap "2" 'previous-end-of-line) ; "2" | |
312 (define-key function-keymap "3" 'backward-char) ; "3" | |
313 (define-key function-keymap "0" 'backward-line) ; "0" | |
314 (update-mode-line)) | |
315 | |
316 (defun edt-beginning-of-window () | |
317 "Home cursor to top of window." | |
318 (interactive) | |
319 (move-to-window-line 0)) | |
320 | |
321 (defun edt-line-to-bottom-of-window () | |
322 "Move the current line to the top of the window." | |
323 (interactive) | |
324 (recenter -1)) | |
325 | |
326 (defun edt-line-to-top-of-window () | |
327 "Move the current line to the top of the window." | |
328 (interactive) | |
329 (recenter 0)) | |
330 | |
331 (defun case-flip-character (num) | |
332 "Change the case of the character under the cursor. | |
333 Accepts a prefix argument of the number of characters to invert." | |
334 (interactive "p") | |
335 (while (> num 0) | |
336 (funcall (if (<= ?a (following-char)) | |
337 'upcase-region 'downcase-region) | |
338 (point) (1+ (point))) | |
339 (forward-char 1) | |
340 (setq num (1- num)))) | |
341 | |
342 (defun indent-or-fill-region () | |
343 "Fill region in text modes, indent region in programming language modes." | |
344 (interactive) | |
345 (if (string= paragraph-start "^$\\|^") | |
346 (indent-region (point) (mark) nil) | |
347 (fill-region (point) (mark)))) | |
348 | |
349 (defun mark-section-wisely () | |
350 "Mark the section in a manner consistent with the major-mode. | |
351 Uses mark-defun for emacs-lisp, lisp, | |
352 mark-c-function for C, | |
353 and mark-paragraph for other modes." | |
354 (interactive) | |
355 (cond ((eq major-mode 'emacs-lisp-mode) | |
356 (mark-defun)) | |
357 ((eq major-mode 'lisp-mode) | |
358 (mark-defun)) | |
359 ((eq major-mode 'c-mode) | |
360 (mark-c-function)) | |
361 (t (mark-paragraph)))) | |
362 | |
363 ;;; Key Bindings | |
258 | 364 ;;;###autoload |
57 | 365 (defun edt-emulation-on () |
199 | 366 "Emulate DEC's EDT editor. |
367 Note that many keys are rebound; including nearly all keypad keys. | |
57 | 368 Use \\[edt-emulation-off] to undo all rebindings except the keypad keys. |
369 Note that this function does not work if called directly from the .emacs file. | |
199 | 370 Instead, the .emacs file should do \"(setq term-setup-hook 'edt-emulation-on)\" |
57 | 371 Then this function will be called at the time when it will work." |
372 (interactive) | |
373 (advance-direction) | |
374 (edt-bind-gold-keypad) ;Must do this *after* $TERM.el is loaded | |
375 (setq edt-mode-old-c-\\ (lookup-key global-map "\C-\\")) | |
376 (global-set-key "\C-\\" 'quoted-insert) | |
377 (setq edt-mode-old-delete (lookup-key global-map "\177")) | |
378 (global-set-key "\177" 'delete-previous-char) ;"Delete" | |
379 (setq edt-mode-old-lisp-delete (lookup-key emacs-lisp-mode-map "\177")) | |
380 (define-key emacs-lisp-mode-map "\177" 'delete-previous-char) ;"Delete" | |
381 (define-key lisp-mode-map "\177" 'delete-previous-char) ;"Delete" | |
382 (setq edt-mode-old-linefeed (lookup-key global-map "\C-j")) | |
383 (global-set-key "\C-j" 'edt-delete-previous-word) ;"LineFeed" | |
384 (define-key esc-map "?" 'apropos)) ;"<ESC>?" | |
385 | |
386 (defun edt-emulation-off () | |
387 "Return from EDT emulation to normal Emacs key bindings. | |
388 The keys redefined by \\[edt-emulation-on] are given their old definitions." | |
389 (interactive) | |
390 (setq edt-direction-string nil) | |
391 (global-set-key "\C-\\" edt-mode-old-c-\\) | |
392 (global-set-key "\177" edt-mode-old-delete) ;"Delete" | |
393 (define-key emacs-lisp-mode-map "\177" edt-mode-old-lisp-delete) ;"Delete" | |
394 (define-key lisp-mode-map "\177" edt-mode-old-lisp-delete) ;"Delete" | |
395 (global-set-key "\C-j" edt-mode-old-linefeed)) ;"LineFeed" | |
396 | |
397 (define-key function-keymap "u" 'previous-line) ;Up arrow | |
398 (define-key function-keymap "d" 'next-line) ;down arrow | |
399 (define-key function-keymap "l" 'backward-char) ;right arrow | |
400 (define-key function-keymap "r" 'forward-char) ;left arrow | |
401 (define-key function-keymap "h" 'edt-beginning-of-window) ;home | |
402 (define-key function-keymap "\C-b" 'describe-key) ;PF2 | |
403 (define-key function-keymap "\C-d" 'delete-current-line);PF4 | |
404 (define-key function-keymap "9" 'append-to-buffer) ;9 keypad key, etc. | |
405 (define-key function-keymap "-" 'delete-current-word) | |
406 (define-key function-keymap "4" 'advance-direction) | |
407 (define-key function-keymap "5" 'backup-direction) | |
408 (define-key function-keymap "6" 'kill-region) | |
409 (define-key function-keymap "," 'delete-current-char) | |
410 (define-key function-keymap "." 'set-mark-command) | |
411 (define-key function-keymap "e" 'other-window) ;enter key | |
412 (define-key function-keymap "\C-a" 'GOLD-prefix) ;PF1 ("gold") | |
413 | |
414 (fset 'GOLD-prefix GOLD-map) | |
415 | |
416 (defvar GOLD-map (make-keymap) | |
199 | 417 "`GOLD-map' maps the function keys on the VT100 keyboard preceeded |
57 | 418 by the PF1 key. GOLD is the ASCII the 7-bit escape sequence <ESC>OP.") |
419 | |
420 (defun define-keypad-key (keymap function-keymap-slot definition) | |
421 (let ((function-key-sequence (function-key-sequence function-keymap-slot))) | |
422 (if function-key-sequence | |
423 (define-key keymap function-key-sequence definition)))) | |
424 | |
425 ;;Bind GOLD/Keyboard keys | |
426 | |
427 (define-key GOLD-map "\C-g" 'keyboard-quit) ; just for safety | |
428 (define-key GOLD-map "\177" 'delete-window) ;"Delete" | |
429 (define-key GOLD-map "\C-h" 'delete-other-windows) ;"BackSpace" | |
430 (define-key GOLD-map "\C-m" 'newline-and-indent) ;"Return" | |
431 (define-key GOLD-map " " 'undo) ;"Spacebar" | |
432 (define-key GOLD-map "%" 'goto-percent) ; "%" | |
433 (define-key GOLD-map "=" 'goto-line) ; "=" | |
434 (define-key GOLD-map "`" 'what-line) ; "`" | |
435 (define-key GOLD-map "\C-\\" 'split-window-vertically) ; "Control-\" | |
436 | |
437 ; GOLD letter combinations: | |
438 (define-key GOLD-map "b" 'buffer-menu) ; "b" | |
439 (define-key GOLD-map "B" 'buffer-menu) ; "B" | |
440 (define-key GOLD-map "d" 'delete-window) ; "d" | |
441 (define-key GOLD-map "D" 'delete-window) ; "D" | |
442 (define-key GOLD-map "e" 'compile) ; "e" | |
443 (define-key GOLD-map "E" 'compile) ; "E" | |
444 (define-key GOLD-map "i" 'insert-file) ; "i" | |
445 (define-key GOLD-map "I" 'insert-file) ; "I" | |
446 (define-key GOLD-map "l" 'goto-line) ; "l" | |
447 (define-key GOLD-map "L" 'goto-line) ; "L" | |
448 (define-key GOLD-map "m" 'save-some-buffers) ; "m" | |
449 (define-key GOLD-map "M" 'save-some-buffers) ; "m" | |
450 (define-key GOLD-map "n" 'next-error) ; "n" | |
451 (define-key GOLD-map "N" 'next-error) ; "N" | |
452 (define-key GOLD-map "o" 'switch-to-buffer-other-window) ; "o" | |
453 (define-key GOLD-map "O" 'switch-to-buffer-other-window) ; "O" | |
454 (define-key GOLD-map "r" 'revert-file) ; "r" | |
455 (define-key GOLD-map "r" 'revert-file) ; "R" | |
456 (define-key GOLD-map "s" 'save-buffer) ; "s" | |
457 (define-key GOLD-map "S" 'save-buffer) ; "S" | |
458 (define-key GOLD-map "v" 'find-file-other-window) ; "v" | |
459 (define-key GOLD-map "V" 'find-file-other-window) ; "V" | |
460 (define-key GOLD-map "w" 'write-file) ; "w" | |
461 (define-key GOLD-map "w" 'write-file) ; "W" | |
462 ;(define-key GOLD-map "z" 'shrink-window) ; "z" | |
463 ;(define-key GOLD-map "Z" 'shrink-window) ; "z" | |
464 | |
465 ;Bind GOLD/Keypad keys | |
466 (defun edt-bind-gold-keypad () | |
467 (define-keypad-key GOLD-map ?u 'edt-line-to-top-of-window) ;"up-arrow" | |
468 (define-keypad-key GOLD-map ?d 'edt-line-to-bottom-of-window) ;"down-arrow" | |
469 (define-keypad-key GOLD-map ?l 'backward-sentence) ;"left-arrow" | |
470 (define-keypad-key GOLD-map ?r 'forward-sentence) ;"right-arrow" | |
471 (define-keypad-key GOLD-map ?\C-a 'mark-section-wisely) ;Gold "PF1" | |
472 (define-keypad-key GOLD-map ?\C-b 'describe-function) ;Help "PF2" | |
473 (define-keypad-key GOLD-map ?\C-c 'occur) ;Find "PF3" | |
474 (define-keypad-key GOLD-map ?\C-d 'undelete-lines) ;Und Line "PF4" | |
475 (define-keypad-key GOLD-map ?0 'open-line) ;Open L "0" | |
476 (define-keypad-key GOLD-map ?1 'case-flip-character) ;Chgcase "1" | |
477 (define-keypad-key GOLD-map ?2 'delete-to-eol) ;Del EOL "2" | |
478 (define-keypad-key GOLD-map ?3 'copy-region-as-kill) ;Copy "3" | |
479 (define-keypad-key GOLD-map ?4 'move-to-end) ;Bottom "4" | |
480 (define-keypad-key GOLD-map ?5 'move-to-beginning) ;Top "5" | |
481 (define-keypad-key GOLD-map ?6 'yank) ;Paste "6" | |
482 (define-keypad-key GOLD-map ?7 'execute-extended-command) ;Command "7" | |
483 (define-keypad-key GOLD-map ?8 'indent-or-fill-region) ;Fill "8" | |
484 (define-keypad-key GOLD-map ?9 'replace-regexp) ;Replace "9" | |
485 (define-keypad-key GOLD-map ?- 'undelete-words) ;UND word "-" | |
486 (define-keypad-key GOLD-map ?, 'undelete-chars) ;UND Char "," | |
487 (define-keypad-key GOLD-map ?. 'redraw-display) ;Reset Window "." | |
488 (define-keypad-key GOLD-map ?e 'shell-command)) ;"ENTER" | |
489 | |
490 ;; Make direction of motion show in mode line | |
491 ;; while EDT emulation is turned on. | |
492 ;; Note that the keypad is always turned on when in Emacs. | |
493 | |
494 (or (assq 'edt-direction-string minor-mode-alist) | |
495 (setq minor-mode-alist (cons '(edt-direction-string edt-direction-string) | |
496 minor-mode-alist))) | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
497 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
498 ;;; edt.el ends here |