(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)
(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)))
(search-command
(and command-name (string-match "search" command-name)))
)
(if (and search-command (stringp search-arg)) (setq grep-arg search-arg)
(setq search-command this-command
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)))
(defvar sun-raw-prefix (make-sparse-keymap))
(defvar sun-raw-prefix-hooks nil
"List of forms to evaluate after setting sun-raw-prefix.")
(defvar suntool-map (make-sparse-keymap)
"*Keymap for Emacstool bindings.")
(defvar suntool-map-hooks nil
"List of forms to evaluate after setting suntool-map.")
(autoload 'sun-mouse-handler "sun-mouse"
"Sun Emacstool handler for mouse blips (not loaded)." t)
(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 "200z" [find])
(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]) (define-key sun-raw-prefix "B" [down]) (define-key sun-raw-prefix "C" [right]) (define-key sun-raw-prefix "D" [left])
(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) (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) (define-key suntool-map "iR" 'backward-page) (define-key suntool-map "ir" 'scroll-down) (define-key suntool-map "kr" 'recenter) (define-key suntool-map "mr" 'end-of-buffer) (define-key suntool-map "oR" 'forward-page) (define-key suntool-map "or" 'scroll-up) (define-key suntool-map "b\M-L" 'rerun-prev-command) (define-key suntool-map "b\M-l" 'prev-complex-command) (define-key suntool-map "bl" 'redraw-display) (define-key suntool-map "cl" 'list-buffers) (define-key suntool-map "dl" 'undo) (define-key suntool-map "el" 'ignore) (define-key suntool-map "fl" 'sun-select-region) (define-key suntool-map "f," 'copy-region-as-kill) (define-key suntool-map "gl" 'ignore) (define-key suntool-map "hl" 'sun-yank-selection) (define-key suntool-map "h," 'yank) (define-key suntool-map "il" 'research-forward) (define-key suntool-map "i," 're-search-forward) (define-key suntool-map "i\M-l" 'research-backward) (define-key suntool-map "i\M-," 're-search-backward)
(define-key suntool-map "jL" 'yank) (define-key suntool-map "jl" 'kill-region-and-unmark) (define-key suntool-map "j\M-l" 'exchange-point-and-mark) (define-key suntool-map "j,"
(lambda () (interactive) (pop-mark)))
(define-key suntool-map "fT" 'shrink-window-horizontally) (define-key suntool-map "gT" 'enlarge-window-horizontally) (define-key suntool-map "ft" 'shrink-window) (define-key suntool-map "gt" 'enlarge-window) (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) (define-key suntool-map "dt" 'scroll-up-in-place) (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)))))
(define-key ctl-x-map "\C-@" 'sun-mouse-once))
(defun emacstool-init ()
"Set up Emacstool window, if you know you are in an emacstool."
(require 'sun-fns)
(define-key ctl-x-map "\C-@" 'sun-mouse-handler)
(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
(concat "\033]lEmacstool - GNU Emacs " emacs-version "\033\\"))))
(defun sun-mouse-once ()
"Converts to emacstool and sun-mouse-handler on first mouse hit."
(interactive)
(emacstool-init)
(sun-mouse-handler))