How to unbind and rebind? - emacs

When working with tables, I noticed that org-table-insert-row is not bound to any keybinding.
I would like to bind it to M-S-<down>, but this key binding is currently associated with
<M-S-down> runs the command move-text-down, which is an interactive autoloaded Lisp function in
‘move-text-20170909.330/move-text.el’.
It is bound to <M-S-down>, <C-S-down>, <menu-bar> <Prelude> <Editing> <Move down>.
move-text-down has so many bindings!
In any case, how to tell my init.el to unbind the existing binding to move-text-down?
I have at the moment:
(global-set-key (kbd "<M-S-down>") 'org-table-insert-row) ;
But it is not working.

Related

redefined keys doesn't work correctly

I've redefined key bindings for some basic movement functions in my init.el file:
(global-set-key "\C-j" 'backward-char)
(global-set-key "\C-k" 'next-line)
(global-set-key "\C-l" 'forward-char)
(keyboard-translate ?\C-i ?\H-i)
(global-set-key [?\H-i] 'previous-line)
(global-set-key "\M-j" 'backward-word)
(global-set-key "\M-l" 'forward-word)
And in general (text editing) it perfectly works, but in some modes it executes multiple commands, e.g. in Buffer mode when I press C-k aside from moving the cursor down Emacs marks the listed buffer for deletion. Also, when I call helm-prelude with C-c p h and press one of these key bindings Emacs either doesn't react at all or, in case of C-k, clears the search bar. I thought that the purpose of global-set-key was to bind commands to specific keys everywhere, am I wrong?
Local (e.g., major-mode) keymap bindings trump global keymap (global-map) bindings. And minor-mode keymap bindings trump both of these.
There is a hierarchy of several keymap types that determines which maps take precedence. See the Elisp manual, node Controlling Active Maps (and nearby nodes about keymaps). The full hierarchy is a bit complicated, but most of the time what you need to be aware of is what I stated in the preceding paragraph.
Yes, the global keymap is only used when there is no binding for the key being pressed in a local keymap. For example, the buffer menu mode uses Buffer-menu-mode-map, where C-k is bound to Buffer-menu-delete.
You may have better luck using keyboard-translate to translate these keys to the "normal" Emacs bindings for those commands, i.e. C-p, C-n etc.

Keymapping in emacs using semantic with interactive functions and default parameters invocation

In semantic; to move around function declarations it is possible to use C-c , J to open declaration, and just C-u C-SPC to return where the function was called. However to map those functions to some other short keybindings like that M-right (meaning alt key in combination with right arrow), so in our .emacs we can have:
(define-key global-map [(M-right)] 'semantic-complete-jump).
This indeed works because C-c , J is mapped to invoke the semantic-complete-jump function.
So two questions:
How to map M-left to the C-u C-SPC? remembering that C-u is not a part of the command, it is just the argument passed to the invoked function.
Is there any way to invoke semantic-complete-jump via C-c , J without being interactive and using by default always the default value (that it is mainly the word under where is the cursor)? This will allow to avoid one additional keystroke moving much faster around the code.
This is possible to do with M-. (mapped to find-tag) and M-* (mapped to pop-tag-mark) playing with tags and etags with emacs, but using semantic it seems to be much more powerful and ideal for big projects with large amount of code.
S̲o̲ ̲t̲h̲e̲ ̲p̲r̲e̲v̲i̲o̲u̲s̲ ̲t̲w̲o̲ ̲q̲u̲e̲s̲t̲i̲o̲n̲s̲ ̲w̲h̲a̲t̲ ̲a̲r̲e̲ ̲a̲s̲k̲i̲n̲g̲ ̲i̲s̲: what configuration lines are needed just to use M-right to move inside the function declarations (without being asked) and M-left to go to the previous point were this function was called using semantic.
Here's what I've got:
(add-hook
'c-mode-common-hook
(lambda()
(define-key c-mode-base-map
(kbd "C-x C-h") 'semantic-ia-fast-jump)))
(global-set-key
(kbd "M-p")
(lambda()(interactive) (set-mark-command 4)))

How to define emacs keybinding 'C-c C-c'?

I want to bind the 'C-c C-c' to a custom command, don't know how to.
I tried (global-set-key (kbd "C-c C-c") 'suspend-emacs), but it seams not work.
Any idea will be appreciated.
Thanks.
It is very likely that the local binding of C-c C-c in the current buffer is shadowing the global binding that you make with global-set-key. Conventionally, key sequences consisting of C-c followed by a control character are reserved for major modes. For instance, CC Mode gives C-c C-c a local binding as comment-region. Key sequences consisting of C-c and a letter (either upper or lower case) are set aside for users:
(global-set-key (kbd "C-c c") 'suspend-emacs)
And you may not want to bind suspend-emacs to a new key sequece. suspend-frame, which is bound to C-z and C-x C-z by default, calls suspend-emacs for us when it is invoked from the (controlling) tty device.

emacs unbound key bindings

How do I clear a binding or edit a binding an emacs package provide?
For instance I had keybindings M-c to capitalize a word.
After I install some 3rd party emacs package, it is changed to calc-dispatch.
I'd like to use M-c as capitalize as before, and set calc-dispatch to something else.
How can I do this in general?
The keybind maps are loaded by order. The keybind map which loaded later will have higher priority. This is why the local key map will override the global keymap, because the global key map is loaded before the local key map(the mode key map). Something is wrong here. Look phils's comment.
What I solve this problem is add a hook to that specify mode to disable that key bind and rebind it to other key in that key map.
First, you need to find the key-map name which defines the M-c bind to calc-dispatch.
It is usually the combination of mode name and mode-map.
For example, the name of python mode key map is py-mode-map.
Second, remove the M-c bind in that mode and rebind to other key using hook.
For example, in python mode, I want to remove the bind C-j (py-newline-and-indent). And rebind it to C-i. Because globally I bind C-j to linum-ace-jump. This is the similar case with yours.
(add-hook 'python-mode-hook
#'(lambda ()
(define-key py-mode-map "\C-j" nil)
(define-key py-mode-map "\C-i" 'py-newline-and-indent)))
What you ask for is:
(global-set-key (kbd "M-c") 'capitalize-word)
This is in general the way to set words globally.
Maybe if you want to substite the two, you can try this:
(substitute-key-definition
'capitalize-word 'calc-dispatch (current-global-map))
(define-key KEYMAPNAME (kbd "KEYCOMBO") 'FUNCNAME)
Is for specific mode. For example: (define-key emacs-lisp-mode (kbd "M-c) 'capitalize-word).
(global-set-key (kbd "M-c") nil)
Is to generally unbind a key (globally).
You can easily find more on this by just googling.

Shift selection and page up/down in emacs 23

I’m trying to replace pc-selection-mode with the new shift-select-mode with emacs 23. It works generally well, only the shift+pgup/down keys don’t create a selected region and I can’t find a confguration setting where I could tell emacs I want these keys too shift translated. Are the supported keys hardcoded? It would be so unlike emacs, so there must be some setting somewhere which I overlook. Any ideas?
I removed PC-select mode and this just worked. For the record, here's what I get for the Page-Down key from describe-key:
<next> (translated from <S-next>) runs the command scroll-up, which is
an interactive built-in function in `C source code'.
It is bound to <next>, C-v.
(scroll-up &optional ARG)
...
With pc-select-mode enabled, Shift-PageUp is bound to scroll-down-mark and Shift-PageDown scroll-up-mark. scroll-down-mark is from pc-select.el so you have to require it before binding the keys (you don't have to enable pc-select).
Binding keys as mentioned can be done evaluating:
(require 'pc-select)
(global-set-key (kbd "S-<prior>") 'scroll-down-mark)
(global-set-key (kbd "S-<next>") 'scroll-up-mark)