I cannot reproduce the exact behavior as C-HOME that you experience. For me it translates to M-[ 1 ;
, without the 5H
(but that is actually inserted...).
But, given that, here's how I would set up the binding.
I'd go into the *scratch*
buffer and type
(read-key-sequence "please type C-home ")
C-j
Which will prompt you for a key sequence, so do C-HOME and Emacs should insert the following right after the read-key-sequence
line:
"^[[1;"
5H
5H
Using the string, I'd set up the binding in my .emacs like so:
(global-set-key "^[[1;" 'beginning-of-buffer)
This will define the key binding appropriately, except that (for me) it now inserts 5H
at the top of the buffer. I believe the 5H
is a product of screen somehow...
Updated to add:
The 5H
annoys me, but as far as I can tell, Emacs thinks we are literally typing it. So, I coded up two alternatives which result in the same behavior.
The first uses keyboard-quit
to interrupt the key sequence after getting to the beginning of the buffer. This prevents the 5H
from being inserted. But it has the downside of doing a keyboard-quit
- which will flash/ding at you ever time. Kind of annoying.
(global-set-key "^[[1;" 'my-bob)
(defun my-bob ()
"Go to beginning of buffer, then quit"
(interactive)
(beginning-of-buffer)
(keyboard-quit))
To avoid the keyboard-quit
, I wrote a different version which runs a little snippet of code which deletes the 5H
if it exists. It's a little more involved, but does the job.
(global-set-key "^[[1;" 'my-bob)
(defun my-bob ()
"Go to beginning of buffer, then delete any 5H inserted by the binding"
(interactive)
(beginning-of-buffer)
(run-with-idle-timer 0.1 nil 'delete-inserted-chars "5H"))
(defun delete-inserted-chars (chars)
(save-excursion
(backward-char (length chars))
(if (looking-at (regexp-quote chars))
(delete-char (length chars)))))
The delete-inserted-chars
can be reused for other bindings in screen which happen to insert characters as well.
beginning-of-buffer
withC-h k
followed byM-<
. You are entering it correctly – RorschachM-x emacs-version
– lawlistCtrl+Home
does work now - no idea why it did not before. I do not know how to typeM-<
:Alt+Shift+,
successfully. It results inM-,
when I try. I am only using emacs in a terminal. – npit