Mapping dead keys like "^" - emacs

I'm currently rebinding almost all of my Emacs bindings to fit my new keyboard layout, bépo, a french equivalent of dvorak.
I'm having trouble mapping my ^ key. The ^ key is a dead key but not at a material level.
I'd like to be able to to map C-^ but currently, it don't work. Because "dead-circumflex" and "circumflex" are two different keys.
If I do:
(global-set-key "C-^" 'next-line)
Then, pressing control key with "^" key does the following:
<C-dead-circumflex> is undefined
We have the proof emacs see the dead-circumflex. But I still can't manage to map it.
I know that I can do
(global-set-key "^" 'next-line)
, and that it will work by pressing ^ twice, but it's not the workaround I'm searching for.

I just had the same annoying error, but only when using the emacs GUI, not from the terminal.
The problem with the proposed solution is that ^ isn't the only character not working. For me it was at least ` and ' as well.
From this thread: https://bugzilla.redhat.com/show_bug.cgi?id=918740 I found that changing XMODIFIERS from "#im=ibus" to "" solved the issue. While searching where XMODIFIERS where set I stubled across the following issue: https://bugs.launchpad.net/ubuntu/+source/ibus/+bug/1125944
It turns out that by removing ~/.config/ibus/bus which solves that issue also solves the issue in emacs with dead keys
rm -rf ~/.config/ibus/bus

The error message tells you what name Emacs uses for the key. You can pass that string to the kbd function to bind it.
(global-set-key (kbd "<C-dead-circumflex>") 'next-line)

Add the following to your ~/.emacs:
(require 'iso-transl)
This takes care of the problem with undefined dead keys.

Related

emacs in terminal meta arrow keybindings

I have just switched from using Emacs.app to emacs server and emacsclient in terminal mode using iterm2 as my terminal emulator. I am having some trouble with some keybindings though. Particularly M-left arrow prints the character D, M-right arrow prints C, M-up arrow prints A, and M-down arrow prints B. M-ret seems to work though, at least for org mode. I am using the xterm defaults for keys in iterm2 and have the left and right option keys bound to +Esc. I can get the M-left functionality in org-mode with Esc-left or Esc-right This is particularly annoying in org-mode. Am I going to have to just rebind the keys in my .emacs? How would I go about doing that?
I have looked at this http://orgmode.org/manual/TTY-keys.html#TTY-keys, but I don't understand why the arrow keys should be unavailable in the terminal.
edit:
Cat meta-up: ^[[1;9A
Cat meta-down: ^[[1;9B
Cat meta-right: ^[[1;9C
Cat meta-left: ^[[1;9D
Main problem solved, but I am now having trouble with shift-up. "<select> undefined". I tried a similar mapping with the escape sequence I got from cat: ^[[1;2A. Reluctant to create another question for a similar problem.
Solution 1
Based on the info you provided, here's one thing you can try. You tell emacs to map those escape sequences to the proper key sequences:
(add-hook 'term-setup-hook
(lambda ()
(define-key function-key-map "\e[1;9A" [M-up])
(define-key function-key-map "\e[1;9B" [M-down])
(define-key function-key-map "\e[1;9C" [M-right])
(define-key function-key-map "\e[1;9D" [M-left])))
Solution 2
I also found another possible solution with a little googling: redefine the iTerm bindings instead, to match what emacs is looking for.
http://offbytwo.com/2012/01/15/emacs-plus-paredit-under-terminal.html
Quote from the above page:
Go back to the profile key bindings under iTerm2 and add bindings for the following:
M-up : Esc-[1;4A
M-down : Esc-[1;4B
M-right : Esc-[1;4C
M-left : Esc-[1;4D
I'm answering in reply to your 'main problem solved, but new one' edit.
I found this guy's blog post on this issue:
- http://webframp.com/emacs/2013/02/22/fixing-emacs-bindings-on-the-in-iterm2/
Basically, you can use the 'run cat' and push buttons trick to see what escape codes are getting sent by your system/terminal, then add 'define-key' lines to define M-{up,down,right,left} and also M-S-{up,down,right,left}.

How to bind Emacs key for delete whole word backword as the same in a shell?

I have just started learning Linux and Emacs. It was pleasant to have the same key bindings in both Emacs and a shell (bash/tcsh) for the most frequently used cursor movements, so that I do not have to consciously think which one I have to use. Still worse, use the wrong command and undo the mistake. There were two exceptions, though.
One often used command was the equivalent of backspace, delete a character backwards. In a shell, it was C-h. I got the same behaviour in Emacs, thanks to this tip from Janos, who probably felt the same way.
http://www.math.rutgers.edu/~komlos/emacs.htm
Now the mistake I do often in Emacs is trying to delete words backwards with the command M-C-h, as in a shell.
Can somebody please give a binding that will make Emacs delete words backwards with 'M-C-h'? Currently, this command selects the whole of the text in a buffer, which is quite an useful thing (C-a in windows), but not so frequently used as deleting words backwards.
Moreover, any binding to replace the current binding of M-h (from the link above) to help will be appreciated.
Thank you,
Elan.
Below binds C-M h to backward-kill-word. You can put it in your .emacs file.
(global-set-key (kbd "C-M-h") 'backward-kill-word)
You can use M-<backspace> in terminal and emacs to delete word backward.
It's best to use key translation so C-M-h works exactly the same as M-backspace would in any minor mode (regardless of whether M-backspace is bound to backward-kill-word or not).
;; bind C-h to <backspace>
(define-key key-translation-map [?\C-h] [?\C-?])
;; bind C-M-h to M-<backspace>
(define-key key-translation-map [?\C-\M-h] [?\C-\M-?])

emacs - [control shift up] doesn't work

I tried to define hotkey as following
(global-set-key [(control shift up)] 'other-window)
but it doesn't work (no error, just doesn't work), neither does
(global-set-key [(control shift down)] 'other-window)
But
(global-set-key [(control shift right)] 'other-window)
and
(global-set-key [(control shift left)] 'other-window)
work!
But because the last two key combinations are used by emacs (as default), I don't wanna change them for other functions.
So how could I make control-shift-up and control-shift-down work?
I have googled "(control shift up)", it seems that control-shift-up is used by other people, (but not very few results).
The reason for this is not an Emacs problem, but comes from the fact that your terminal cannot produce a key sequence for C-S-up.
You can verify this very easily. Open a terminal and then type:
Control-v Control-Shift-right
The Control-v part will make the control sequence for the next key be inserted verbatim into your shell. In our case, it will insert the sequence for Control-Shift right, and that'll look something like this:
^[[1;6C
Now, try the same thing for C-S-up:
Control-v Control-Shift-up
You'll see that no control sequence is entered, which hints at the fact that when you press C-S-up in Emacs, it will actually never receive anything, because the terminal is not able to produce anything to pass on to Emacs.
We can double-verify this if you just start a new emacs -nw and type C-h k to invoke Emacs' describe-key function. You'll get asked in the minibuffer to type a key to see what function it is bound to. If you now type C-S-up nothing happens - of course not, since the terminal in which your Emacs runs doesn't produce anything.
However, if you're just looking for an unused key-combination, how about just Shift-up (or even Shift-right) without Control? That one should work both in a terminal emacs and in the windowed version.
Finally, with the help from grawity on superuser.com, I got it working. Please this thread
https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup
This could well be a duplicate of:
Binding M-<up> / M-<down> in emacs 23.1.1
If this is the case, Gilles' answer should sort you out (undoubtedly with different escape sequences, though.)
edit (for better visibility -- see answer below):
It turned out that gnome terminal does not transmit these key combinations, so the solution relies upon the following: https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup

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

basic shortcut (M-del) not working in Emacs and giving erratic behavior

I am using Emacs and most shortcuts work normally, but M-Del for deleting a word backwards produces either an error at the bottom of a `scan' error, and at other times moves the cursor a set of lines below. Any ideas why this may be happening? M-Del works fine for deleting forward words. (** from a comment made below it appear that the command is mapped to a down paragraph lisp function instead of delete a word backwards? How can I reset the mappings to the standard one?)
Best.
writing lisp emacs key binding and cannot specify the <delete> character
has the answer (by Gilles). It looks like there is a bug on some systems due to an overlap with a shell command shadow translating ESC-x to ESC C-d
it can be seen from running
M-x load-library edmacro
M-x edmacro-insert-key M-del
giving ESC C-d
in the folder ~/.emacs.d/ creating a file init.el and inserting
(global-set-key [escape delete] 'backward-kill-word)
this though overrides all uses of ESC from M (meta key) to be translated as escape rendering common M-d, M-w, etc all unseen except for M-del
so the solution is to remap the faulty remapping back to the correct binding.
(global-set-key (kbd "M-C-d") 'backward-kill-word)
Best