2014-01-25 21 views
1

我正在使用Emacs 23和xterm,並試圖將我的Linux系統從POSIX區域設置切換到en_US.utf8以進入21世紀。問題:當我在此語言環境中使用鍵盤上的Alt鍵時,xterm發送一個雙字符序列。我想修復emacs,以便它將Alt-f視爲meta-f,而不是兩個字符的序列"\303\246"。我認爲這可能是一個輸入編碼的工作,但從emacs文檔中,我還沒有想出如何編寫一個。如何使用UTF-8語言環境使用emacs -nw來使用xterm?

作爲替代方案,我會願意將八進制'\303'添加到鍵盤映射中,以便emacs將它視爲前綴字符以引入元轉義。我寧願這樣做的方式是將'\303'綁定到一個函數,然後將下一個鍵並將其調整爲一個元鍵。但是我也搞不清楚那個。

最糟糕的情況我想我寫了一個循環,通過'z'或其他同樣可怕的東西來綁定'a'的元鍵。

我與set-terminal-coding-system好惹的,但問題的關鍵是,在使用UTF-8,xterm使用Alt鍵發送非ASCII字符— Alt鍵不再表現得像元。因此將終端編碼系統設置爲UTF-8只能讓我輸入帶有變音符號的拉丁字符。不是我所希望的行爲。

我發現了一個非常可怕的答案,它涉及猜測xterm圍繞元密鑰做些什麼。歡迎提出改進意見—我想找到可以乾淨地完成這項工作的代碼。

(而僅供參考,I'm not the only one with this problem

+0

你嘗試過通過'設置終端編碼,system'設置呢?什麼返回'M- :(終端編碼系統)'?如果我理解正確,問題可能是您的Alt未翻譯爲Meta - 請檢查終端設置 –

+0

@AlexOtt既不是'nil'也不是'utf-8'工作。我認爲這個錯誤在'xterm',而不是在'emacs'中。這真是一個解決'xterm'奇怪的問題的方法。例如,使用rxvt,'emacs -nw'「可以用」Alt鍵「工作」。 –

+0

man [xterm](http://invisible-island.net/xterm/manpage/xterm.html),請參見[eightBitInput](http://invisible-island.net/xterm/manpage/xterm.html#VT100-窗口小部件 - 資源:eightBitInput)。 –

回答

1

這裏是一個真正可怕的黑客:

(unless (display-graphic-p) 
    (defun make-meta-key() 
    (interactive) 
    (let ((e (read-event))) 
     (if (numberp e) 
      (let ((keys (vector (event-convert-list (list 'meta 
                 (+ (event-basic-type e) 64)))))) 
      (let ((result (key-binding keys))) 
       (command-execute result))) 
     (error "this can't happen")))) 
    (global-set-key [?\M-C] 'make-meta-key)) 

這似乎解決什麼xterm在做什麼。

ETA:修訂,以處理更多元序列:

(unless (display-graphic-p) ;; deal with the Unicode sequences that xterm sends when Alt (meta) keys ;; are used. N.B. Works with Alt-letter, Alt-\, Alt-space, and Alt-Shift-: (defun make-meta-key() (interactive) (let ((e (read-event))) ;; (message "Got event %s; basic event is %s" e (event-basic-type e)) (if (numberp e) (let* ((basic (event-basic-type e)) (shifted (+ basic 64)) (basecode (if (<= shifted 127) shifted basic)) (keys (vector (event-convert-list (list 'meta basecode)))) (command (key-binding keys))) ;; (message "Result is %s; commandp says %s" command (commandp command)) (command-execute command)) (error "this can't happen")))) (global-set-key [?\M-C] 'make-meta-key) (defun do-nothing() (interactive) nil) (global-set-key [?\M-B] 'do-nothing))

相關問題