Using a meta key that sends ESC N key

Jon Zeeff zeeff at b-tech.ann-arbor.mi.us
Wed Nov 2 04:13:02 AEST 1988


A while back I asked for a way to get a meta key (alt key) on my 
terminal (the console on a '386 system) to work as a emacs meta key.  
In the hope that others will benefit from the authors time (thanks), 
I'm listing the responses I got.  The suggestion from Anton Rang 
seemed to work fine for me.  

Note that this is particularily relevant to Microport Unix emacs users 
- the alt key causes another key to send ESC N key.  

---------------------------------------------------------------------
From: matt at oddjob.uchicago.edu (Matt Crawford)

Copying the ESC keymap to ESC N is fine only until some key is 
rebound.  

How about instead binding ESC-N to the following function?

(defun sorta-meta ()
  "Act like a META key"
  (interactive)
  (setq prefix-arg current-prefix-arg
	this-command last-command
	unread-command-char ?\e))

Caution: untested.

------------------------------------------------------------------------
From: umix!esl.esl.com!lrs (Lynn Slater)

(defun eat-extra-n ()
  "Replaces the command input with Esc"
  (interactive)
  (setq unread-command-char 27))

(global-set-key "\en" 'eat-extra-n)


----------------------------------------------------------------
From: Paul Dworkin <umix!media-lab.media.mit.edu!paul>

  Try putting the following "magic" into your .emacs file.


The following is a quick hack with similar results:

	(define-key esc-map "n" 'ESC-prefix)

This makes ESC N become ESC.  The only problem with it is that you can't
invoke whatever function was on ESC N.

---------------------------------------------------------------------
From: Anton Rang <umix!cpsin3.cps.msu.edu!rang>

  I suspect you'd be able to do something like:

	(global-set-key "\eN" 'ESC-prefix)

[This worked well for me]

------------------------------------------------------------------
From: Mark D. Baushke <umix!silvlis.com!mdb>


;---------- make ESC N <key-sequence> behave like ESC <key-sequence> ----------
;; Note the following should probably be done inside a
;; lisp/term/<terminal>.el file rather than in your .emacs file.

;; Some versions of copy-keymap don't recurse to all levels.
(defun deep-copy-keymap (keymap)
  "Return a deep copy of KEYMAP.  That is, all levels are copied,
not just the top level."
  (if (not (keymapp keymap))
      keymap
    (cond

     ((listp keymap)
      (let ((new-keymap (copy-alist keymap)))
	(setq keymap (cdr new-keymap))
	(while keymap
	  (let ((binding (car keymap)))
	    (if (keymapp (cdr binding))
		(setcdr binding (deep-copy-keymap (cdr binding))))
	    )
	  (setq keymap (cdr keymap))
	  )
	new-keymap
	))

      ((vectorp keymap)
       (let ((i 0)
	     (n (length keymap))
	     (new-keymap (copy-sequence keymap)))
	 (while (< i n)
	   (if (keymapp (aref keymap i))
	       (aset new-keymap i (deep-copy-keymap (aref keymap i))))
	   (setq i (1+ i)))
	 new-keymap
	 )))))

;; Create a copy of the esc-map which can be bound to the N key.
(setq esc-n-map (deep-copy-keymap esc-map))

;; Install the key map.
(define-key esc-map "N" esc-n-map)

;;!; Alternative to last two lisp statements above would be given the
;;!; name of the terminal type which has the ESC N problem is is
;;!; "footype" then:
;;!;
;;!; (if (string= (getenv "TERM") "footype")
;;!;     (progn
;;!;       ;; Create a copy of the esc-map which can be bound to the N key.
;;!;       (setq esc-n-map (deep-copy-keymap esc-map))
;;!;       
;;!;       ;; Install the key map.
;;!;       (define-key esc-map "N" esc-n-map)))


------------------------------------------------------------------------------
From: umix!bigtex.cactus.org!james (James Van Artsdalen)

You can do certain mappings:

(setq term-file-prefix nil)

;; Map AT386/Microport function key escape sequences
;; into the standard slots in function-keymap.

(require 'keypad)

(defvar SS3-map nil
  "SS3-map maps the keypad on the AT keyboard.")

(if (not SS3-map)
    (progn

     (setq SS3-map (lookup-key global-map "\eO"))
     (if (not (keymapp SS3-map))
	 (setq SS3-map (make-keymap)))  ;; <ESC>O commands
     (setup-terminal-keymap SS3-map
	    '(("K" . ?N)		; page down
	      ("C" . ?P)		; page up
	      ("A" . ?\^a)		; home (beginning of line)
	      ("N" . ?.)        	; delete character
	      ("I" . ?\^b)		; end (end of line)
     	      ("P" . ??)	   	; help - F1
	      ("e" . backward-word)
	      ("o" . forward-word)
	      ("c" . beginning-of-buffer)
	      ("k" . end-of-buffer)
	      ("M" . overwrite-mode)
	      ("T" . ?\^c)))       ; isearch - F5

     (define-key global-map "\eO" SS3-map)))

(define-key SS3-map "\C-K" 'end-of-buffer)
(define-key SS3-map "\C-C" 'beginning-of-buffer)
;; (define-key SS3-map "\C-E" 'backward-word)
;; (define-key SS3-map "\C-O" 'forward-word)

(defvar SS2-map nil
  "SS2-map maps the function keys on the AT keyboard.")

(if (not SS2-map)
    (progn

     (setq SS2-map (lookup-key global-map "\eN"))
     (if (not (keymapp SS2-map))
	 (setq SS2-map (make-keymap)))  ;; <ESC>N commands
     (setup-terminal-keymap SS2-map
	    '(("u" . advertised-undo)	        ; undo
	      ("b" . list-buffers)
	      ("g" . goto-line)
	      ("w" . write-file)
	      ("s" . save-buffer)
	      ("1" . digit-argument)
	      ("2" . digit-argument)
	      ("3" . digit-argument)
	      ("4" . digit-argument)
	      ("5" . digit-argument)
	      ("6" . digit-argument)
	      ("7" . digit-argument)
	      ("8" . digit-argument)
	      ("9" . digit-argument)
	      ("0" . digit-argument)
	      ("i" . overwrite-mode)
              ("x" . save-buffers-kill-emacs)))

     (define-key global-map "\eN" SS2-map)))

;;;
;;;  install ispell
;;;

;;; 
(autoload 'ispell-word "ispell"
	  "Check spelling of word at or before point" t)
(autoload 'ispell-complete-word
	  "ispell" "Complete word at or before point" t)
(autoload 'ispell-region "ispell"
	  "Check spelling of every word in the region" t)
(autoload 'ispell-buffer "ispell"
	  "Check spelling of every word in the buffer" t)

;;; (autoload 'ispell-word "ispell"
;;;   "Check the spelling of word in buffer." t)
;;; (global-set-key "\e$" 'ispell-word)
;;; (autoload 'ispell-region "ispell"
;;;   "Check the spelling of region." t)
;;; (autoload 'ispell-buffer "ispell"
;;;   "Check the spelling of buffer." t)


-- 
Jon Zeeff      			Ann Arbor, MI
umix!b-tech!zeeff  		zeeff at b-tech.ann-arbor.mi.us



More information about the Comp.unix.microport mailing list