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