simpleclip
simpleclip copied to clipboard
Advice on getting this working with emacs-mac-port
I'm trying to use https://github.com/railwaycat/emacs-mac-port/ on OS X, but for some reason the keybindings don't work. I've filed an issue here https://github.com/railwaycat/emacs-mac-port/issues/57 but maybe you have some insight as to what keybindings may be overriding simpleclip's.
Hi!
Yes, the Mac port has different modifier bindings than Cocoa Emacs.app.
The Mac port has the meta
modifier on ⌘, and reserves the option key for native OS X extended characters. So, by default
- Emacs sees ⌘-v as meta-v, bound to
scroll-down-command
. (The way to see that is to type the sequence C-h k ⌘-v.) - Emacs sees option-v as the square root symbol "√".
By contrast Cocoa Emacs.app maps ⌘ to the super
modifier, and option to the meta
modifier.
So, if you want the modifiers in the Mac port to match Cocoa Emacs.app, you are halfway there: you have meta
on both ⌘ and option. Emacs sees them as the same key. This should do what you want:
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super)
You may also want to set
(setq mac-pass-command-to-system nil)
However, it seems that I should update the docs for this and several other libraries, because the docs just assume that OS X users are running Cocoa Emacs. But ⌘-v is different on the different ports.
Yay, that did it. I was missing the (setq mac-command-modifier 'super)
command.
Thanks!
It turns out that that wasn't my problem. I didn't need to switch the option and command keys.
The problem was that I had lost the use of the "M-x" key, which is the only meta key that I need since I use vimpulse mode.
So to get the M-X key back, I just did:
(global-set-key "≈" 'execute-extended-command)
These are my settings, if this helps someone else:
(global-set-key [(meta s)] 'save-buffer)
(global-set-key [(meta l)] 'goto-line)
(global-set-key [(meta w)]
(lambda () (interactive) (delete-window)))
(global-set-key [(meta z)] 'undo)
(if window-system
(progn
(require 'simpleclip)
(simpleclip-mode 1)
(global-set-key "≈" 'execute-extended-command)))
Note that this doesn't entirely solve the problem of which key is the meta key for Emacs (this only fixes the M-x key).
Ok, now I'm trying to solve a similar problem with regular Emacs 24.3 for Mac OS X . I also lost the use of the M-x key. In fact it looks like the option and cmd keys do the exact thing. I guess they're both mapped to super? so how do i set my option key to be meta?
I tried (setq mac-option-modifier 'meta)
but that didn't work
I tried
(setq mac-option-modifier 'meta)
but that didn't work
Right. The mac-
prefix is specific to the Mac port. Cocoa Emacs uses variables starting with ns-
. To make option map to the meta
modifier:
(setq ns-alternate-modifier 'meta)
Thanks very much for the snippet above regarding vimpulse. I'd like to make simpleclip "just work" under vimpulse/evil/viper, but have not done anything about it since I don't use those modes.
Oh, good to know.
In my attempts to harmonize regular Emacs for Mac OS X and emacs-mac-port (which uses the option key for Mac alternate characters), I ended up reshuffling things. I mapped the option key to Hyper and then got my M-x keybinding back that way:
;; Change function key to hyper so that we can rebind our regular M-x to it
; For regular Emacs for Mac OS X
(setq ns-function-modifier 'hyper)
(setq ns-option-modifier 'super) ; Doesn't seem to have any effect as option and meta do the same thing
(setq ns-command-modifier 'meta)
; For emacs-mac-port
(setq mac-function-modifier 'hyper)
;; Get back our M-x key, which won't interfere with emacs-mac-port use of the Option
;; key for Mac alternate characters
(global-set-key [(hyper x)] 'execute-extended-command)
;; To backward-kill-word, in Mac we usually do Option-Backspace, but since
;; emacs-mac-port takes over the Option key, we have to rely on the default
;; Ctrl-Backspace or map Fn-Backspace.
;; Note that Fn-Backspace only works in emacs-mac-port so best to use Ctrl-Backspace
;; just like on Windows
(global-set-key [(hyper delete)] 'backward-kill-word)
;; Typical Mac bindings
(global-set-key [(meta s)] 'save-buffer)
(global-set-key [(meta w)]
(lambda () (interactive) (kill-buffer)))
; (lambda () (interactive) (delete-window)))
(global-set-key [(meta z)] 'undo)
(global-set-key [(meta backspace)]
(lambda nil (interactive) (kill-line 0)))
;; Emacs bindings
(global-set-key [(meta l)] 'goto-line)
I wish I could make sense of it all :)