Skip to content

Instantly share code, notes, and snippets.

@railwaycat
Created August 28, 2012 13:43
Show Gist options
  • Select an option

  • Save railwaycat/3498096 to your computer and use it in GitHub Desktop.

Select an option

Save railwaycat/3498096 to your computer and use it in GitHub Desktop.
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)
)
)
)
@yyz1989

yyz1989 commented Jul 12, 2016

Copy link
Copy Markdown

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

@maxfurman

Copy link
Copy Markdown

@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

idcrook commented Jun 9, 2018

Copy link
Copy Markdown

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

brgr commented Mar 29, 2019

Copy link
Copy Markdown

@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

hisnawi commented Mar 1, 2020

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

@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