From 2215ffe68d36c5a2f80b0830e2f7f19bb7803ce2 Mon Sep 17 00:00:00 2001 From: Aaron Culich Date: Tue, 11 Apr 2017 13:43:54 -0700 Subject: [PATCH] =?UTF-8?q?change=20osx-command-as=20default=20for=20?= =?UTF-8?q?=E2=8C=98=20to=20hyper=20instead=20of=20super?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The purpose of this PR is to set the default for ⌘ to `hyper' and to provide the function `kbd-mac-command` to replace `kbd' when defining keybindings for ⌘ in case someone decides to explicitly set osx-command-as to `super' or `alt'. There are problems setting osx-command-as to `alt' and `super', so we use `hyper' as a default instead because, for example: - Using `alt': Command-x or Command-m inserts, respectively: × µ - Using `super': Control-Command-f produces keycode: Setting to `hyper' seems to avoid both types of the above problems. Also, while it is possible, it is not recommended to set to `meta' since standard OSX shortcuts would overshadow important keys such as M-x. Two other small changes include: - Commenting out the code that defines (C-s-f) since it is unnecessary if we use `hyper' as the default; and if we really want to use `super' then we should figure out how to solve the weird keycode issue. - add keybinding for ⌘` (Command-backtick) to `other-window'. Emacs usually swallows this keystroke, so other-window basically restores the default behavior that most Mac OSX users would expect. --- layers/+os/osx/README.org | 5 ++-- layers/+os/osx/config.el | 13 +++++++-- layers/+os/osx/keybindings.el | 52 +++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/layers/+os/osx/README.org b/layers/+os/osx/README.org index f76e34172..2f2f95781 100644 --- a/layers/+os/osx/README.org +++ b/layers/+os/osx/README.org @@ -15,7 +15,7 @@ * Description Spacemacs is not just emacs+vim. It can have OSX keybindings too! This layer -globally defines common OSX keybindings. ~⌘~ is set to ~super~ and ~⌥~ is set to +globally defines common OSX keybindings. ~⌘~ is set to ~hyper~ and ~⌥~ is set to ~meta~. Aside from that, there's nothing much, really. While in =dired= this layer will try to use =gls= instead of =ls=. @@ -37,7 +37,7 @@ The different modifier keys can be set as follows: #+BEGIN_SRC emacs-lisp (setq-defaults dotspacemacs-configuration-layers '( - (osx :variables osx-command-as 'super + (osx :variables osx-command-as 'hyper osx-option-as 'meta osx-control-as 'control osx-function-as 'none @@ -115,6 +115,7 @@ To get =gls= install coreutils homebrew: | ~⌘ w~ | Close window | | ~⌘ W~ | Close frame | | ~⌘ n~ | New frame | +| ~⌘ `~ | Other frame | | ~⌘ z~ | Undo | | ~⌘ Z~ | Redo | | ~⌃ ⌘ f~ | Toggle fullscreen | diff --git a/layers/+os/osx/config.el b/layers/+os/osx/config.el index 4c9fb368e..dc58c4ee6 100644 --- a/layers/+os/osx/config.el +++ b/layers/+os/osx/config.el @@ -16,10 +16,19 @@ option key to type common characters. Default: `deprecated'") -(defvar osx-command-as 'super +(defvar osx-command-as 'hyper "Sets the key binding of the `COMMAND' key on OSX. Possible values are `super' `meta' `hyper' `alt' `none'. - Default: `super'.") + Default: `hyper'.") +;; There are problems setting osx-command-as to `alt' and `super', +;; so we use `hyper' as a default instead because, for example: +;; - Using `alt': Command-x or Command-m inserts, respectively: × µ +;; - Using `super': Control-Command-f produces keycode: +;; Setting to `hyper' seems to avoid both types of the above problems. +;; Also, while it is possible, it is not recommended to set to `meta' +;; since standard OSX shortcuts would overshadow important keys such +;; as M-x. + (defvar osx-option-as 'meta "Sets the key binding of the `OPTION' key on OSX. Possible values are `super' `meta' `hyper' `alt' `none'. diff --git a/layers/+os/osx/keybindings.el b/layers/+os/osx/keybindings.el index cc9776802..8420bc575 100644 --- a/layers/+os/osx/keybindings.el +++ b/layers/+os/osx/keybindings.el @@ -15,7 +15,7 @@ ;; this is only applicable to GUI mode (when (display-graphic-p) - ;; `Command' key is by default bound to SUPER (s-*). + ;; `Command' key is by default bound to HYPER (H-*), ;; `Option' key is by default bound to META (M-*). ;; `Function' key is by default not rebound. ;; `Control' key is by default not rebound. @@ -48,25 +48,39 @@ (when (member key-value allowed-values) (setf (symbol-value internal-var) key-value)))) + (defun kbd-mac-command (keys) + "Wraps `kbd' function with Mac OSX compatible Command-key (⌘). +KEYS should be a string such as \"f\" which will be turned into values +such as \"H-f\", \"s-f\", or \"A-f\" depending on the value of +`mac-commmand-modifier' which could be `hyper', `super', or `alt'. +KEYS with a string of \"C-f\" are also valid and will be turned into +values such as \"H-C-f\". +Returns nil if `mac-command-modifier' is set to `none' or something +other than the three sane values listed above." + (let ((found (assoc mac-command-modifier + '((hyper . "H-") + (super . "s-") + (alt . "A-"))))) + (when found (kbd (concat (cdr found) keys))))) + ;; Keybindings - (global-set-key (kbd "s-=") 'spacemacs/scale-up-font) - (global-set-key (kbd "s--") 'spacemacs/scale-down-font) - (global-set-key (kbd "s-0") 'spacemacs/reset-font-size) - (global-set-key (kbd "s-q") 'save-buffers-kill-terminal) - (global-set-key (kbd "s-v") 'yank) - (global-set-key (kbd "s-c") 'evil-yank) - (global-set-key (kbd "s-a") 'mark-whole-buffer) - (global-set-key (kbd "s-x") 'kill-region) - (global-set-key (kbd "s-w") 'delete-window) - (global-set-key (kbd "s-W") 'delete-frame) - (global-set-key (kbd "s-n") 'make-frame) - (global-set-key (kbd "s-z") 'undo-tree-undo) - (global-set-key (kbd "s-s") + (global-set-key (kbd-mac-command "=") 'spacemacs/scale-up-font) + (global-set-key (kbd-mac-command "-") 'spacemacs/scale-down-font) + (global-set-key (kbd-mac-command "0") 'spacemacs/reset-font-size) + (global-set-key (kbd-mac-command "q") 'save-buffers-kill-terminal) + (global-set-key (kbd-mac-command "v") 'yank) + (global-set-key (kbd-mac-command "c") 'evil-yank) + (global-set-key (kbd-mac-command "a") 'mark-whole-buffer) + (global-set-key (kbd-mac-command "x") 'kill-region) + (global-set-key (kbd-mac-command "w") 'delete-window) + (global-set-key (kbd-mac-command "W") 'delete-frame) + (global-set-key (kbd-mac-command "n") 'make-frame) + (global-set-key (kbd-mac-command "`") 'other-frame) + (global-set-key (kbd-mac-command "z") 'undo-tree-undo) + (global-set-key (kbd-mac-command "s") (lambda () (interactive) (call-interactively (key-binding "\C-x\C-s")))) - (global-set-key (kbd "s-Z") 'undo-tree-redo) - (global-set-key (kbd "C-s-f") 'spacemacs/toggle-frame-fullscreen) ;; window manipulation with command key (global-set-key (kbd "s-1") 'winum-select-window-1) @@ -79,5 +93,9 @@ (global-set-key (kbd "s-8") 'winum-select-window-8) (global-set-key (kbd "s-9") 'winum-select-window-9) + (global-set-key (kbd-mac-command "Z") 'undo-tree-redo) + (global-set-key (kbd-mac-command "C-f") 'spacemacs/toggle-frame-fullscreen) + ;; Emacs sometimes registers C-s-f as this weird keycode - (global-set-key (kbd "") 'spacemacs/toggle-frame-fullscreen))) + ;; (global-set-key (kbd "") 'spacemacs/toggle-frame-fullscreen) + ))