From: Howlin' Bob (gt8134b@prism.gatech.EDU)
Date: 05/28/93


From: gt8134b@prism.gatech.EDU (Howlin' Bob)
Subject: Here are my Emacs 19.8 console.el and .emacs
Date: 28 May 1993 05:52:42 GMT

Well, I'm sure all of us have participated in the ftp storm to prep.ai.mit.edu
and it's many mirrors to acquire our very own copies of GNU Emacs 19.{7,8,9}.
I did, and noticed that the standard termcap keybindings don't really do
justice to the Linux keyboard. While some of this could be solved through
the termcap, I decided that route was fairly problematic for wide
distribution and hacked together a sample console.el.

I haven't checked out the precompiled binaries that were uploaded
recently (by Rik Faith or Rick Sladkey, I can't remember which). They
probably come with a console.el that's superior to this one, but since
I didn't feel like downloading XX megabytes of redundant data...

The features of this console.el are:

 * defines F1-F12 as emacs keys f1 - f12, the PrintScreen as print,
   insert, delete, home, end, PageUp as prior, PageDown as next,
   the cursor keys, and a peculiar keypad mode
 * the keypad is put into "application" mode, which means that the
   keys are distinguishable from both standard number keys and
   the gray cursor keys.
 * the keypad keys operate in 2 modes: NumLock on and NumLock off
 * NumLock off, the default mode, defines the keys as kp-0 - kp-9,
   kp-enter, etc. You may bind these however you like. I show
   some examples at the end (in my sample .emacs file)
 * NumLock on defines these keys as normal keys corresponding to the
   letters on the keycaps (i.e. as 0-9, +, -, *, /, linefeed)
 * NumLock mode is toggled by the NumLock key :-)
 * The current NumLock status is displayed in the mode line.
   I made NumLock global (i.e. not buffer-local) because that's how
   a keyboard is supposed to work.

I'll include the files here, as they're small. Feel free to e-mail with
any questions, comments, improvements. There are smarter ways to do this,
I'm sure, but I'm only an amateur elisp programmer.

Put the console.el in $(emacsdir)/lisp/term. Byte-compile it with
M-x byte-compile-file if you wish. Put .emacs in your home directory.

==begin console.el==
;;; console.el --- define key sequences for Linux console
;;; adapted from: vt100.el (included with Emacs 19)

;; Author: Robert Sanders, gt8134b@prism.gatech.edu
;; Keywords: terminals

;;; Commentary:

;; Uses the Emacs 19 terminal initialization features --- won't work with 18.

;; specifically modified for the Linux console as of version 0.99pl9
;; ...overrides the termcap defaults (bad)

;;; Code:

;;; CSI sequences - those that start with "\e[".
;; Termcap or terminfo should set some of these up automatically.
;; however, as no distribution seems to have the termcap set up right,
;; we'll define the keys no matter what...

 (if (not (boundp 'vt100-CSI-prefix))
     (setq vt100-CSI-prefix (lookup-key function-key-map "\e["))

   (if (keymapp vt100-CSI-prefix)
       nil
     (define-prefix-command 'vt100-CSI-prefix)
     (define-key function-key-map "\e[" 'vt100-CSI-prefix)))

;; you can comment out any of these to get the termcap
;; defaults

(define-key vt100-CSI-prefix "A" [up])
(define-key vt100-CSI-prefix "B" [down])
(define-key vt100-CSI-prefix "C" [right])
(define-key vt100-CSI-prefix "D" [left])
(define-key vt100-CSI-prefix "5~" [prior])
(define-key vt100-CSI-prefix "6~" [next])
(define-key vt100-CSI-prefix "2~" [insert])
(define-key vt100-CSI-prefix "1~" [home])
(define-key vt100-CSI-prefix "4~" [end])
(define-key vt100-CSI-prefix "3~" [delete])
(define-key vt100-CSI-prefix "i" [print]) ; PrintScreen key
(define-key vt100-CSI-prefix "[A" [f1])
(define-key vt100-CSI-prefix "[B" [f2])
(define-key vt100-CSI-prefix "[C" [f3])
(define-key vt100-CSI-prefix "[D" [f4])
(define-key vt100-CSI-prefix "[E" [f5])
(define-key vt100-CSI-prefix "17~" [f6])
(define-key vt100-CSI-prefix "18~" [f7])
(define-key vt100-CSI-prefix "19~" [f8])
(define-key vt100-CSI-prefix "20~" [f9])
(define-key vt100-CSI-prefix "21~" [f10])
(define-key vt100-CSI-prefix "28~" [f11])
(define-key vt100-CSI-prefix "29~" [f12])

;;; SS3 sequences - those that start with "\eO".

(if (boundp 'vt100-SS3-prefix)
    nil
  (define-prefix-command 'vt100-SS3-prefix)
  (define-key function-key-map "\eO" 'vt100-SS3-prefix)

  ;; Terminfo might set these
  (defun linux-define-numlock-off ()
    "Set Linux console keypad to simulated NumLock-off mode"
    (interactive)
    (setq linux-numlock-string "")
    (force-mode-line-update)
    (define-key vt100-SS3-prefix "p" [kp-0]) ; 0
    (define-key vt100-SS3-prefix "q" [kp-1]) ; 1
    (define-key vt100-SS3-prefix "r" [kp-2]) ; 2
    (define-key vt100-SS3-prefix "s" [kp-3]) ; 3
    (define-key vt100-SS3-prefix "t" [kp-4]) ; 4
    (define-key vt100-SS3-prefix "u" [kp-5]) ; 5
    (define-key vt100-SS3-prefix "v" [kp-6]) ; 6
    (define-key vt100-SS3-prefix "w" [kp-7]) ; 7
    (define-key vt100-SS3-prefix "x" [kp-8]) ; 8
    (define-key vt100-SS3-prefix "y" [kp-9]) ; 9
    (define-key vt100-SS3-prefix "l" [kp-add])
    (define-key vt100-SS3-prefix "S" [kp-subtract])
    (define-key vt100-SS3-prefix "R" [kp-multiply])
    (define-key vt100-SS3-prefix "Q" [kp-divide])
    (define-key vt100-SS3-prefix "M" [kp-enter])
    (define-key vt100-SS3-prefix "n" [kp-decimal])
    )

  (defun linux-define-numlock-on ()
    "Set Linux console keypad to simulated NumLock-on mode"
    (interactive)
    (setq linux-numlock-string "NumLock")
    (force-mode-line-update)
    (define-key vt100-SS3-prefix "p" [?0]) ; 0
    (define-key vt100-SS3-prefix "q" [?1]) ; 1
    (define-key vt100-SS3-prefix "r" [?2]) ; 2
    (define-key vt100-SS3-prefix "s" [?3]) ; 3
    (define-key vt100-SS3-prefix "t" [?4]) ; 4
    (define-key vt100-SS3-prefix "u" [?5]) ; 5
    (define-key vt100-SS3-prefix "v" [?6]) ; 6
    (define-key vt100-SS3-prefix "w" [?7]) ; 7
    (define-key vt100-SS3-prefix "x" [?8]) ; 8
    (define-key vt100-SS3-prefix "y" [?9]) ; 9
    (define-key vt100-SS3-prefix "l" [?+])
    (define-key vt100-SS3-prefix "S" [?-])
    (define-key vt100-SS3-prefix "R" [?*])
    (define-key vt100-SS3-prefix "Q" [?/])
    (define-key vt100-SS3-prefix "M" [?\C-j])
    (define-key vt100-SS3-prefix "n" [?.])
    )

  ;; these are the strings the Linux console keypad transmits when
  ;; in application mode. Emacs manually turns keypad mode on
  ;; at the bottom of this file.

  (defvar linux-numlock-string ""
    "String which contains ``NumLock'' if the Linux console simulated NumLock
is on, or otherwise nothing.")
  (defvar linux-console-numlock nil "State of simulated keypad NumLock")
  (defun do-linux-console-numlock () "Handle the keypad NumLock key."
    (interactive)
    (if (setq linux-console-numlock (not linux-console-numlock))
        (linux-define-numlock-on)
      (linux-define-numlock-off)))

  ;; I really ought to make this add to the mode-line-format instead of
  ;; setting it...
  (setq-default mode-line-format '("" mode-line-modified mode-line-buffer-identification " " global-mode-string " %[(" mode-name minor-mode-alist "%n" mode-line-process ")%]--" (line-number-mode "L%l--") (-3 . "%p") "------" linux-numlock-string "-%-") )

  (linux-define-numlock-off)
  (define-key vt100-SS3-prefix "P" [kp-numlock])
)

;; put keypad into application mode so we can differentiate between
;; keypad keys and normal keys...we use the functions
;; linux-define-numlock-{on,off} to simulate the keypad functionality.
;; we can fudge the mode-line, but we still can't change the LED :-(

(global-set-key [kp-numlock] 'do-linux-console-numlock)
(send-string-to-terminal "\e=")

;;; console.el ends here

== begin .emacs ==
(setq running-emacs18 nil)
(setq running-emacs19 nil)
(setq running-lucid nil)

;; divine by means of the presence of Lucid- or Emacs19- specific functions
;; which is running. If neither of the version-specific functions is
;; present, we can assume Emacs 18 is running
;;
(if (fboundp 'buffer-dedicated-screen)
    (setq running-lucid t)
  (if (fboundp 'current-frame-configuration)
      (setq running-emacs19 t)
    (setq running-emacs18 t)))

;;; Note: the above test is for the system upon which I had at one time
;;; Emacs 18.59, Lucid 19.6, *and* Emacs 19.8 installed. You don't
;;; really need it for this file...

(setq text-mode-hook 'turn-on-auto-fill)
(setq texinfo-mode-hook 'turn-on-auto-fill)
(setq make-backup-files nil)
(put 'eval-expression 'disabled nil)

;; put point at the beginning of the first line of the
;; window
(defun top-of-window () "Put point at top of window."
  (interactive)
  (goto-char (window-start)))

;; put point at the end of the last line of the window WITHOUT
;; changing the window start end, which (goto-char (window-end))
;; would do.

(defun bottom-of-window () "Put point at bottom of window."
  (interactive)
  (top-of-window)
  (forward-line (- (window-height) 2)) ; compensate for mode-line
  (end-of-line))

(if running-emacs19
    (let ()
      ;; this is for GNU Emacs 19.8
      ;; compiled by Robert Sanders for Linux
      ;; on May 26, 1993

;; (require 'lucid)

      (setq region-face 1)
      (global-set-key [mouse-3] 'mouse-buffer-menu)
      (global-set-key [S-mouse-3] 'mouse-tear-off-window)

      (line-number-mode t)

      (global-set-key [?\C-2] 'set-mark-command)
      (global-set-key [?\C--] 'undo)

      (global-set-key [kp-enter] 'newline-and-indent)
      (global-set-key [f4] 'buffer-menu)
      (global-set-key [f9] 'add-change-log-entry)
      (global-set-key [f11] 'compile)
      (global-set-key [f12] 'what-line)
      (global-set-key [kp-5] 'goto-line)
      (global-set-key [delete] 'delete-char)
      (global-set-key [kp-7] 'beginning-of-line)
      (global-set-key [kp-1] 'end-of-line)
      (global-set-key [kp-4] 'backward-word)
      (global-set-key [kp-6] 'forward-word)
      (global-set-key [kp-8] 'backward-paragraph)
      (global-set-key [kp-2] 'forward-paragraph)
      (global-set-key [kp-9] 'top-of-window)
      (global-set-key [kp-3] 'bottom-of-window)

      (global-set-key "\M-b" 'buffer-menu)
      (define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-1-window)
))
;; end of emacs 19 section

========================================

I hope these help some.

-- 
Robert Sanders
Georgia Institute of Technology, Atlanta Georgia, 30332
uucp:     ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt8134b
Internet: gt8134b@prism.gatech.edu