Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Meta to option key when using XQuartz on mac to open emacs installed on remote server

My problem is like this: Firstly, I login into a remote server through ssh -Y using the Terminal.app on Mac. Then open the emacs installed on that remote server by typing

emacs

Because of I add the option -Y when using ssh, the emacs is opened in the XQuartz installed on Mac.

At this time, the problem comes: the option key is not treated as Meta and only the ESC key is treated as Meta. But I want to use the option key as Meta.

How can I solve it?

like image 590
Negelis Avatar asked Jan 17 '13 12:01

Negelis


People also ask

How do you change the Meta key on a Mac?

Alternatively, instead of using defaults in the command line, you can simply go to the Terminal > Preferences... (or type ⌘ + , ). Then, Profiles > Keyboard and check the box Use Option as Meta key .

What is Emacs Meta key on Mac?

If your Emacs does not recognize your Alt key as the Meta key anymore, then you probably have some other key bound to Meta. In some distributions, this is the Windows key, or a Penguin key on some keyboards. On Macintoshes meta is often the Option key, which often is caught for other purposes.

What is Alt key in Emacs?

Meta is Alt in Practice By default on all major operating systems in use (Windows, Linux, OS X), emacs maps its Meta to Alt key. So, practically speaking, the Meta key is the Alt key.


1 Answers

Take a look at http://www.emacswiki.org/emacs/MetaKeyProblems

specifically this part.

You can then run emacs from X11 windows (Applications/Utilities/X11.app) with the option/alt key as the meta key. Furthermore, you may use the xmodmap command to remap the command key to Control only under X11. This has the advantage of allowing the command key to behave expectedly with other Mac applications. xmodmap can also ensure that the Alt/Option key is set to be the Meta key in emacs. You can do this with the following ~/.xmodmap file (the lines starting with exclamation points are comments and can be omitted):

! undo any meta keys already set
 clear Mod1
 ! keycodes 63 and 71 are the left and right COMMAND buttons adjacent to the spacebar; set them to be control keys
 keycode 63=Control_L
 keycode 71=Control_R
 ! keycodes 66 and 69 are the option/alt keys; assign them as Meta keys
 keycode 66=Meta_L
 keycode 69=Meta_R
 ! now tell X11 that the Meta keys act as the Mod1 (meta) modier key; that is, when they are pressed with KEY, it is the same as hitting M-KEY
 add Mod1 = Meta_L Meta_R
 ! tell X11 that the Control keys are Control modifiers, so when pressed with u (for example) it is the same as hitting C-u
 add Control = Control_L Control_R

Use the above file with the command

xmodmap ~/.xmodmap

before starting emacs (for instance, from /etc/bashrc if you use the login shell option to xterm, i.e. xterm -ls in X11/Application/Customize for terminal).

like image 192
Doon Avatar answered Sep 18 '22 02:09

Doon