[comp.emacs] terminal sends 3 chars for meta key

mdb@silvlis.COM (Mark D. Baushke) (10/16/88)

>  Date: 15 Oct 88 15:17:55 GMT
>  From: sun!rutgers.edu!mailrus!b-tech!zeeff  (Jon Zeeff)
>  
>  I just started using emacs and I'd like to use the meta key on this
>  terminal.  Unfortunately, this key send ESC N key (ie. pressing M-A sends
>  <esc>NA).  Is there a way to get emacs to ignore that extra N sent between
>  the esc and the A?

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

;---------- 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)))



Enjoy!
------------------------------------------------------------------------------
Mark D. Baushke                 Internet:    mdb%silvlis.com@sun.com
Silvar-Lisco, Inc.              Nameservers: mdb@silvlis.com
1080 Marsh Road                 Usenet:      {pyramid,sun}!silvlis!mdb
Menlo Park, CA 94025-1053       Telephone:   +1 415 853-6411 / +1 415 969-8328

matt@oddjob.uchicago.edu (Matt Crawford) (10/17/88)

Ugh.  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.

________________________________________________________
Matt Crawford	     		matt@oddjob.uchicago.edu