Binding M- / M- in Emacs 23.1.1

后端 未结 7 549
南笙
南笙 2020-11-27 18:36

I\'m trying to put in a feature that I miss from Eclipse, where Alt+[Up/Down] transposes the lines up or down, but can not for the life of m

相关标签:
7条回答
  • 2020-11-27 18:55

    ugly workaround:

    I've typed C-q <M-up> it produced ^[[1;3A on the terminal inside screen inside emacs.

    (global-set-key (kbd "<M-up>") 'transpose-line-up)
    (global-set-key (kbd "^[[1;3A") 'transpose-line-up)
    

    I've got Lisp error: (void-function transpose-line-up) so the key bindings work.

    Note: C-q runs the command quoted-insert.

    0 讨论(0)
  • 2020-11-27 19:00

    Emacs has a complex mechanism to handle the vicissitudes of function key and modifier encodings on various terminal types. It doesn't work out of the box in all cases. The following settings should work on your terminal:

    (define-key input-decode-map "\e\eOA" [(meta up)])
    (define-key input-decode-map "\e\eOB" [(meta down)])
    (global-set-key [(meta up)] 'transpose-line-up)
    (global-set-key [(meta down)] 'transpose-line-down)
    

    You should be able to use (kbd "<M-up>") and (kbd "<M-down>") in place of [(meta up)] and [(meta down)], as long as you've done the step of telling Emacs (via input-decode-map) about the escape sequences that your terminal uses to encode these key combinations.

    0 讨论(0)
  • 2020-11-27 19:05

    works on OSX Terminal:

    (global-set-key (kbd "ESC <up>") 'transpose-line-up)
    (global-set-key (kbd "ESC <down>") 'transpose-line-down)
    
    0 讨论(0)
  • 2020-11-27 19:12
    (global-set-key [M-up] 'beginning-of-buffer)
    (global-set-key [M-down] 'end-of-buffer)
    

    In my OSX, I have this definition to perform Alt-up/down to jump to top/bottom of buffer.

    0 讨论(0)
  • 2020-11-27 19:13

    The following lines work for me on macOS 10.11.6 and GNU Emacs 25.2.1:

    (global-set-key (kbd "ESC <down>") 'end-of-buffer)
    (global-set-key (kbd "ESC <up>") 'beginning-of-buffer)
    
    0 讨论(0)
  • 2020-11-27 19:15

    I always use C-h k (key) (i.e. describe-key) to find out how Emacs refers to (key), and then use (kbd) with that same string to utilise it.

    In this case, describe-key returns <M-up>, so I would use (global-set-key (kbd "<M-up>") 'transpose-line-up) (exactly as J.F. Sebastian has done).

    Edit:

    Running emacs -nw (but not through screen), describe-key reports ESC <up> (translated from ESC M-[ A), and (kbd "ESC <up>") is successful for binding it.

    Running screen emacs -nw, describe-key reports ESC <up> (translated from ESC M-O A), which seems to match what you see, and the binding for (kbd "ESC <up>") still works for me.

    (n.b. Tested under Cygwin with screen 4.00.03, and Emacs 23.2.1.)

    0 讨论(0)
提交回复
热议问题