sun.el 10.4 KB
Newer Older
Richard M. Stallman's avatar
Richard M. Stallman committed
1
;;; sun.el --- keybinding for standard default sunterm keys
2

3
;; Copyright (C) 1987, 2001, 2002, 2003, 2004,
Glenn Morris's avatar
Glenn Morris committed
4
;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Erik Naggum's avatar
Erik Naggum committed
5

6 7 8
;; Author: Jeff Peck <peck@sun.com>
;; Keywords: terminals

Erik Naggum's avatar
Erik Naggum committed
9 10 11 12
;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
13
;; the Free Software Foundation; either version 3, or (at your option)
Erik Naggum's avatar
Erik Naggum committed
14 15 16 17 18 19
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
Jim Blandy's avatar
Jim Blandy committed
20

Erik Naggum's avatar
Erik Naggum committed
21 22
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
23 24
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Jim Blandy's avatar
Jim Blandy committed
25

26
;;; Commentary:
Jim Blandy's avatar
Jim Blandy committed
27 28 29 30

;; The function key sequences for the console have been converted for
;; use with function-key-map, but the *tool stuff hasn't been touched.

31
;;; Code:
Jim Blandy's avatar
Jim Blandy committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

(defun scroll-down-in-place (n)
  (interactive "p")
  (previous-line n)
  (scroll-down n))

(defun scroll-up-in-place (n)
  (interactive "p")
  (next-line n)
  (scroll-up n))

(defun kill-region-and-unmark (beg end)
  "Like kill-region, but pops the mark [which equals point, anyway.]"
  (interactive "r")
  (kill-region beg end)
  (setq this-command 'kill-region-and-unmark)
  (set-mark-command t))

(defun select-previous-complex-command ()
  "Select Previous-complex-command"
  (interactive)
  (if (zerop (minibuffer-depth))
      (repeat-complex-command 1)
55
    ;; FIXME: this function does not seem to exist.  -stef'01
Jim Blandy's avatar
Jim Blandy committed
56 57 58 59 60 61 62 63 64 65 66 67 68
    (previous-complex-command 1)))

(defun rerun-prev-command ()
  "Repeat Previous-complex-command."
  (interactive)
  (eval (nth 0 command-history)))

(defvar grep-arg nil "Default arg for RE-search")
(defun grep-arg ()
  (if (memq last-command '(research-forward research-backward)) grep-arg
    (let* ((command (car command-history))
	   (command-name (symbol-name (car command)))
	   (search-arg (car (cdr command)))
69
	   (search-command
Jim Blandy's avatar
Jim Blandy committed
70 71 72
	    (and command-name (string-match "search" command-name)))
	   )
      (if (and search-command (stringp search-arg)) (setq grep-arg search-arg)
73
	(setq search-command this-command
Jim Blandy's avatar
Jim Blandy committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87
	      grep-arg (read-string "REsearch: " grep-arg)
	      this-command search-command)
	grep-arg))))

(defun research-forward ()
  "Repeat RE search forward."
  (interactive)
  (re-search-forward (grep-arg)))

(defun research-backward ()
  "Repeat RE search backward."
  (interactive)
  (re-search-backward (grep-arg)))

88 89 90 91
;;
;; handle sun's extra function keys
;; this version for those who run with standard .ttyswrc and no emacstool
;;
92
;; sunview picks up expose and open on the way UP,
93 94
;; so we ignore them on the way down
;;
Jim Blandy's avatar
Jim Blandy committed
95

96
(defvar sun-raw-prefix (make-sparse-keymap))
Jim Blandy's avatar
Jim Blandy committed
97

98 99
;; Since .emacs gets loaded before this file, a hook is supplied
;; for you to put your own bindings in.
Jim Blandy's avatar
Jim Blandy committed
100

Jim Blandy's avatar
Jim Blandy committed
101 102
(defvar sun-raw-prefix-hooks nil
  "List of forms to evaluate after setting sun-raw-prefix.")
Jim Blandy's avatar
Jim Blandy committed
103 104


105
;;; This section adds definitions for the emacstool users
106 107 108 109 110 111 112 113
;; emacstool event filter converts function keys to C-x*{c}{lrt}
;;
;; for example the Open key (L7) would be encoded as "\C-x*gl"
;; the control, meta, and shift keys modify the character {lrt}
;; note that (unshifted) C-l is ",",  C-r is "2", and C-t is "4"
;;
;; {c} is [a-j] for LEFT, [a-i] for TOP, [a-o] for RIGHT.
;; A higher level insists on encoding {h,j,l,n}{r} (the arrow keys)
114
;; as ANSI escape sequences.  Use the shell command
115 116 117
;; % setkeys noarrows
;; if you want these to come through for emacstool.
;;
118
;; If you are not using EmacsTool,
119 120 121 122 123 124 125 126 127 128
;; you can also use this by creating a .ttyswrc file to do the conversion.
;; but it won't include the CONTROL, META, or SHIFT keys!
;;
;; Important to define SHIFTed sequence before matching unshifted sequence.
;; (talk about bletcherous old uppercase terminal conventions!*$#@&%*&#$%)
;;  this is worse than C-S/C-Q flow control anyday!
;;  Do *YOU* run in capslock mode?
;;

;; Note:  al, el and gl are trapped by EmacsTool, so they never make it here.
Jim Blandy's avatar
Jim Blandy committed
129 130 131 132 133

(defvar suntool-map (make-sparse-keymap)
  "*Keymap for Emacstool bindings.")


134 135
;; Since .emacs gets loaded before this file, a hook is supplied
;; for you to put your own bindings in.
Jim Blandy's avatar
Jim Blandy committed
136 137 138 139

(defvar suntool-map-hooks nil
  "List of forms to evaluate after setting suntool-map.")

140 141 142 143 144 145 146
;;
;; If running under emacstool, arrange to call suspend-emacstool
;; instead of suspend-emacs.
;;
;; First mouse blip is a clue that we are in emacstool.
;;
;; C-x C-@ is the mouse command prefix.
Jim Blandy's avatar
Jim Blandy committed
147

148
(autoload 'sun-mouse-handler "sun-mouse"
Jim Blandy's avatar
Jim Blandy committed
149 150
	  "Sun Emacstool handler for mouse blips (not loaded)." t)

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
(defun terminal-init-sun ()
  "Terminal initialization function for sun."
  (define-key function-key-map "\e[" sun-raw-prefix)

  (define-key sun-raw-prefix "210z" [r3])
  (define-key sun-raw-prefix "213z" [r6])
  (define-key sun-raw-prefix "214z" [r7])
  (define-key sun-raw-prefix "216z" [r9])
  (define-key sun-raw-prefix "218z" [r11])
  (define-key sun-raw-prefix "220z" [r13])
  (define-key sun-raw-prefix "222z" [r15])
  (define-key sun-raw-prefix "193z" [redo])
  (define-key sun-raw-prefix "194z" [props])
  (define-key sun-raw-prefix "195z" [undo])
  ;; (define-key sun-raw-prefix "196z" 'ignore)		; Expose-down
  ;; (define-key sun-raw-prefix "197z" [put])
  ;; (define-key sun-raw-prefix "198z" 'ignore)		; Open-down
  ;; (define-key sun-raw-prefix "199z" [get])
  (define-key sun-raw-prefix "200z" [find])
  ;; (define-key sun-raw-prefix "201z" 'kill-region-and-unmark)	; Delete
  (define-key sun-raw-prefix "224z" [f1])
  (define-key sun-raw-prefix "225z" [f2])
  (define-key sun-raw-prefix "226z" [f3])
  (define-key sun-raw-prefix "227z" [f4])
  (define-key sun-raw-prefix "228z" [f5])
  (define-key sun-raw-prefix "229z" [f6])
  (define-key sun-raw-prefix "230z" [f7])
  (define-key sun-raw-prefix "231z" [f8])
  (define-key sun-raw-prefix "232z" [f9])
  (define-key sun-raw-prefix "233z" [f10])
  (define-key sun-raw-prefix "234z" [f11])
  (define-key sun-raw-prefix "235z" [f12])
  (define-key sun-raw-prefix "A" [up])			; R8
  (define-key sun-raw-prefix "B" [down])		; R14
  (define-key sun-raw-prefix "C" [right])		; R12
  (define-key sun-raw-prefix "D" [left])		; R10

  (global-set-key [r3]	'backward-page)
  (global-set-key [r6]	'forward-page)
  (global-set-key [r7]	'beginning-of-buffer)
  (global-set-key [r9]	'scroll-down)
  (global-set-key [r11]	'recenter)
  (global-set-key [r13]	'end-of-buffer)
  (global-set-key [r15]	'scroll-up)
  (global-set-key [redo]	'redraw-display) ;FIXME: collides with default.
  (global-set-key [props]	'list-buffers)
  (global-set-key [put]	'sun-select-region)
  (global-set-key [get]	'sun-yank-selection)
  (global-set-key [find]	'exchange-point-and-mark)
  (global-set-key [f3]	'scroll-down-in-place)
  (global-set-key [f4]	'scroll-up-in-place)
  (global-set-key [f6]	'shrink-window)
  (global-set-key [f7]	'enlarge-window)

  (when sun-raw-prefix-hooks
    (message "sun-raw-prefix-hooks is obsolete!  Use term-setup-hook instead!")
    (let ((hooks sun-raw-prefix-hooks))
      (while hooks
	(eval (car hooks))
	(setq hooks (cdr hooks)))))

  (define-key suntool-map "gr" 'beginning-of-buffer)	; r7
  (define-key suntool-map "iR" 'backward-page)		; R9
  (define-key suntool-map "ir" 'scroll-down)		; r9
  (define-key suntool-map "kr" 'recenter)		; r11
  (define-key suntool-map "mr" 'end-of-buffer)		; r13
  (define-key suntool-map "oR" 'forward-page)		; R15
  (define-key suntool-map "or" 'scroll-up)		; r15
  (define-key suntool-map "b\M-L" 'rerun-prev-command)	; M-AGAIN
  (define-key suntool-map "b\M-l" 'prev-complex-command) ; M-Again
  (define-key suntool-map "bl" 'redraw-display)		 ; Again
  (define-key suntool-map "cl" 'list-buffers)		 ; Props
  (define-key suntool-map "dl" 'undo)			 ; Undo
  (define-key suntool-map "el" 'ignore)			 ; Expose-Open
  (define-key suntool-map "fl" 'sun-select-region)	 ; Put
  (define-key suntool-map "f," 'copy-region-as-kill)	 ; C-Put
  (define-key suntool-map "gl" 'ignore)			 ; Open-Open
  (define-key suntool-map "hl" 'sun-yank-selection)	 ; Get
  (define-key suntool-map "h," 'yank)			 ; C-Get
  (define-key suntool-map "il" 'research-forward)	 ; Find
  (define-key suntool-map "i," 're-search-forward)	 ; C-Find
  (define-key suntool-map "i\M-l" 'research-backward)	 ; M-Find
  (define-key suntool-map "i\M-," 're-search-backward)	 ; C-M-Find

  (define-key suntool-map "jL" 'yank)			; DELETE
  (define-key suntool-map "jl" 'kill-region-and-unmark)	; Delete
  (define-key suntool-map "j\M-l" 'exchange-point-and-mark) ; M-Delete
  (define-key suntool-map "j,"
    (lambda () (interactive) (pop-mark))) ; C-Delete

  (define-key suntool-map "fT" 'shrink-window-horizontally)	; T6
  (define-key suntool-map "gT" 'enlarge-window-horizontally)	; T7
  (define-key suntool-map "ft" 'shrink-window)			; t6
  (define-key suntool-map "gt" 'enlarge-window)			; t7
  (define-key suntool-map "cT" (lambda (n) (interactive "p") (scroll-down n)))
  (define-key suntool-map "dT" (lambda (n) (interactive "p") (scroll-up n)))
  (define-key suntool-map "ct" 'scroll-down-in-place)		; t3
  (define-key suntool-map "dt" 'scroll-up-in-place)		; t4
  (define-key ctl-x-map "*" suntool-map)

  (when suntool-map-hooks
    (message "suntool-map-hooks is obsolete!  Use term-setup-hook instead!")
    (let ((hooks suntool-map-hooks))
      (while hooks
	(eval (car hooks))
	(setq hooks (cdr hooks)))))
257

258 259
  (define-key ctl-x-map "\C-@" 'sun-mouse-once))

Jim Blandy's avatar
Jim Blandy committed
260 261 262 263 264 265
(defun emacstool-init ()
  "Set up Emacstool window, if you know you are in an emacstool."
  ;; Make sure sun-mouse and sun-fns are loaded.
  (require 'sun-fns)
  (define-key ctl-x-map "\C-@" 'sun-mouse-handler)

266
  ;; FIXME: this function does not seem to exist either.  -stef'01
Jim Blandy's avatar
Jim Blandy committed
267 268 269 270 271 272 273
  (if (< (sun-window-init) 0)
      (message "Not a Sun Window")
    (progn
      (substitute-key-definition 'suspend-emacs 'suspend-emacstool global-map)
      (substitute-key-definition 'suspend-emacs 'suspend-emacstool esc-map)
      (substitute-key-definition 'suspend-emacs 'suspend-emacstool ctl-x-map))
      (send-string-to-terminal
274
       (concat "\033]lEmacstool - GNU Emacs " emacs-version "\033\\"))))
Jim Blandy's avatar
Jim Blandy committed
275 276 277 278 279

(defun sun-mouse-once ()
  "Converts to emacstool and sun-mouse-handler on first mouse hit."
  (interactive)
  (emacstool-init)
280
  (sun-mouse-handler))			; Now, execute this mouse blip.
281

Miles Bader's avatar
Miles Bader committed
282
;;; arch-tag: db761d47-fd7d-42b4-aae1-04fa116b6ba6
283
;;; sun.el ends here