]> code.delx.au - gnu-emacs/blob - lisp/term/sun.el
*** empty log message ***
[gnu-emacs] / lisp / term / sun.el
1 ;; keybinding for standard default sunterm keys
2 ;; Copyright (C) 1987 Free Software Foundation, Inc.
3
4 ;; This file is part of GNU Emacs.
5
6 ;; GNU Emacs is distributed in the hope that it will be useful,
7 ;; but WITHOUT ANY WARRANTY. No author or distributor
8 ;; accepts responsibility to anyone for the consequences of using it
9 ;; or for whether it serves any particular purpose or works at all,
10 ;; unless he says so in writing. Refer to the GNU Emacs General Public
11 ;; License for full details.
12
13 ;; Everyone is granted permission to copy, modify and redistribute
14 ;; GNU Emacs, but only under the conditions described in the
15 ;; GNU Emacs General Public License. A copy of this license is
16 ;; supposed to have been given to you along with GNU Emacs so you
17 ;; can know your rights and responsibilities. It should be in a
18 ;; file named COPYING. Among other things, the copyright notice
19 ;; and this notice must be preserved on all copies.
20
21 ;; Jeff Peck, Sun Microsystems Inc <peck@sun.com>
22
23 ;; The function key sequences for the console have been converted for
24 ;; use with function-key-map, but the *tool stuff hasn't been touched.
25
26
27 (defun ignore-key ()
28 "interactive version of ignore"
29 (interactive)
30 (ignore))
31
32 (defun scroll-down-in-place (n)
33 (interactive "p")
34 (previous-line n)
35 (scroll-down n))
36
37 (defun scroll-up-in-place (n)
38 (interactive "p")
39 (next-line n)
40 (scroll-up n))
41
42 (defun kill-region-and-unmark (beg end)
43 "Like kill-region, but pops the mark [which equals point, anyway.]"
44 (interactive "r")
45 (kill-region beg end)
46 (setq this-command 'kill-region-and-unmark)
47 (set-mark-command t))
48
49 (defun select-previous-complex-command ()
50 "Select Previous-complex-command"
51 (interactive)
52 (if (zerop (minibuffer-depth))
53 (repeat-complex-command 1)
54 (previous-complex-command 1)))
55
56 (defun rerun-prev-command ()
57 "Repeat Previous-complex-command."
58 (interactive)
59 (eval (nth 0 command-history)))
60
61 (defvar grep-arg nil "Default arg for RE-search")
62 (defun grep-arg ()
63 (if (memq last-command '(research-forward research-backward)) grep-arg
64 (let* ((command (car command-history))
65 (command-name (symbol-name (car command)))
66 (search-arg (car (cdr command)))
67 (search-command
68 (and command-name (string-match "search" command-name)))
69 )
70 (if (and search-command (stringp search-arg)) (setq grep-arg search-arg)
71 (setq search-command this-command
72 grep-arg (read-string "REsearch: " grep-arg)
73 this-command search-command)
74 grep-arg))))
75
76 (defun research-forward ()
77 "Repeat RE search forward."
78 (interactive)
79 (re-search-forward (grep-arg)))
80
81 (defun research-backward ()
82 "Repeat RE search backward."
83 (interactive)
84 (re-search-backward (grep-arg)))
85 \f
86 ;;;
87 ;;; handle sun's extra function keys
88 ;;; this version for those who run with standard .ttyswrc and no emacstool
89 ;;;
90 ;;; sunview picks up expose and open on the way UP,
91 ;;; so we ignore them on the way down
92 ;;;
93
94 (defvar sun-esc-bracket nil
95 "*If non-nil, rebind ESC [ as prefix for Sun function keys.")
96
97 (define-prefix-command 'sun-raw-prefix)
98 (define-key function-key-map "\e[" 'sun-raw-prefix)
99
100 (define-key sun-raw-prefix "210z" [r3])
101 (define-key sun-raw-prefix "213z" [r6])
102 (define-key sun-raw-prefix "214z" [r7])
103 (define-key sun-raw-prefix "216z" [r9])
104 (define-key sun-raw-prefix "218z" [r11])
105 (define-key sun-raw-prefix "220z" [r13])
106 (define-key sun-raw-prefix "222z" [r15])
107 (define-key sun-raw-prefix "193z" [again])
108 (define-key sun-raw-prefix "194z" [props])
109 (define-key sun-raw-prefix "195z" [undo])
110 ; (define-key sun-raw-prefix "196z" 'ignore-key) ; Expose-down
111 ; (define-key sun-raw-prefix "197z" [put])
112 ; (define-key sun-raw-prefix "198z" 'ignore-key) ; Open-down
113 ; (define-key sun-raw-prefix "199z" [get])
114 (define-key sun-raw-prefix "200z" [find])
115 ; (define-key sun-raw-prefix "201z" 'kill-region-and-unmark) ; Delete
116 (define-key sun-raw-prefix "226z" [t3])
117 (define-key sun-raw-prefix "227z" [t4])
118 (define-key sun-raw-prefix "229z" [t6])
119 (define-key sun-raw-prefix "230z" [t7])
120 (define-key sun-raw-prefix "A" [up]) ; R8
121 (define-key sun-raw-prefix "B" [down]) ; R14
122 (define-key sun-raw-prefix "C" [right]) ; R12
123 (define-key sun-raw-prefix "D" [left]) ; R10
124
125 (global-set-key [r3] 'backward-page)
126 (global-set-key [r6] 'forward-page)
127 (global-set-key [r7] 'beginning-of-buffer)
128 (global-set-key [r9] 'scroll-down)
129 (global-set-key [r11] 'recenter)
130 (global-set-key [r13] 'end-of-buffer)
131 (global-set-key [r15] 'scroll-up)
132 (global-set-key [again] 'redraw-display)
133 (global-set-key [props] 'list-buffers)
134 (global-set-key [undo] 'undo)
135 (global-set-key [put] 'sun-select-region)
136 (global-set-key [get] 'sun-yank-selection)
137 (global-set-key [find] 'exchange-point-and-mark)
138 (global-set-key [t3] 'scroll-down-in-place)
139 (global-set-key [t4] 'scroll-up-in-place)
140 (global-set-key [t6] 'shrink-window)
141 (global-set-key [t7] 'enlarge-window)
142
143
144 (if sun-esc-bracket (global-unset-key "\e["))
145
146 ;;; Since .emacs gets loaded before this file, a hook is supplied
147 ;;; for you to put your own bindings in.
148
149 (defvar sun-raw-prefix-hooks nil
150 "List of forms to evaluate after setting sun-raw-prefix.")
151
152 (let ((hooks sun-raw-prefix-hooks))
153 (while hooks
154 (eval (car hooks))
155 (setq hooks (cdr hooks))
156 ))
157
158 \f
159 ;;; This section adds defintions for the emacstool users
160 ;;; emacstool event filter converts function keys to C-x*{c}{lrt}
161 ;;;
162 ;;; for example the Open key (L7) would be encoded as "\C-x*gl"
163 ;;; the control, meta, and shift keys modify the character {lrt}
164 ;;; note that (unshifted) C-l is ",", C-r is "2", and C-t is "4"
165 ;;;
166 ;;; {c} is [a-j] for LEFT, [a-i] for TOP, [a-o] for RIGHT.
167 ;;; A higher level insists on encoding {h,j,l,n}{r} (the arrow keys)
168 ;;; as ANSI escape sequences. Use the shell command
169 ;;; % setkeys noarrows
170 ;;; if you want these to come through for emacstool.
171 ;;;
172 ;;; If you are not using EmacsTool,
173 ;;; you can also use this by creating a .ttyswrc file to do the conversion.
174 ;;; but it won't include the CONTROL, META, or SHIFT keys!
175 ;;;
176 ;;; Important to define SHIFTed sequence before matching unshifted sequence.
177 ;;; (talk about bletcherous old uppercase terminal conventions!*$#@&%*&#$%)
178 ;;; this is worse than C-S/C-Q flow control anyday!
179 ;;; Do *YOU* run in capslock mode?
180 ;;;
181
182 ;;; Note: al, el and gl are trapped by EmacsTool, so they never make it here.
183
184 (defvar meta-flag t)
185
186 (defvar suntool-map (make-sparse-keymap)
187 "*Keymap for Emacstool bindings.")
188
189 (define-key suntool-map "gr" 'beginning-of-buffer) ; r7
190 (define-key suntool-map "iR" 'backward-page) ; R9
191 (define-key suntool-map "ir" 'scroll-down) ; r9
192 (define-key suntool-map "kr" 'recenter) ; r11
193 (define-key suntool-map "mr" 'end-of-buffer) ; r13
194 (define-key suntool-map "oR" 'forward-page) ; R15
195 (define-key suntool-map "or" 'scroll-up) ; r15
196 (define-key suntool-map "b\M-L" 'rerun-prev-command) ; M-AGAIN
197 (define-key suntool-map "b\M-l" 'prev-complex-command) ; M-Again
198 (define-key suntool-map "bl" 'redraw-display) ; Again
199 (define-key suntool-map "cl" 'list-buffers) ; Props
200 (define-key suntool-map "dl" 'undo) ; Undo
201 (define-key suntool-map "el" 'ignore-key) ; Expose-Open
202 (define-key suntool-map "fl" 'sun-select-region) ; Put
203 (define-key suntool-map "f," 'copy-region-as-kill) ; C-Put
204 (define-key suntool-map "gl" 'ignore-key) ; Open-Open
205 (define-key suntool-map "hl" 'sun-yank-selection) ; Get
206 (define-key suntool-map "h," 'yank) ; C-Get
207 (define-key suntool-map "il" 'research-forward) ; Find
208 (define-key suntool-map "i," 're-search-forward) ; C-Find
209 (define-key suntool-map "i\M-l" 'research-backward) ; M-Find
210 (define-key suntool-map "i\M-," 're-search-backward) ; C-M-Find
211
212 (define-key suntool-map "jL" 'yank) ; DELETE
213 (define-key suntool-map "jl" 'kill-region-and-unmark) ; Delete
214 (define-key suntool-map "j\M-l" 'exchange-point-and-mark); M-Delete
215 (define-key suntool-map "j,"
216 '(lambda () (interactive) (pop-mark 1))) ; C-Delete
217
218 (define-key suntool-map "fT" 'shrink-window-horizontally) ; T6
219 (define-key suntool-map "gT" 'enlarge-window-horizontally) ; T7
220 (define-key suntool-map "ft" 'shrink-window) ; t6
221 (define-key suntool-map "gt" 'enlarge-window) ; t7
222 (define-key suntool-map "cT" '(lambda(n) (interactive "p") (scroll-down n)))
223 (define-key suntool-map "dT" '(lambda(n) (interactive "p") (scroll-up n)))
224 (define-key suntool-map "ct" 'scroll-down-in-place) ; t3
225 (define-key suntool-map "dt" 'scroll-up-in-place) ; t4
226 (define-key ctl-x-map "*" suntool-map)
227
228 ;;; Since .emacs gets loaded before this file, a hook is supplied
229 ;;; for you to put your own bindings in.
230
231 (defvar suntool-map-hooks nil
232 "List of forms to evaluate after setting suntool-map.")
233
234 (let ((hooks suntool-map-hooks))
235 (while hooks
236 (eval (car hooks))
237 (setq hooks (cdr hooks))
238 ))
239
240 ;;;
241 ;;; If running under emacstool, arrange to call suspend-emacstool
242 ;;; instead of suspend-emacs.
243 ;;;
244 ;;; First mouse blip is a clue that we are in emacstool.
245 ;;;
246 ;;; C-x C-@ is the mouse command prefix.
247
248 (autoload 'sun-mouse-handler "sun-mouse"
249 "Sun Emacstool handler for mouse blips (not loaded)." t)
250
251 (defun emacstool-init ()
252 "Set up Emacstool window, if you know you are in an emacstool."
253 ;; Make sure sun-mouse and sun-fns are loaded.
254 (require 'sun-fns)
255 (define-key ctl-x-map "\C-@" 'sun-mouse-handler)
256
257 (if (< (sun-window-init) 0)
258 (message "Not a Sun Window")
259 (progn
260 (substitute-key-definition 'suspend-emacs 'suspend-emacstool global-map)
261 (substitute-key-definition 'suspend-emacs 'suspend-emacstool esc-map)
262 (substitute-key-definition 'suspend-emacs 'suspend-emacstool ctl-x-map))
263 (send-string-to-terminal
264 (concat "\033]lEmacstool - GNU Emacs " emacs-version "\033\\"))
265 ))
266
267 (defun sun-mouse-once ()
268 "Converts to emacstool and sun-mouse-handler on first mouse hit."
269 (interactive)
270 (emacstool-init)
271 (sun-mouse-handler) ; Now, execute this mouse blip.
272 )
273 (define-key ctl-x-map "\C-@" 'sun-mouse-once)