Subject: Re: bug#5330: Term mode in Cocoa does not respect NS-ALTERNATE-MODIFIER

From: Scott Bell <[email-masked]>
Date: Mon, 18 Jan 2010 15:00:17 -0700

On 2010-01-18, at 2:17 PM, Ken Hori wrote:

> Please ignore my last post.
> 
> You can instead apply the following patch for a quick fix:
> 
> +++ term.el    2010-01-18 09:27:33.085376730 -0800
> @@ -1208,8 +1208,17 @@
>  
>  (defun term-send-raw-meta ()
>    (interactive)
> -  (let* ((keys (this-command-keys))
> -         (char (aref keys (1- (length keys)))))
> +  (let ((char last-input-event))
> +    (when (symbolp last-input-event)
> +      ;; Convert `return' to C-m, etc.
> +      (let ((tmp (get char 'event-symbol-elements)))
> +    (when tmp
> +      (setq char (car tmp)))
> +    (when (symbolp char)
> +      (setq tmp (get char 'ascii-character))
> +      (when tmp
> +        (setq char tmp)))))
> +    (setq char (event-basic-type char))
>      (term-send-raw-string (if (and (numberp char)
>                     (> char 127)
>                     (< char 256))
> 
> Or, just replace your term-send-raw-meta with:
> 
> (defun term-send-raw-meta ()
>   (interactive)
>   (let ((char last-input-event))
>     (when (symbolp last-input-event)
>       ;; Convert `return' to C-m, etc.
>       (let ((tmp (get char 'event-symbol-elements)))
>     (when tmp
>       (setq char (car tmp)))
>     (when (symbolp char)
>       (setq tmp (get char 'ascii-character))
>       (when tmp
>         (setq char tmp)))))
>     (setq char (event-basic-type char))
>     (term-send-raw-string (if (and (numberp char)
>                    (> char 127)
>                    (< char 256))
>                   (make-string 1 char)
>                 (format "\e%c" char)))))
> 
> Let me know if it succeeds or not.

This works, at least in my common use cases (M-d, M-RET, etc.)

- Scott