unable to set keymap for key Ctrl-; - emacs

I am trying to set the global key for the C-; key by placing the below code in init.el file.
(global-set-key "\C-;" 'backward-kill-word)
But this gives the following error in the *Warning* buffer
error "Invalid modifier in string"

try this,
(global-set-key [(control ?\;)] 'backward-kill-word)
another way and I guess most easiest way of doing is with kbd function
(global-set-key (kbd "C-;") 'backward-kill-word)

Related

How do you set a key with both cmd and ctrl in Emacs.app?

(global-set-key (kbd "C-s-f") 'emmet-next-edit-point)
When I hit C-s-f, I get the error <C-s-268632070> is undefined.
(global-set-key (kbd "C-s-268632070") 'emmet-next-edit-point)
When I evaluate, I get the error C-s- must prefix a single character, not 268632070
Emacs 24.2.1, latest OS X.
Place numerical key in angle brackets:
(global-set-key (kbd "<C-s-268632070>") 'emmet-next-edit-point)

bind 'indent-to-column' to C-tab

I'm trying to bind indent-to-column 100 to C-TAB (or even just indent-to-column so I could then enter the column number I want), but what I tried isn't working:
This gives me an error when I open emacs:
(global-set-key (kbd "<C-tab>") 'indent-to-column 100)
This seems to have no effect:
(global-set-key (kbd "<C-tab>") 'indent-to-column)
What am I doing wrong?
Your second expression should work (in that it should bind indent-to-column to C-TAB, but you still have to provide the argument). You can check this using the following key sequence to see what C-TAB is bound to:
C-hkC-TAB
If you want to provide the argument as well, you can use this kind of construct:
(global-set-key (kbd "<C-tab>")
(lambda ()
(interactive)
(indent-to-column 100)))
Try this:
(global-set-key [(control tab)] 'indent-to-column)

How can i bind C-x-insert in emacs

I want to bind C-x-insert to a command. This works:
(global-set-key [\C-insert] 'my-func)
But this doesn't:
(global-set-key [\C-x-insert] 'my-func)
C-hcC-xinsert tells me
C-x <insert> is undefined
Which tells me how Emacs refers to that sequence, which in turn means that I can pass the string "C-x <insert>" into the kbd function, and it will Just Work.
(global-set-key (kbd "C-x <insert>") 'my-func)
kbd is your friend.
This seems to work:
(define-key ctl-x-map [insert] 'beginning-of-line)

Defining key binding with arguments

I want to map C-f C-b as moving forward and backward by a fixed amount of lines in a file.
I did this:
(global-set-key (kbd "C-f") 'next-line)
(global-set-key (kbd "C-b") 'previous-line)
but I don't know how to specify an argument before the next-line command. I guess I should use digit-argument but I am unable to write the command in a correct way.
You've changed your question to be about how to bind directly to key sequences
This binds C-c l to C-u 5 C-n
(global-set-key (kbd "C-c l") (kbd "C-u 5 C-n"))
One of the possible alternatives would be define a new function:
(defun my-next-line ()
(interactive)
(next-line 5))
(global-set-key (kbd "C-f") 'my-next-line)
Otherwise, if it is just something you can accomplish with the keyboard you might want to use
M-x name-last-kbd-macro
and save it in your .emacs file
M-x insert-kbd-macro
and have emacs implement the function for you.
It will just get the name you gave in your call to name-last-kbd-macro

Emacs: why does keybinding with M-S-[letter] set mark?

I'm experimenting with new bindings for basic movement in Emacs. Borrowing from this page and ErgoEmacs, this remapping works as expected:
(global-set-key (kbd "M-i") 'previous-line)
(global-set-key (kbd "M-k") 'next-line)
(global-set-key (kbd "M-j") 'backward-char)
(global-set-key (kbd "M-l") 'forward-char)
But defining a Shift-Alt combination gives an unwanted side-effect.
(global-set-key (kbd "M-I") 'cua-scroll-down)
(global-set-key (kbd "M-K") 'cua-scroll-up)
(global-set-key (kbd "M-J") 'backward-word)
(global-set-key (kbd "M-L") 'forward-word)
Running describe-key (C-h k) shows that the bindings were successful. And these bindings move point as they should, but for some reason it sets the mark at my original position, and gives me a highlighted region as I move the point.
How do I correct this?
EDIT:
This has something to do with cua-mode. When I disable cua-mode, the problem disappears. Unfortunately, disabling cua-mode is not a desirable solution.
EDIT:
This is a bug in Emacs. It's tracked as bug#11221, title 'cua-mode activates the mark for shifted bindings'. From the discussion on the mailing list, it sounds like there will be a fix to cua-base.el.
It's indeed likely triggered by shift-select-mode, but it looks like a bug: shift-select-mode should pay attention to the fact that the command is bound to a shifted key. Try to reproduce the problem without using CUA and then please report it with M-x report-emacs-bug.
That's because of the shift selection. You can disable it by setting shift-select-mode to nil.