[gnu.emacs.help] Using arrow keys on HP terminals

darrylo@HPNMXX.HP.COM (03/22/91)

> I have the arrow keys on our HP terminals set up to move the cursor thusly:
> 
> (global-set-key "\ea" 'previous-line)
> (global-set-key "\eb" 'next-line)
> (global-set-key "\ec" 'forward-char)
> (global-set-key "\ed" 'backward-char)
> 
> The problem is that the "original" functions bound to these sequences
> (M-a, M-b, M-c, M-d) must be remapped or executed explicitly. Is
> there a more elegant way of binding the arrow keys to cursor movement?
> Perhaps some timing device that says, "the 'a' came immediately after
> the ESC so it was probably an arrow key." I will post a summary of any
> helpful replies.

     Here is some code (at the end of this message) that causes the
arrow keys on HP terminals/keyboards to ALWAYS execute whatever is bound
to ^B, ^F, etc.  (it's completely mode independent).  You do, however,
have to supply a function called `is-HP-terminal' that evaluates to
non-nil if an HP terminal/keyboard is being used.

     This code should be easy to understand and modify for use with
other terminals.

     This question brings up another point: in the past few days, I've
seen a few questions about using GNU Emacs with HP workstations.  As the
code contained at the end of this message comes from the version of GNU
Emacs used internally within HP, I'd like to mention that a number of
people within HP has contributed a number of programs (sources) to
Interex (an HP user's group), for distribution via their contrib tapes.
Among the contributions is a version of GNU Emacs used internally within
HP, and it has a number of enhancements:

* HP terminals, keyboards, etc. are now fully recognized (it still works
  with non-HP terminals, though).

* Numerous X-window functions have been added.  You can programmatically
  change the window/icon name, move the window, iconize the window,
  etc., etc..

* It's a complete, "compile-and-go" package for GNU Emacs V18.57.  You
  get easy-to-follow instructions (hopefully ;-) on how to compile and
  install GNU Emacs on HP workstations.  In addition to Emacs, it
  contains copies of ispell (for integrated spell-checking), indent (for
  reformatting C code), mkptypes (for generating ANSI C prototypes), and
  other C programs.  These are included just in case you don't already
  have a copy.  You can think of this package as a "value-added" version
  of GNU Emacs.

* If an error occurs in your .emacs file, you get a much more
  informative error message than "error in init".

* Numerous functions from the public Emacs mailing lists, etc. have been
  merged into this version (so much, in fact, that the size of the "new"
  elisp sources is larger than the size of the "standard" elisp
  sources).  Among these are GNU Emacs Calc (a symbolic RPN calculator),
  LaTexInfo, Forms mode, a couple of C++ modes, some pascal modes,
  ange-ftp, Ed Reingold's calendar and diary functions, CMU process
  modes, modes to edit C comments, edebug (the *old* Emacs-Lisp
  source-level debugger), tetris, gomoku, a Mathematica mode,
  an outline-minor-mode, an (old) perl mode, supercite/superyank, VM
  4.42, and many other goodies.

* The visible size of the minibuffer can shrink and grow, as necessary.

* It comes with PCL versions of all of the major manuals:

	GNU Emacs Manual (the 300-page user's guide)
	GNU Emacs Lisp Reference Manual (a 550-page programmer's manual)
	GNU Emacs Calc (a 300-page guide to the RPN symbolic calculator)

  To print the manuals, you just feed them to an HP laserjet printer;
  you don't need TeX and a DVI converter.

* Best of all, it falls under the GNU Public License (you were wondering
  why I was making this commercial-sounding pitch, didn't you?)

     "Expert" users of GNU Emacs will probably not be interested in
this, although novices will like it (it's a *complete* "compile'n go"
package).

     To distinguish this version from "normal" GNU Emacs, the
documentation refers to this version as the "Unofficial HP GNU Emacs".
Note that this version is not supported by Hewlett-Packard in any way
(the HP people who work on this, do so on their own time).

     Please note that this version is a 15MB compressed tar archive
(yes, that's fifteen megabytes!), and that you need about 30-35MB to
extract and compile it.

     How can you get a copy?  The best way is to order a tape from
Interex (I can't make it available via anonymous ftp, as I don't have
access to a machine connected to an open subnet that allows outside
anonymous ftp access).  However, if there is a *major* site within the
US that already has an unofficial HP archive, I would be willing to ftp
the 15MB compressed tar archive to that site.

     -- Darryl Okahata
	UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
	Internet: darrylo%hpnmd@relay.hp.com

DISCLAIMER: this message is the author's personal opinion and does not
constitute the support, opinion or policy of Hewlett-Packard or of the
little green men that have been following him all day.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; The following is code that optionally makes the arrow keys always do the
;; same thing as the standard Emacs cursor movement keys (^B, ^F, etc., etc.).
;;

(defun execute-key-sequence (key)
  "Execute the key sequence given by KEY.
The key sequence must be complete, and must not contain multiple key
sequences." 
  (let ( (function (key-binding key)) )
    (if function
      (progn
	(call-interactively function)
      )
      (progn
	(ding)
      )
    )
  )
)


(defun key-left ()
  "Execute the function bound to the C-b key."
  (interactive "")
  (execute-key-sequence "\^b")
)

(defun key-right ()
  "Execute the function bound to the C-f key."
  (interactive "")
  (execute-key-sequence "\^f")
)

(defun key-up ()
  "Execute the function bound to the C-p key."
  (interactive "")
  (execute-key-sequence "\^p")
)

(defun key-down ()
  "Execute the function bound to the C-n key."
  (interactive "")
  (execute-key-sequence "\^n")
)

(defun key-next ()
  "Execute the function bound to the C-v key."
  (interactive "")
  (execute-key-sequence "\^v")
)

(if (is-HP-terminal)
  (progn
    ;; Redefine the cursor keys to always do the same thing as the standard
    ;; Emacs cursor keys.
    (global-set-key "\^[D" 'key-left)
    (global-set-key "\^[C" 'key-right)
    (global-set-key "\^[A" 'key-up)
    (global-set-key "\^[B" 'key-down)
    (global-set-key "\^[U" 'key-next)
  )
)