Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
meta key switch
;; Keybonds
(global-set-key [(hyper a)] 'mark-whole-buffer)
(global-set-key [(hyper v)] 'yank)
(global-set-key [(hyper c)] 'kill-ring-save)
(global-set-key [(hyper s)] 'save-buffer)
(global-set-key [(hyper l)] 'goto-line)
(global-set-key [(hyper w)]
(lambda () (interactive) (delete-window)))
(global-set-key [(hyper z)] 'undo)
;; mac switch meta key
(defun mac-switch-meta nil
"switch meta between Option and Command"
(interactive)
(if (eq mac-option-modifier nil)
(progn
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'hyper)
)
(progn
(setq mac-option-modifier nil)
(setq mac-command-modifier 'meta)
)
)
)
@samspo

This comment has been minimized.

Copy link

@samspo samspo commented Jan 16, 2013

Thanks. Very useful.

Is there any possibility to avoid modifying the behavior of the right option key so that I can enter "[]{}" when writing in emacs ?
I tried (setq ns-right-alternate-modifier nil), but it doesn't function

@bartlebee

This comment has been minimized.

Copy link

@bartlebee bartlebee commented Jan 28, 2013

@samspo this mac port doesn't use the ns-* variables and the mac-* variables don't include a right option at the moment. I'm working on a patch for that.

@samspo

This comment has been minimized.

Copy link

@samspo samspo commented Feb 6, 2013

@bartebee Thank you for your answer.

@pitkali

This comment has been minimized.

Copy link

@pitkali pitkali commented Feb 7, 2013

@bartlebee I'd also love to see the ability to have left option work as meta, while right being good old option. I have so many keybindings using super...

@kristianhellquist

This comment has been minimized.

Copy link

@kristianhellquist kristianhellquist commented Feb 26, 2013

+1 for (setq ns-right-alternate-modifier nil)

@kristianhellquist

This comment has been minimized.

Copy link

@kristianhellquist kristianhellquist commented Feb 26, 2013

@samspo In the meantime I hard-wire those keys see https://gist.github.com/meeiw/1772649

@FeiSun

This comment has been minimized.

Copy link

@FeiSun FeiSun commented Mar 4, 2013

I wanna use command+s to save file or command+q to quit emacs
Then how can I set the command key to its default role?
I set (setq mac-command-modifier nil)
It has no effect

@kyleduck

This comment has been minimized.

Copy link

@kyleduck kyleduck commented Nov 4, 2013

@bartlebee tried this out and found it to be snappy. also like how text is rendered. only thing keeping me from switching full-time is the lack of right-left modifier keys... too many hypers and super keybindings with stubborn muscle memory.

nice work though a+

@alls0rts

This comment has been minimized.

Copy link

@alls0rts alls0rts commented Jan 31, 2015

I've been using this for a while, so much that I forgot about the setting of mac-option-modifier and was wondering why a Service that I have enabled would not work. Would it be possible that when a Hyper key combination is not matched by emacs that it could be passed up?

@yyz1989

This comment has been minimized.

Copy link

@yyz1989 yyz1989 commented Jul 12, 2016

@FeiSun have you found a solution? I am looking for something similar...

@maxfurman

This comment has been minimized.

Copy link

@maxfurman maxfurman commented Oct 31, 2016

@FeiSun @yyz1989 AFAICT there's no way to fully enable the default command-key behaviors, but you can add the ones you need to the snippet above. For example, (global-set-key [(hyper q)] 'save-buffers-kill-emacs) will make cmd-q quit emacs

@idcrook

This comment has been minimized.

Copy link

@idcrook idcrook commented Jun 9, 2018

Not sure when/what emacs version this was added, but something like this now works:

       ;; Do not have emacs capture right alt/option key and command keys
       (setq ns-right-command-modifier 'none)   ;; original value is 'left'
       (setq ns-right-alternate-modifier 'none) ;; original value is 'left'
       ;;(setq ns-right-option-modifier nil)      ;; alias for ns-right-alternate-modifier
@brgr

This comment has been minimized.

Copy link

@brgr brgr commented Mar 29, 2019

@idcrook I don't know about you, but for my Emacs Mac Port these ns-* commands are still not available. However, for everyone searching to get something like that to work, there exists now a mac-right-{alternate|command}-modifier command!

@hisnawi

This comment has been minimized.

Copy link

@hisnawi hisnawi commented Mar 1, 2020

I am sorry, but how do you use this?
I included the contents of the file in the beginning of this thread in my setup but I still can't have them swapped.
I am on Catalina by the way. I am also using terminal mode (emacs -nw)

@railwaycat

This comment has been minimized.

Copy link
Owner Author

@railwaycat railwaycat commented Mar 23, 2020

@hisnawi This setup does not work for emacs -nw, since it is your terminal emulator(iTerm2, Terminal.app etc) who controls the cmd and option key behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.