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