Super key binding in emacs - emacs

(global-set-key (kbd "<s-d>") 'duplicate-line)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECB MODE;;;;;;;;;;;;;;;;;;;;;
(global-set-key (kbd "<s-left>") 'ecb-goto-window-methods)
(global-set-key (kbd "<s-right>") 'ecb-goto-window-edit1)
(global-set-key (kbd "<s-down>") 'ecb-goto-window-history)
(global-set-key (kbd "<s-up>") 'ecb-goto-window-sources)
(global-set-key (kbd "<s-home>") 'ecb-goto-window-directories)
This is part of my .emacs file. I am facing a strange problem while binding a key combination containing super key. Whenever I bind a function to super-key + <alphanumberic value> it refuses to work.
In the above file all the bindings except <s-d> are working fine.
I am using emacs 24.3 on fedora 13

The reason the kbd macro is so convenient is that the argument you pass it is exactly the same thing that Emacs tells you when you ask about a key binding. You're guessing at the argument, but you never need to do that.
When you type C-hk (or C-hc) and then the key sequence in question, Emacs will display a message describing that binding. In this instance it will describe super-key + d as s-d.
Therefore you can use (kbd "s-d") to refer to it.
Ask Emacs to describe a key sequence
Plug the answer into kbd

Some selection which works here:
(global-set-key [(super ?\ö)] 'ar-beginning-of-comment-atpt)
(global-set-key [(super ?\Ö)] 'ar-end-of-comment-atpt)
(global-set-key [(super p)] 'View-sroll-line-backward)
(global-set-key [(super s)] 'hs-hide-all)
(global-set-key [(super tab)] 'scroll-up)
(global-set-key [(super \{)] 'ar-brace-region-atpt)
(global-set-key [(super space)] 'ar-whitespace-to-minus)
(global-set-key [(super kp-4)] 'missing-py-variable-name-face-lp-1215791-test)

All of these are from . . . /lisp/term/ns-win.el
(define-key global-map [?\s-,] 'customize)
(define-key global-map [?\s-'] 'next-multiframe-window)
(define-key global-map [?\s-`] 'other-frame)
(define-key global-map [?\s-~] 'ns-prev-frame)
(define-key global-map [?\s--] 'center-line)
(define-key global-map [?\s-:] 'ispell)
(define-key global-map [?\s-?] 'info)
(define-key global-map [?\s-^] 'kill-some-buffers)
(define-key global-map [?\s-&] 'kill-this-buffer)
(define-key global-map [?\s-C] 'ns-popup-color-panel)
(define-key global-map [?\s-D] 'dired)
(define-key global-map [?\s-E] 'edit-abbrevs)
(define-key global-map [?\s-L] 'shell-command)
(define-key global-map [?\s-M] 'manual-entry)
(define-key global-map [?\s-S] 'ns-write-file-using-panel)
(define-key global-map [?\s-a] 'mark-whole-buffer)
(define-key global-map [?\s-c] 'ns-copy-including-secondary)
(define-key global-map [?\s-d] 'isearch-repeat-backward)
(define-key global-map [?\s-e] 'isearch-yank-kill)
(define-key global-map [?\s-f] 'isearch-forward)
(define-key global-map [?\s-g] 'isearch-repeat-forward)
(define-key global-map [?\s-h] 'ns-do-hide-emacs)
(define-key global-map [?\s-H] 'ns-do-hide-others)
(define-key global-map [?\s-j] 'exchange-point-and-mark)
(define-key global-map [?\s-k] 'kill-this-buffer)
(define-key global-map [?\s-l] 'goto-line)
(define-key global-map [?\s-m] 'iconify-frame)
(define-key global-map [?\s-n] 'make-frame)
(define-key global-map [?\s-o] 'ns-open-file-using-panel)
(define-key global-map [?\s-p] 'ns-print-buffer)
(define-key global-map [?\s-q] 'save-buffers-kill-emacs)
(define-key global-map [?\s-s] 'save-buffer)
(define-key global-map [?\s-t] 'ns-popup-font-panel)
(define-key global-map [?\s-u] 'revert-buffer)
(define-key global-map [?\s-v] 'yank)
(define-key global-map [?\s-w] 'delete-frame)
(define-key global-map [?\s-x] 'kill-region)
(define-key global-map [?\s-y] 'ns-paste-secondary)
(define-key global-map [?\s-z] 'undo)
(define-key global-map [?\s-|] 'shell-command-on-region)
(define-key global-map [s-kp-bar] 'shell-command-on-region)
;; (as in Terminal.app)
(define-key global-map [s-right] 'ns-next-frame)
(define-key global-map [s-left] 'ns-prev-frame)
Here is an example for ctrl+opt+command+s on a US Apple wired mini-keyboard:
(define-key global-map (kbd "<M-C-s-268632083>") 'help-for-help)

Related

Emacs evil: general window movement remap

This is the question I should have asked instead of this:
Emacs evil: space as a prefix key in motion state
I want to define a bunch of commands for moving, moving between, opening and closing windows and buffers that works in all states except insert mode, and are all of the form "SPC ". It would be nice to be able to set this once and be fine everywhere (except when there are conflicts, though overriding would be fine), but if that isn't easy, I would also like to know how to override keybindings in new states that I run across where my keybindings don't work. Hopefully knowing that would also help me edit keybindings in arbitrary states.
What I currently have is this:
(define-key evil-normal-state-map (kbd "SPC") nil)
(define-key evil-motion-state-map (kbd "SPC") nil)
(define-key evil-motion-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-motion-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-motion-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-motion-state-map (kbd "SPC l") 'evil-window-right)
(define-key evil-normal-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-normal-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-normal-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-normal-state-map (kbd "SPC l") 'evil-window-right)
and "SPC H" and so on for moving windows. It doesn't work in list-buffers or Dired. Evil leader only seems to work for normal mode.
We meet again.
Perhaps it'd be simpler to define a prefix keymap and bind to it. For example:
(define-prefix-command 'my-window-map)
(let ((map my-window-map))
(define-key map "h" 'evil-window-left)
(define-key map "j" 'evil-window-down)
(define-key map "k" 'evil-window-up)
(define-key map "l" 'evil-window-right)
(define-key map "H" 'evil-window-move-far-left)
(define-key map "J" 'evil-window-move-very-bottom)
(define-key map "K" 'evil-window-move-very-top)
(define-key map "L" 'evil-window-move-far-right)
;; And presumably, for opening/closing
(define-key map "v" 'evil-window-vsplit)
(define-key map "s" 'evil-window-split)
(define-key map "c" 'evil-window-delete))
Then you can map the prefix keymap to SPC in various modes:
;; Do this for each state you want these bindings available
(define-key evil-motion-state-map " " 'my-window-map)
(define-key evil-visual-state-map " " 'my-window-map)
;; You don't need to unbind/rebind evil-normal-state-map --
;; there is no default mapping for " ". Also: unbound keys in normal
;; mode will fall through to motion bindings.
;; For particular modes (like dired and list-buffer window)
(define-key dired-mode-map " " 'my-window-map)
(define-key Buffer-menu-mode-map " " 'my-window-map)
Alternatively, you can have dired and list-buffer start in normal mode. This will likely interfere with their default mappings.
(evil-set-initial-state 'dired-mode 'normal)
(evil-set-initial-state 'Buffer-menu-mode 'normal)
If you find your mapping overridden by another mode (which shouldn't be common for that key), you can try adding my-window-map to evil-overriding-maps: (add-to-list 'evil-overriding-maps '(my-window-map)). This supposedly gives those maps precedence.
Disclaimer: I haven't tested this. I find it simpler to undefine keys in conflicting plugins.
On a side note, all these commands are already available in evil-window-map. It may be simpler for you to map SPC to that:
(define-key evil-motion-state-map " " 'evil-window-map)
(define-key evil-visual-state-map " " 'evil-window-map)
...

Can I bind action to a keypress in Emacs?

I have (kbd "C-c S-<down>") and (kbd "C-c S-<up>") bound to shrink-window and enlarge-window, respectively.
It works, but I also want Emacs to change window size during a keypress, while I am holding S-<down> or S-<up>.
Is it possible in Emacs?
(define-key global-map [S-up] 'enlarge-window)
(define-key global-map [S-down] 'shrink-window)

Unbinding Evil's C-w mappings?

I'm trying out Emacs with Evil mode.
I'd like to use C-w as a prefix for my own window manipulation shortcuts that are defined globally, not just for buffers with Evil mode. I have the following code in my init.el
(define-prefix-command 'my-window-map)
(global-set-key (kbd "C-w") 'my-window-map)
(define-key my-window-map (kbd "h") 'windmove-left)
(define-key my-window-map (kbd "j") 'windmove-down)
(define-key my-window-map (kbd "k") 'windmove-up)
(define-key my-window-map (kbd "l") 'windmove-right)
(define-key my-window-map (kbd "v") 'split-window-right)
(define-key my-window-map (kbd "b") 'split-window-below)
(define-key my-window-map (kbd "x") 'delete-window)
(define-key my-window-map (kbd "o") 'delete-other-windows)
This works if Evil is not loaded, but when I load Evil it overwrites any conflicting maps (C-w b for example).
I can also comment out L106-158 and L236 from evil-maps.el and my maps work, but I would rather not deal with modifying evil-maps.el.
Is there a way to prevent Evil from using the C-w prefix, or unset it afterwards?
The C-w prefix switches you into the evil-window-map, so undefining C-w in that map will not help. The key mapping in the "evil-maps" file that is relevant sets C-w in evil-motion-state-map to evil-window-map, and that binding is inherited by most of the other evil maps. You could set that keybinding to nil so you can use your own binding in this way:
(eval-after-load "evil-maps"
(define-key evil-motion-state-map "\C-w" nil))
However, neither evil-insert-state-map nor evil-emacs-state-map inherit in this way (I'm pretty sure), so you'll need to unbind in those maps as well. So use the following to unbind in all 3 maps in one fell swoop:
(eval-after-load "evil-maps"
(dolist (map '(evil-motion-state-map
evil-insert-state-map
evil-emacs-state-map))
(define-key (eval map) "\C-w" nil)))
You could also replace the nil with 'my-window-map to rebind to your own mapping, but it's probably already exposed via your call to global-set-key.
The easiest way to do something after some package is loaded is using eval-after-load. In your example, you could put this in your .emacs:
(defun set-control-w-shortcuts ()
(define-prefix-command 'my-window-map)
(global-set-key (kbd "C-w") 'my-window-map)
(define-key my-window-map (kbd "h") 'windmove-left)
(define-key my-window-map (kbd "j") 'windmove-down)
(define-key my-window-map (kbd "k") 'windmove-up)
(define-key my-window-map (kbd "l") 'windmove-right)
(define-key my-window-map (kbd "v") 'split-window-right)
(define-key my-window-map (kbd "b") 'split-window-below)
(define-key my-window-map (kbd "x") 'delete-window)
(define-key my-window-map (kbd "o") 'delete-other-windows))
(set-control-w-shortcuts)
(eval-after-load "evil-maps"
'(progn
(define-key evil-window-map "\C-w" 'nil)
(set-control-w-shortcuts)))

How to keep traditional binding on M-x in emacs evil mode

I am trying to bind execute-extended-command to M-x in evil normal mode.
I currently have
;; evil mode
(require 'evil)
(evil-mode 1)
(define-key evil-normal-state-map "M-x" 'execute-extended-command)
in my .emacs file but the keybinding doesn't work. I tried replacing
"M-x"
with
"\M-x"
and
(kbd "M-x")
but neither works. I also tried adding it to evil.el and evil-maps.el.
I don't know what's wrong with your binding. You could use Emacs' own global-set-key for global stuff and if you plan something special for say, insert mode, you could override that later on, like this:
;; this works, just tested. My evil is 1.0-dev from github.
(global-set-key (kbd "M-x") 'smex)
(define-key evil-insert-state-map (kbd "M-x") 'execute-extended-command)
Use (kdb "") macro when you have modifier keys in your binding. But you can use the macro always, regardless of the content. These are for example usage. When in doubt, wrap the key in (kdb ).
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;;(global-set-key (kbd "M-x") 'execute-extended-command)
(define-key evil-normal-state-map ",d" 'volatile-kill-buffer)
(define-key evil-normal-state-map ",b" 'ido-switch-buffer)
(define-key evil-normal-state-map ",s" 'ispell-word)
(define-key evil-normal-state-map (kbd "C-x g") 'magit-status)
(define-key evil-insert-state-map (kbd "C-f") 'my-expand-file-name-at-point)
(define-key evil-insert-state-map (kbd "C-x C-l") 'my-expand-lines)
(define-key minibuffer-local-map (kbd "C-w") 'backward-kill-word)
(define-key evil-normal-state-map (kbd ",ff") 'ido-find-file)
After long research and with help from #emacs and #evil-mode channels on irc, it turned out that my emacs was broken. It was a snapshot from http://emacs.naquadah.org/ I tried all this on another emacs version (from debian jessies repos) and it worked ok.

Emacs Meta-Key in Terminal

I'm trying to configure my Meta-Key, such that I can input {},[], etc. in a terminal emacs (using a German keyboard). I haved tried setting my Meta-Key, but can't get it to work. I want to use Alt+8 for {, Alt+9 for }, Alt-5 for [, Alt-6 for ].
(setq mac-option-modifier nil
mac-command-modifier 'meta
x-select-enable-clipboard t)
See:
Unable to type braces and square braces in emacs
Have you tried?
(define-key global-map (kbd "M-8") "{")
(define-key global-map (kbd "M-9") "}")
For macos azerty French keyboard. It's :
(define-key global-map (kbd "M-(") "{")
(define-key global-map (kbd "M-)") "}")