From: exujsch@exu.ericsson.se (Johnny Schmittou EXU-T-EEG x7887 Dallas Texas USA)
Newsgroups: comp.emacs
Subject: xterm key bindings for jove and GNUEmacs (Part 2)
Keywords: xterm, .Xdefaults, .joverc, .emacs
Date: 27 Aug 92 14:50:32 GMT
Reply-To: exujsch@exu.ericsson.se (Johnny Schmittou EXU-T-EEG x7887 Dallas Texas USA)
Organization: Ericsson Network Systems


This is Part 2 to my previous posting.  Please see Part 1 for the
introductory details.  Note that my jove bindings and GNUEmacs bindings
are almost mirror images of each other.  Thus I can be using either
editor and my key bindings are virtually (95%?) the same...

Following are the GNUemacs key bindings for use in the .emacs file, to be
used in conjunction with the ".Xdefaults" file and the "xterm" shell:

------------- begin cut here for use in .emacs file, GNUEmacs V18.57 --------------------
;; File:  define-sun4-keys-xterm.el
;;
;; Binds Sun xterm keys with emacs commands.  For use on a SUN4 type keyboard.
;;

;  (message "Start of define-sun4-keys-xterm")
;  (sit-for 2)

;; unset key sequence ESC-O, so that cursor keys work
;(global-unset-key "\eO")

;; unset key sequence ESC-[ (normally forward-paragraph)
;; so that Sun xterm keyboard function keys do useful things
;(global-unset-key "\e[")

;-------------------------------------------------------------------------
;  Sun xterm top row righthand keypad keys
;-------------------------------------------------------------------------

;  (message "Before top row keypad keys")
;  (sit-for 2)

  (global-set-key "\C-x3" 'execute-extended-command) ; Pause
;  (global-set-key "\C-w" 'kill-region)               ; PrSc, R2
;  (global-set-key "\e[210z" 'kill-region)            ; Scroll Lock Break, R3

;-------------------------------------------------------------------------
;  Sun xterm top row shifted righthand keypad keys
;-------------------------------------------------------------------------

;  (message "Before shifted top row keypad keys")
;  (sit-for 2)

  (global-set-key "\C-x4" 'shell-command)            ; Pause
  (global-set-key "\C-x9" 'keyboard-quit)            ; PrSc, R2
  (global-set-key "\C-x8" 'keyboard-quit)            ; Scroll Lock Break, R3

;-------------------------------------------------------------------------
; Numeric righthand keypad
;-------------------------------------------------------------------------

;  (message "Before righthand keypad keys")
;  (sit-for 2)

;  (global-set-key "\e[211z"  'ESC-prefix)         ;Define meta key
  (global-set-key "\eh"     'describe-bindings)   ;NP =
  (global-set-key "\C-r" 'find-prev-occur)        ;NP /
  (global-set-key "\C-s" 'find-next-occur)        ;NP *
  (global-set-key "\C-x-"   'delete-entire-line)  ;NP -
  (global-set-key "\C-xE" 'backward-word)         ;NP1
  (global-set-key "\e[218z" 'other-window)        ;NP5
;  (global-set-key "\e[E" 'other-window)           ;NP5
  (global-set-key "\C-x\C-w" 'copy-above-word)    ;NP7
  (global-set-key "\C-x\C-l" 'copy-above-line)    ;NP9
  (global-set-key "\C-a" 'overwrite-mode)         ;NP0
  (global-set-key "\C-x+" 'kill-word)             ;NP+
  (global-set-key "\C-f" 'forward-to-word)        ;NP3
  (global-set-key "\e." 'set-mark-command)        ;NP.
  (global-set-key "\C-x6" 'enlarge-window)        ;NP Enter

;-------------------------------------------------------------------------
; Shifted numeric righthand keypad
;-------------------------------------------------------------------------

;  (message "Before shifted righthand keypad keys")
;  (sit-for 2)

  (global-set-key "\C-\\" 'find-first-occur-backward) ;NP /
  (global-set-key "\es"  'find-first-occur-forward)   ;NP *
  (global-set-key "\C-y" 'yank)                       ;NP -
  (global-set-key "\eL" 'downcase-word)               ;NP1
;  (global-set-key "\e[218z" 'other-window)            ;NP5
  (global-set-key "\C-xW" 'copy-below-word)           ;NP7
  (global-set-key "\C-xL" 'copy-below-line)           ;NP9
  (global-set-key "\C-o" 'open-line)                  ;NP0
;  (global-set-key "\C-y" 'yank)                       ;NP+
  (global-set-key "\eU" 'upcase-word)                 ;NP3
  (global-set-key "\C-x." 'delete-to-eol)             ;NP.
  (global-set-key "\C-x7" 'shrink-window)             ;NP Enter

;-------------------------------------------------------------------------
; Lefthand keypad
;-------------------------------------------------------------------------
;  (message "Before lefthand keypad")
;  (sit-for 2)

(global-set-key "\ez" 'save-buffers-kill-emacs)     ;; L1 "STOP"
(global-set-key "\e[193z" 'rerun-prev-command)      ;; L2 "AGAIN"
(global-set-key "\C-xa" 'apropos)                   ;; L3 "PROPS"
; (global-set-key "\e[195z" 'advertised-undo)         ;; L4 "UNDO" (as C-x u)
; (global-set-key "\e[196z" 'describe-mode)           ;; L5 "FRONT" (C-h m) 
; (global-set-key "\e[197z" 'copy-region-as-kill)     ;; L6 "COPY" (as M-w)
; (global-set-key "\e[198z" 'find-file)               ;; L7 "OPEN" (file dus)
; (global-set-key "\e[199z" 'yank)                    ;; L8 "PASTE" (as C-y)
(global-set-key "\ea" 'auto-get-file)               ;; L9 "FIND" (as M-s)
; (global-set-key "\e[201z" 'kill-region-safe)        ;; L10 "CUT" (as C-w)
; (global-set-key "\e[202z" 'info)                    ;; "HELP" (as C-h i)

;-------------------------------------------------------------------------
; GOLD (ESC) key definitions
;-------------------------------------------------------------------------

;  (message "Before gold keys")
;  (sit-for 2)

  (global-set-key "\e!" 'insert-comment-date)
  (global-set-key "\e/" 'call-last-kbd-macro)
;  (global-set-key "\e." 'set-mark-command)
;  (global-set-key "\ea" 'apropos)
  (global-set-key "\eA" 'apropos)
  (global-set-key "\eb"  'beginning-of-buffer)
  (global-set-key "\eB"  'beginning-of-buffer)
  (global-set-key "\ec"  'capitalize-word)
  (global-set-key "\eC"  'center-line)
;  (global-set-key "\ed"  'my-insert-date)
;  (global-set-key "\eD"  'my-insert-date)
  (global-set-key "\ed"  'kill-word)
  (global-set-key "\eD"  'kill-word)
  (global-set-key "\ee"  'end-of-buffer)
  (global-set-key "\eE"  'end-of-buffer)
  (global-set-key "\ef"  'do-nothing)
  (global-set-key "\eF"  'do-nothing)
  (global-set-key "\eg"  'auto-get-file)
  (global-set-key "\eG"  'auto-get-file)
;  (global-set-key "\eh"  'describe-function)
  (global-set-key "\eH"  'describe-function)
  (global-set-key "\ei"  'find-file)
  (global-set-key "\eI"  'find-file)
  (global-set-key "\ek"  'call-last-kbd-macro)
  (global-set-key "\eK"  'call-last-kbd-macro)
  (global-set-key "\el"  'start-kbd-macro)
; (global-set-key "\eL"  'start-kbd-macro)
  (global-set-key "\em"  'toggle-read-only)
  (global-set-key "\eM"  'toggle-read-only)
  (global-set-key "\en"  'next-window)
  (global-set-key "\eN"  'next-window)
  (global-set-key "\eo"  'write-file)
  (global-set-key "\eO"  'write-file)
  (global-set-key "\ep"  'previous-window)
  (global-set-key "\eP"  'previous-window)
  (global-set-key "\eq"  'kill-emacs)
  (global-set-key "\eQ"  'kill-emacs)
  (global-set-key "\er"  'end-kbd-macro)
  (global-set-key "\eR"  'end-kbd-macro)
;;;  (global-set-key "\es"  'list-directory)
;;;  (global-set-key "\eS"  'list-directory)
;  (global-set-key "\es"  'cd)
;  (global-set-key "\eS"  'cd)
;;;  (global-set-key "\et"  'do-nothing)
;;;  (global-set-key "\eT"  'do-nothing)
  (global-set-key "\eu"  'upcase-region)
;  (global-set-key "\eU"  'upcase-region)
  (global-set-key "\ev"  'do-nothing)
  (global-set-key "\eV"  'do-nothing)
  (global-set-key "\ew"  'copy-region)
  (global-set-key "\eW"  'copy-region)
;;; \ex is bound to execute-extended-command
;;; and should not be changed.
;;;  (global-set-key "\ex"  'insert-file)
;;;  (global-set-key "\eX"  'insert-file)
;;;  (global-set-key "\ey"  'do-nothing)
;;;  (global-set-key "\eY"  'do-nothing)
;;;  (global-set-key "\ez"  'save-buffers-kill-emacs)
;;;  (global-set-key "\eZ"  'save-buffers-kill-emacs)

;-------------------------------------------------------------------------
; Control-key definitions
;-------------------------------------------------------------------------

;  (message "Before control keys")
;  (sit-for 2)

  (global-set-key "\C-^" 'cursor-to-top)
  (global-set-key "\C-'" 'quoted-insert)
;  (global-set-key "\C-a" 'overwrite-mode)
;  (global-set-key "\C-b" 'beginning-of-line) ;standard, left arrow
  (global-set-key "\C-b" 'backward-char) ;standard, left arrow
  (global-set-key "\C-d" 'delete-char)
  (global-set-key "\C-e" 'end-of-line)
;  (global-set-key "\C-f" 'forward-word)  ;standard, right arrow
;  (global-set-key "\C-f" 'forward-char)  ;standard, right arrow
;;; "\C-g" is bound to the "keyboard-quit" function and should not be changed
;;; (global-set-key "\C-g" 'do-nothing)
;;; "\C-h" is bound to GNU Emacs help menu and should not be changed
;;; (global-set-key "\C-h" 'describe-bindings)
;  (global-set-key "\C-i" 'indent-for-tab-command)
  (global-set-key "\C-j" 'insert-initials-date)
  (global-set-key "\C-k" 'global-set-key)
  (global-set-key "\C-l" 'recenter)
;;; "\C-m" is RETURN key and should not be changed
;  (global-set-key "\C-n" 'scroll-up)   ;standard, down arrow
  (global-set-key "\C-n" 'next-line)   ;standard, down arrow
;  (global-set-key "\C-o" 'open-line)
;  (global-set-key "\C-p" 'scroll-down) ;standard, up arrow
  (global-set-key "\C-p" 'previous-line) ;standard, up arrow
; (global-set-key "\C-q" 'keyboard-quit)
;  (global-set-key "\C-r" 'find-prev-occur)
;;; "\C-s" is global-setd to be incremental-search-forward;  it also
;;;    does successive forward searches.
  (global-set-key "\C-s" 'find-next-occur)
  (global-set-key "\C-t" 'display-the-time)
  (global-set-key "\C-u" 'upcase-word)
  (global-set-key "\C-v" 'cursor-to-bottom)
  (global-set-key "\C-w" 'kill-region)

;;; "\C-x" is a prefix character and should not be changed
  (global-set-key "\C-xw" 'copy-above-space)
  (global-set-key "\C-xl" 'copy-below-space)

;  (global-set-key "\C-y" 'yank)
  (global-set-key "\C-z" 'save-buffers-kill-emacs)
  (global-set-key "\C-_" 'find-first-occur-forward)
;  (global-set-key "\C-\\" 'find-first-occur-backward)

;-------------------------------------------------------------------------
; Function key definitions
;-------------------------------------------------------------------------
 
;  (message "Before function keys")
;  (sit-for 2)

  (global-set-key "\e1" 'delete-other-windows)   ; F1
  (global-set-key "\e2" 'split-window)           ; F2
  (global-set-key "\e3" 'write-file)             ; F3
  (global-set-key "\e4" 'find-file)              ; F4
  (global-set-key "\e5" 'query-replace)          ; F5
  (global-set-key "\e6" 'buffer-menu)            ; F6
;  (global-set-key "\e6" 'list-buffers)           ; F6
  (global-set-key "\e7" 'scroll-down)            ; F7
  (global-set-key "\e8" 'scroll-up)              ; F8
  (global-set-key "\e9" 'kill-buffer)            ; F9
  (global-set-key "\e0" 'describe-key-briefly)   ; F10
  (global-set-key "\C-x1" 'describe-function)    ; F11
  (global-set-key "\C-x2" 'switch-to-buffer)     ; F12

;-------------------------------------------------------------------------
; Arrow key definitions
;-------------------------------------------------------------------------

;  (message "Before arrow keys")
;  (sit-for 2)

; (global-set-key "\e*\e\C-h" 'previous-line)      ; Up arrow
; (global-set-key "\e*\e\C-n" 'next-line)      ; down arrow
; (global-set-key "\e*\e\C-l" 'forward-char)      ; right arrow
; (global-set-key "\e*\e\C-j" 'backward-char)      ; left arrow

;  (global-set-key  "\e[215z" 'previous-line)		; R8  (up-arrow)
;  (global-set-key  "\e[217z" 'backward-char)		; R10 (lf-arrow)
;  (global-set-key  "\e[219z" 'forward-char)		; R12 (rt-arrow)
;  (global-set-key  "\e[221z" 'next-line)		; R14 (dn-arrow)

; (global-set-key "\C-h" 'previous-line) ;up-arrow
; (global-set-key "\C-n" 'next-line)       ;down-arrow
; (global-set-key "\C-j" 'backward-char)   ;left-arrow
; (global-set-key "\C-l" 'forward-char)         ;right-arrow

  (global-set-key  "\e[A" 'previous-line)	; R8  (up-arrow)
  (global-set-key  "\e[D" 'backward-char)	; R10 (lf-arrow)
  (global-set-key  "\e[C" 'forward-char)	; R12 (rt-arrow)
  (global-set-key  "\e[B" 'next-line)		; R14 (dn-arrow)

;-------------------------------------------------------------------------
; Shifted arrow key definitions
;-------------------------------------------------------------------------

;  (message "Before shifted arrow keys")
;  (sit-for 2)

 (global-set-key "\C-xA" 'beginning-of-buffer) ;up-arrow
 (global-set-key "\C-xB" 'end-of-buffer)       ;down-arrow
 (global-set-key "\C-xD" 'beginning-of-line)   ;left-arrow
 (global-set-key "\C-xC" 'end-of-line)         ;right-arrow

; (global-set-key "\M-\C-h" 'beginning-of-buffer) ;up-arrow
; (global-set-key "\M-\C-n" 'end-of-buffer)       ;down-arrow
; (global-set-key "\M-\C-j" 'beginning-of-line)   ;left-arrow
; (global-set-key "\M-\C-l" 'end-of-line)         ;right-arrow

; (global-set-key "\M-\C-p" 'beginning-of-buffer) ;up-arrow
; (global-set-key "\M-\C-n" 'end-of-buffer)       ;down-arrow
; (global-set-key "\M-\C-b" 'beginning-of-line)   ;left-arrow
; (global-set-key "\M-\C-f" 'end-of-line)         ;right-arrow

; (global-set-key "\M-\C-213z" 'find-first-occur-forward) ;gold-* (keypad)

;  (message "All of my keys are now defined")
;  (sit-for 2)

;*************************************************************************
; Define various lisp functions
;*************************************************************************

;;;
;;; misc stuff
;;;                                

;  (message "Before misc stuff")
;  (sit-for 2)

;-------------------------------------------------------------------------
; Define some keyboard (kbd) macros as Lisp code.

(fset 'auto-get-file
   ".C4D.

(fset 'copy-above-space
   "[A.[B")

(fset 'copy-below-space
   "[B.[A")

;-------------------------------------------------------------------------
; Define some honest to goodness Lisp functions.

(defun copy-above-word ()
  "Copies the word above the cursor."
  (interactive)
  (previous-line 1)
  (delete-current-word 1)
  (undelete-words)
  (next-line 1)
  (undelete-words)
  (end-of-line)
)

(defun copy-above-line ()
  "Copies the line above the cursor."
  (interactive)
  (previous-line 1)
  (delete-to-eol 1)
  (my-undelete-lines)
  (next-line 1)
  (my-undelete-lines)
  (end-of-line)
)

(defun copy-below-word ()
  "Copies the word below the cursor."
  (interactive)
  (next-line 1)
  (delete-current-word 1)
  (undelete-words)
  (previous-line 1)
  (undelete-words)
  (end-of-line)
)

(defun copy-below-line ()
  "Copies the line below the cursor."
  (interactive)
  (next-line 1)
  (delete-to-eol 1)
  (my-undelete-lines)
  (previous-line 1)
  (my-undelete-lines)
  (end-of-line)
)

;(defun insert-date()
;  (interactive)
;  (let ((date (current-time-string)))
;  (insert (substring date 4 7) "." (substring date 7 10) "," (substring date -5)
;		  )))

(defun my-insert-date()
  "Inserts the current date into the text."
  (interactive)
  (let ((mydate (current-time-string)))
    (if (string-equal (substring mydate 8 9) " ")
      (insert "0" (substring mydate 9 10) "-" (substring mydate 4 7) "-" 
              (substring mydate 22 24)
      )
    (progn
      (insert (substring mydate 8 10) "-" (substring mydate 4 7) "-" 
              (substring mydate 22 24)
      )
    )
    )
  )
)

(defun insert-initials-date()
  "Inserts my initials and the date into the text."
  (interactive)
  (insert "--jbs ")
  (my-insert-date)
)

(defun insert-comment-date()
  "Inserts comment character, my username and the current date into the text."
  (interactive)
  (insert "!*  EXUJSCH  ")
  (my-insert-date)
)

(defun skip-to-column ()
  "Moves the cursor to a given column."
  (interactive)
  (setq new-cursor-position nil)
  (setq new-cursor-position (read-string "Skip to which column: "))
  (if (eq new-cursor-position nil)
    (message "No column was entered.")
  (progn
    (setq int-cursor-position (string-to-int new-cursor-position))
    (if (or 
          (< int-cursor-position 1) 
          (> int-cursor-position 80)
        )
      (message "Invalid column - must be between 1 and 80.")
    (progn
      (move-to-column int-cursor-position)
    )
    )
  )
  )
)
------------- end cut here for use in .emacs file, GNUEmacs V18.57 --------------------
--
___________________________________________________________________________
Internet....: exujsch@exu.ericsson.se | "Everything I say is the absolute
Real life...: Johnny Schmittou        |  Gospel...  Nah, just kidding."
Virtual life: Q-man   ---<<<I'd rather be drumming.>>>--- Dallas, Texas USA