Unbinding emacs keys for multi-term in emacs 23 - emacs

I'm trying to setup multi-term for emacs 23, but the
(setq term-unbind-key-list '("C-z" "C-x" "C-c" "C-h" "C-y"))
line all the websites I've seen recommend for getting rid of key binding clashes doesn't work- I still can't C-z out of man pages for example.
Did something change in emacs 23? How do I unbind them properly?

The variable term-unbind-key-list only affects bindings in the key map term-raw-map. You can find this out by looking at the documentation for the function multi-term-keystroke-setup (no idea why this information isn't available for the variable itself...)
Keystroke setup of `term-char-mode'.
By default, the key bindings of term-char-mode' conflict with user's
keystroke. So this function unbinds some keys withterm-raw-map', and
binds some keystroke with `term-raw-map'.
So... likely the C-z is still bound to suspend-frame b/c that's what Emacs does by default.
If you want C-z to be bound to what it is normally in a terminal (suspend-job), you can do this:
(require 'multi-term)
(add-to-list 'term-bind-key-alist '("C-z" . term-stop-subjob))
Which makes the binding do what (I'm guessing) you want.

Related

Emacs: How to bind key only in regular buffers and not in the minibuffer?

I have written a fancy function, which I would like to bind to TAB. The functionality is only meaningful in any non-read-only text buffer. Currently, I bind it either like that:
(global-set-key (kbd "<tab>") 'my-indent-region)
or
(define-key global-map (kbd "<tab>") 'my-indent-region)
The problem with this binding is that now tab-completion does no longer work in the minibuffer, which is an essential feature (e.g. for buffer/file names, or M-x).
Is it possible to bind TAB only for regular modes? I know that I can use define-key some-major-mode-map, but since I want it in all modes except for the minibuffer, this would be annoying to maintain. Thus, I'm probably looking for something like a define-key any-mode-except-minibuffer ....
If such a functionality does not exist: Is there a workaround to get the tab-completion working in the minibuffer again? Maybe I can re-set the original minibuffer tab binding after changing the global binding? I couldn't figure out though which function I actually have to bind to make it work.
After some more research I found a workaround/solution to the problem in this answer.
Apparently, my problem was that I was binding to (kbd "<tab>"). If I understand it correctly, my problem was in fact not that I overwrote the actual keymap of the minibuffer -- I guess they are correctly loaded when entering the minibuffer minor modes. However, there seems to be a precedence of a binding to (kbd "<tab>") over a binding to just "\t". According to the above answer, the minibuffer bindings just use "\t", so binding to (kbd "<tab>") shadows them. I'm now using the following binding instead:
(global-set-key "\t" 'my-indent-region)
Now everything seems to be working fine.
Do you see this behavior when you start Emacs without your init file (emacs -Q)? I doubt it. If not, then recursively bisect your init file to find out what is causing the problem.
The minibuffer uses its own keymaps, which are local and which therefore take precedence over global keymap bindings.
However, any minor-mode keymaps take precedence over local keymaps. So if, for example, you have a (global) minor mode turned on that binds <tab> then that will override any binding for that key in the minibuffer keymaps.
Another thing you can do is simply bind whatever command you want to <tab> in the minibuffer keymaps. But again, you should not need to do that, if you want the usual <tab> behavior for the minibuffer.
[Another possible confusion: Some things, such as Isearch, which you might think use the minibuffer do not use it. Isearch uses its own keymap, isearch-mode-map.]
UPDATE after your comment:
Assigning a key in the global map, as you have done, should not affect what that key does in the minibuffer, provided it has a different binding in the minibuffer keymaps. TAB is typically bound in all of the minibuffer completion keymaps (but not in the non-completion minibuffer keymaps).
See the Elisp manual, nodes Completion Commands and Text from Minibuffer for information about the minibuffer keymaps.
To see what the current bindings are for a keymap that is associated with a variable (such as minibuffer-local-completion-map), load library help-fns+.el and use C-h M-k followed by the keymap variable's name. (See Help+ for more information about the library.)
If you do not want TAB to use your global command binding in the non-completion minibuffer maps (minibuffer-local-map, minibuffer-local-ns-map), then just bind it in those maps to whatever command you like. But for the completion maps you should not need to do anything - TAB should already be bound there.
Did you try emacs -Q, to see if something in your init file is interfering? If not, do that first.

org mode - how to disable some keybindings?

I started using Emacs (currently for org mode only). I don't use priorities in my TODOs, hence I'd like to disable S-UP and S-DOWN key bindings (which loop through the priorities). How can I do this?
#lawlist gave you the recipe in his comment. Here's how to find this out for yourself.
See if there is a keymap variable for the mode in question - typically there is one. In this case, try C-h v org-mode-map. If you find no such variable, fish around a little, using the apropos commands - for example, M-x apropos-variable org-mode.
Bind the key(s) in question to nil in that keymap:
(define-key org-mode-map (kbd "S-<up>") nil)
C-h m gives you info about the current mode. Sometimes it lists the important key bindings for the mode. And C-h b (anywhere) lists lots of key bindings for the current context.
If you want to see all of the key bindings that belong to a given keymap variable (in human-readable form), then load library help-fns+.el and then use C-h M-k followed by the keymap variable name (e.g. org-mode-map). See Help+.

disable package key-binding override in Emacs

This seems like some basic Emacs configuration issue that I do not understand.
I have Emacs 24.3 preinstalled on site. In a Verilog file, pressing M-s is bound to p4-current-file "edit" (Perforce operation), likewise M-e is bound to p4-current-file "sync". All is well.
The problem is in a VHDL file, M-s does the same, but M-e is bound to "vhdl-end-of-statement". I would like it to do "p4 edit" like in Verilog.
Seems that vhdl-mode is overriding the M-e key function, and I cannot not find how to change this permanently. If I do local-unset-key and unset M-e, I get the desired result, M-e does p4 edit, but when I restart Emacs M-e does "vhdl-end-of-statement" again.
How can I change M-e to do "p4 edit" permanently? I'm not fluent in Lisp, but will be happy to get instructions how to change this.
Thanks.
To remove an over-riding binding from a mode keymap, so that Emacs will fall back to what it would usually use, you would normally do something like this:
(eval-after-load "vhdl-mode"
'(progn
(define-key vhdl-mode-map (kbd "M-e") nil) ;; unbind M-e
(define-key vhdl-mode-map (kbd "M-a") nil))) ;; unbind M-a
As MrBones comments, though, these are not very desirable custom bindings. Both M-s and M-e have standard uses in Emacs (the former is normally a prefix binding which a bunch of useful things hang off), and if possible you should consider moving those bindings to other keys.
(My impression is that the "preinstalled on site" version had these bindings already in place, though? In which case that's more a note for whoever maintains that...)

Emacs, probing arbitrary keymap

key-binding probes keys in the currently active keymaps. For those keymaps, such as minibuffer ones, or isearch-mode-map which are restrictive and become inactive as soon as the user presses a key outside of a limited set of defined keys, I am not able to invoke key-binding without deactivating those keymaps.
How do I:
Determine which keymaps come into effect after invoking certain commands (for example, isearch-mode-map is set as the overriding-local-map by isearch-forward-regexp) in a way that does not involve analyzing source code. Is there a hook that I can use to track/log the state of a variable?
Probe keys in those keymaps. For example, to what is RET bound in isearch-mode-map?
My closest solution has been to bind this function:
(defun probe_keybinding ()
(interactive)
(message (prin1-to-string (key-binding (read-key-sequence-vector "Enter key to probe"))))
)
to an uncommon key like 'S-f9' and invoke it when the keymaps in which I am interested are active (eg in the middle of a find-file in the minibuffer or a eval-expression). This does not always work, for example, isearch-forward-regexp exits as soon as a non-recognized key is entered.
There's no easy way to determine which keymaps will come into use in response to particular commands. Any function can call (use-local-map ...) whenever it likes, so the only way to be sure is to read the source code.
Having said that, the Emacs code does follow conventions that make it possible to find the answer in many cases. If foo-mode has a keymap, then the keymap will usually be named foo-mode-map. You can see a list of variables with names ending in -map by running M-x apropos RET -map$ RET.
You can look up a key in a keymap with the function lookup-key. See "Functions for Key Lookup" in the Emacs Lisp manual. So to find out what RET is bound to in isearch-mode-map, evaluate:
(lookup-key isearch-mode-map (kbd "RET"))
===> isearch-exit
Another element of the answer is to look at individual keymaps. Unfortunately, if you just do C-h v isearch-mode-map (or any other keymap variable) you will see a Lisp expression that is not very readable.
Instead, you can use describe-keymap, from library help-fns+.el. It is bound to C-h M-k, and it shows you all of the (non-menu) keys bound in a keymap, in a human-readable way. More description here.

writing lisp emacs key binding and cannot specify the <delete> character

For some reason I got the default M-del key binding for backward-kill-word mapped to a scan for matching brackets and resetting is not working, so I am trying to set the global key binding in lisp. So I wrote in ~/.emacs.d/init.el the lisp commands:
(global-set-key (kbd "M-h") 'backward-kill-word)
(global-set-key (kbd "M-<\delete>") ‘backward-kill-word)
I tried them with C-x C-e and they both give the 'backward-kill-word output but only the first key-binding works "M-h", the other is ignored and M-del still trying the strange scanning action. The delete key works in emacs elsewhere, so it seems like "delete" is not being mapped to the physical key in lisp (and the backslash is there to show in this text only as the word was being commented out). Any idea what keyword to use or special character?
Best.
(I looked for libraries that may have overrided this command but I cannot find them)
On some systems, the delete key is defined as an alias to C-d. This is done through function-key-map on GNU Emacs <23 and local-function-key-map on GNU Emacs 23. (I've observed this behavior on Debian and Ubuntu 10.04 under X.) The purpose of such translations is to isolate people who code modes from the terminal intricacies: a mode that wants to shadow the delete command only needs to rebind C-d and not wonder if it should rebind delete (is that a delete left or delete right?) or deletechar or something else.
If there is a global or local binding for delete, it shadows this translation to C-d. However, if you press ESC delete, if there is no global or local binding for ESC delete, the second key is translated to C-d. This translation has precedence over the interpretation of ESC delete as M-delete. So ESC delete becomes equivalent to C-M-d.
This is arguably a bug in Emacs: the effect of ESC delete should be the same as M-delete, and there is no reason why ESC delete would run down-list which has nothing to do with deletion.
There are several possible fixes; I don't know which is best. One that should work with any version of Emacs is
(global-set-key [?\e delete] 'backward-kill-word)
The really nice thing about kbd is that what you type there is the same string that Emacs displays. So, try the following
C-h k M-<\delete> (to use your syntax)
or
M-x describe-key M-<\delete>
Emacs (for me) responds with:
M-DEL (translated from <M-delete>)
runs the command backward-kill-word,
which is an interactive compiled Lisp
function in `simple.el'.
It is bound to , M-DEL.
(backward-kill-word arg)
....
Which you can see shows that the representation for the key you want is M-DEL or M-delete.
Which is a long way of getting to the point that what you want is
(global-set-key (kbd "M-delete") 'backward-kill-word)
Of course, if you have something in your .emacs that overrides it, the above won't help. You'll need to find that included library and stop using it (or customize its behavior).
You might want to call global-set-key interactively to see how it interprets meta-delete. Also try local-set-key to ensure the strange binding is not mode-specific.
After not being able to find the library holding the conflict I found this webpage
http://www.cs.cmu.edu/cgi-bin/info2www?%28emacs%29Rebinding
Changing Key Bindings Interactively...
`M-x global-set-key KEY CMD '
Define KEY globally to run CMD....
Normally, C-z' is bound to the function
suspend-emacs' (when not using the X Window System), but you can
change C-z' to invoke an interactive subshell within Emacs, by binding
it toshell' as follows:
M-x global-set-key <RET> C-z shell <RET>
`global-set-key' reads the command name after the key. After you
press the key, a message like this appears so that you can confirm that
you are binding the key you want:
Set key C-z to command:...
And now the standard default is returned to by doing
M-x global-set-key M-del ...
backward-kill-word
But this is transient and must be done on each reload, any way to make this permanent?
Putting a command into the init.el is not overriding the other effect