How to change window-numbering default key binding - emacs

The default key binding is below:
(defvar window-numbering-keymap
(let ((map (make-sparse-keymap)))
(define-key map "\M-0" 'select-window-0)
(define-key map "\M-1" 'select-window-1)
(define-key map "\M-2" 'select-window-2)
(define-key map "\M-3" 'select-window-3)
(define-key map "\M-4" 'select-window-4)
(define-key map "\M-5" 'select-window-5)
(define-key map "\M-6" 'select-window-6)
(define-key map "\M-7" 'select-window-7)
(define-key map "\M-8" 'select-window-8)
(define-key map "\M-9" 'select-window-9)
map)
"Keymap used in by `window-numbering-mode'.")
I want to use the key "Command (s)" instead of Meta, I change the key binding like this:
(define-key map "\s-1" 'select-window-1)
but it doesn't work. In minibuffer: s-1 is undefined.

As #Drew said, changing "\s-1" to (kbd "s-1") works OK. Thank you Drew.

Related

Is there a way to make <menu> a prefix key in emacs?

I'm trying to get vimish-fold to work, and it does work. The problem is that I want to bind it to the menu key instead of the M key.
(progn
(define-prefix-command 'my-menu-key-map)
(define-key vimish-fold-mode (kdb "v f") 'vimish-fold)
(define-key vimish-fold-mode (kdb "v u") 'vimish-fold-refold)
)
(global-set-key (kdb "<menu>") my-menu-key-map)
I essentially want menu v f -> vimish-fold and menu v u -> vimish-fold-refold. The problem I'm having is it's giving me an error telling me I have the wrong type argument.
Error in private config: init.el, (wrong-type-argument keymapp nil)
You have some repeated typos:
(kdb should be (kbd
(define-key vimish-fold-mode should be (define-key my-menu-key-map

Emacs, binding "C-c s" key to "<menu>" key

How to bind "C-c s" to "< menu >" key, so that I can use Cscope in emacs easily? My aim is to replace C-c s prefix with menu key.
Instead of pressing "C-c s g", I have to press "< menu > g" and
Instead of pressing "C-c s =", I have to press "< menu > =" and for remaining cscope bindings.
edit 1:
Well, I have already done this by binding each key separately to cscope functions. I was searching for more generic and smaller solution.
I have done it like this,
(define-key global-map [(menu) (s)] 'cscope-find-this-symbol)
(define-key global-map [(menu) (d)] 'cscope-find-global-definition)
(define-key global-map [(menu) (g)] 'cscope-find-global-definition)
(define-key global-map [(menu) (G)] 'cscope-find-global-definition-no-prompting)
(define-key global-map [(menu) (=)] 'cscope-find-assignments-to-this-symbol)
(define-key global-map [(menu) (c)] 'cscope-find-functions-calling-this-function)
(define-key global-map [(menu) (C)] 'cscope-find-called-functions)
(define-key global-map [(menu) (t)] 'cscope-find-this-text-string)
(define-key global-map [(menu) (e)] 'cscope-find-egrep-pattern)
(define-key global-map [(menu) (f)] 'cscope-find-this-file)
(define-key global-map [(menu) (i)] 'cscope-find-files-including-file)
;; --- (The '---' indicates that this line corresponds to a menu separator.)
(define-key global-map [(menu) (b)] 'cscope-display-buffer)
(define-key global-map [(menu) (B)] 'cscope-display-buffer-toggle)
(define-key global-map [(menu) (n)] 'cscope-history-forward-line-current-result)
(define-key global-map [(menu) (N)] 'cscope-history-forward-file-current-result)
(define-key global-map [(menu) (p)] 'cscope-history-backward-line-current-result)
(define-key global-map [(menu) (P)] 'cscope-history-backward-file-current-result)
(define-key global-map [(menu) (u)] 'cscope-pop-mark)
;; ---
(define-key global-map [(menu) (a)] 'cscope-set-initial-directory)
(define-key global-map [(menu) (A)] 'cscope-unset-initial-directory)
;; ---
(define-key global-map [(menu) (L)] 'cscope-create-list-of-files-to-index)
(define-key global-map [(menu) (I)] 'cscope-index-files)
(define-key global-map [(menu) (E)] 'cscope-edit-list-of-files-to-index)
(define-key global-map [(menu) (W)] 'cscope-tell-user-about-directory)
(define-key global-map [(menu) (S)] 'cscope-tell-user-about-directory)
(define-key global-map [(menu) (T)] 'cscope-tell-user-about-directory)
(define-key global-map [(menu) (D)] 'cscope-dired-directory)

Rebind digits for normal mode in evil

Is it possible to rebind digits. That, for example, "5" is "$", and "%" is "5"?
In evil-maps.el digits are defined like this.
(define-key evil-motion-state-map "1" 'digit-argument)
(define-key evil-motion-state-map "2" 'digit-argument)
...
I tried the answer of #ChillarAnand
(add-hook 'evil-mode-hook 'evil-mode-bindings)
(defun evil-mode-bindings ()
"Bind symbols to digits."
(define-key key-translation-map (kbd "%") "5")
(define-key key-translation-map (kbd "*") "8")
)
(define-key evil-normal-state-map "5" 'evil-beginning-of-line)
(define-key evil-normal-state-map "8" 'evil-end-of-line)
But Shift-5 still does not behave like 5, the same is true for 8.
Is it possible to fix it for the config above?
The same stands for #tarblet solution.
What I use as a test is a sequence Shift-5, G.
Quite a hacky solution, but it should do what you want:
(defun capslock-digit-argument-fn (digit)
`(lambda (arg)
(interactive "P")
(setq last-command-event (+ ,digit ?0))
(digit-argument arg)))
(define-key evil-motion-state-map "!" (capslock-digit-argument-fn 1))
(define-key evil-motion-state-map "#" (capslock-digit-argument-fn 2))
(define-key evil-motion-state-map "#" (capslock-digit-argument-fn 3))
(define-key evil-motion-state-map "$" (capslock-digit-argument-fn 4))
(define-key evil-motion-state-map "%" (capslock-digit-argument-fn 5))
(define-key evil-motion-state-map "^" (capslock-digit-argument-fn 6))
(define-key evil-motion-state-map "&" (capslock-digit-argument-fn 7))
(define-key evil-motion-state-map "*" (capslock-digit-argument-fn 8))
(define-key evil-motion-state-map "(" (capslock-digit-argument-fn 9))
It rebinds the variable which digit-argument looks at when trying to figure out which key was pressed. If you don't mind ) not behaving exactly like 0 (no jumping to beginning of line, only working as digit arg) you could set it as well.
Ofcourse, anything is possible in emacs :)
Add this piece of code to you config.
(add-hook 'evil-mode-hook 'evil-mode-bindings)
(defun evil-mode-bindings ()
"Bind symbols to digits."
(define-key key-translation-map (kbd "!") (kbd "1"))
(define-key key-translation-map (kbd "#") (kbd "2"))
(define-key key-translation-map (kbd "#") (kbd "3"))
(define-key key-translation-map (kbd "$") (kbd "4"))
(define-key key-translation-map (kbd "%") (kbd "5"))
(define-key key-translation-map (kbd "^") (kbd "6"))
(define-key key-translation-map (kbd "&") (kbd "7"))
(define-key key-translation-map (kbd "*") (kbd "8"))
(define-key key-translation-map (kbd "(") (kbd "9"))
(define-key key-translation-map (kbd ")") (kbd "0")))
Whenever You enter evil mode, evil-mode-hook runs evil-mode-bindings function. This function binds, symbols to corresponding digits.
Update:
As #npostavs mentioned, You can also use this
(add-hook 'evil-mode-hook 'evil-mode-bindings)
(defun evil-mode-bindings ()
"Bind symbols to digits."
(define-key key-translation-map (kbd "!") "1")
(define-key key-translation-map (kbd "#") "2")
(define-key key-translation-map (kbd "#") "3")
(define-key key-translation-map (kbd "$") "4")
(define-key key-translation-map (kbd "%") "5")
(define-key key-translation-map (kbd "^") "6")
(define-key key-translation-map (kbd "&") "7")
(define-key key-translation-map (kbd "*") "8")
(define-key key-translation-map (kbd "(") "9")
(define-key key-translation-map (kbd ")") "0"))

in Emacs, how to change key bindings for orgstruct-mode?

I use custom key bindings for org-mode:
(eval-after-load "org"
'(progn
(define-key org-mode-map (kbd "<M-S-left>") nil)
(define-key org-mode-map (kbd "<M-S-right>") nil)
(define-key org-mode-map (kbd "<M-S-up>") nil)
(define-key org-mode-map (kbd "<M-S-down>") nil)
(define-key org-mode-map (kbd "<M-left>") nil)
(define-key org-mode-map (kbd "<M-right>") nil)
(define-key org-mode-map (kbd "<M-right>") nil)
(define-key org-mode-map [C-S-right] 'org-shiftmetaright)
(define-key org-mode-map [C-S-left] 'org-shiftmetaleft)
(define-key org-mode-map [C-right] 'org-metaright)
(define-key org-mode-map [C-left] 'org-metaleft)
(define-key org-mode-map [C-up] 'org-metaup)
(define-key org-mode-map [C-down] 'org-metadown)
(define-key org-mode-map [C-S-return] 'org-insert-todo-heading)
))
I'd like to use these same key bindings in orgstruct-mode, which I run overtop message-mode. What I tried doesn't work:
(define-key orgstruct-mode-map (kbd "<M-S-left>") nil)
(define-key orgstruct-mode-map (kbd "<M-S-right>") nil)
(define-key orgstruct-mode-map (kbd "<M-S-up>") nil)
(define-key orgstruct-mode-map (kbd "<M-S-down>") nil)
(define-key orgstruct-mode-map (kbd "<M-left>") nil)
(define-key orgstruct-mode-map (kbd "<M-right>") nil)
(define-key orgstruct-mode-map (kbd "<M-up>") nil)
(define-key orgstruct-mode-map (kbd "<M-down>") nil)
How can I change the key map for orgstruct-mode?
Defining a key to nil unbinds it. By unbinding a key in orgstruct-mode-map (the minor mode), you've exposed the message-mode-map (the major mode) bindings. You can override the message-mode-map keybindings by actively binding those keys in orgstruct-mode-map, but if you want to unbind them, you'll need to unbind the keys in message-mode-map as well.
Here's a way to unbind all of those keys in both maps:
(cl-dolist (map '(message-mode-map orgstruct-mode-map))
(cl-dolist (key '("<M-S-left>" "<M-S-right>" "<M-S-up>" "<M-S-down>"
"<M-left>" "<M-right>" "<M-up>" "<M-down>"))
(define-key (eval map) (kbd key) nil)))

xcscope key rebinding in in conflict with emacs default

I have the following in my init.el but c-\ in emacs binds to input method. I don't use input method anyways so is there a way to disable c-\ not to bind to input method?
(add-to-list 'load-path "~/.emacs.d")
(require 'xcscope)
(setq cscope-do-not-update-database t)
(define-key cscope:map "\C-\\s" 'cscope-find-this-symbol)
(define-key cscope:map "\C-\\g" 'cscope-find-global-definition)
(define-key cscope:map "\C-\\d" 'cscope-find-called-functions)
(define-key cscope:map "\C-\\c" 'cscope-find-functions-calling-this-function)
(define-key cscope:map "\C-\\t" 'cscope-find-this-text-string)
(define-key cscope:map "\C-\\e" 'cscope-find-egrep-pattern)
(define-key cscope:map "\C-\\f" 'cscope-find-this-file)
(define-key cscope:map "\C-\\i" 'cscope-find-files-including-file)
(define-key cscope:map "\C-\\b" 'cscope-display-buffer)
(define-key cscope:map "\C-\\B" 'cscope-display-buffer-toggle)
(define-key cscope:map "\C-\\n" 'cscope-next-symbol)
(define-key cscope:map "\C-\\N" 'cscope-next-file)
(define-key cscope:map "\C-\\p" 'cscope-prev-symbol)
(define-key cscope:map "\C-\\P" 'cscope-prev-file)
(define-key cscope:map "\C-\\u" 'cscope-pop-mark)
(define-key cscope:map "\C-\\v" 'cscope-history-backward)
(define-key cscope:map "\C-\\V" 'cscope-history-forward)
Try this:
(global-unset-key (kbd "C-\\"))