I 've a unix keyboard on a FreeBSD 12 work station with 10 special keys.
Stop Again
Props Undo
Front Copy
Open Paste
Find Cut
and try to use them for short-cuts under Emacs 26.3 in graphics mode. Some of the key symbol names are mapped via the X11 driver to XF86-Key names like:
Copy - XF86Copy
Cut - XF86Cut
Paste - XF86Paste
and some of the key symbol names remain in the Sun-Key namespace like:
Props - SunProps
Front - SunFront
Open - SunOpen.
I want to use the SunFront key, to call some menu items under Emacs but get a strange result for the extended version of such a sequence. The both key binding definitions
(global-set-key [SunFront] 'buffer-menu-open)
(global-set-key [(control SunFront)] 'buffer-menu-open)
are working well and open the buffer menue. But if I try to extend the sequence:
(global-set-key [(control SunFront) (control b)] 'buffer-menu-open)
I got the error
global-set-key: Key sequence <C-SunFront> C-b starts with non-prefix key <C-SunFront>
. On the other hand the sequence:
(global-set-key [(control XF86Copy) (control b)] 'buffer-menu-open)
works well and opens the expected menu. What is the right way to define the emacs key sequence for the SunFront setup?
The error you get is because you already bound (in that same keymap) [(control SunFront)] to a command, so the new define-key would overwrite that definition.
You can eliminate the error by explicitly overwriting the old def before adding the new one:
(global-set-key [(control SunFront)] nil)
(global-set-key [(control SunFront) (control b)] 'buffer-menu-open)
But most likely all you need to do is to remove the previous binding instead.
Related
I’m on a Mac and would like to use the function key F19 as meta.
(There’s a good reason, although it's a bit of a hack: My built (the otherwise excellent port by Yamamoto Mitsuharu) doesn’t support using only the left alt key as meta while preserving the native behavior (inserting special characters) of the right alt key.. So I remapped the left alt key to an unused key - F19 - on the system level with PCKeyboardHack (xmodmap is sorely missed) and would like to tell Emacs to use that as meta.)
So, how do I: use a function key (F19 in my case) as meta key in Emacs?
(I’m fairly new to Emacs and, after some googling, tried out something like
(define-key global-map [f19] \M)
but that, of course, doesn’t do the trick (Symbol’s value as variable is void: M)
Well, with
(setq x-alt-keysym symbol)
you can tell emacs what key is to be understood as meta, but afaik it only accepts 'meta, 'alt, 'super and 'hyper as symbol. Maybe try it with f19.
An alternative option that will work but which will require adaption to a new way of working would be to use F19 as a prefix key (like you use C-h or F1 to invoke help commands):
(define-prefix-command 'f19-map)
(global-set-key (kbd "<f19>") 'f19-map)
(global-set-key (kbd "<f19> x") 'execute-extended-command)
(global-set-key (kbd "<f19> u") 'upcase-word)
...
Writing the configuration shouldn't be too hard. Just press C-h b to get all existing keybindings and edit the help buffer. Get rid of all lines that don't start with M-, then use rectangles to replace all occurrences of ^M- by (global-set-key (kbd ", and so on.
Yet another option would be to bind the key to Esc instead of F19, as long as that's supported by your system, and use the esc prefix instead of the f19 prefix. That way you don't have to change the emacs configuration at all.
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.
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.
I'd like to redefine some of the default aquamacs shortcuts.
I've tried putting this in my preferences.el file:
(global-unset-key (kbd "A-l"))
(global-set-key (kbd "A-l") 'forward char)
but it doesn't change the behavior of CMD-l
check the key descriptor as JF Sebastian said. But there is another typo in what you have written, it should be something like:
(global-set-key [(meta l)] 'forward-char)
(I am using meta, but by default aquamacs doesn't seem to have command has meta, not sure what it is)
You can check to what the key is mapped by typing:
c-h c
and then the key combination you want to check. It will tell you in the minibuffer. You can thus check if your binding worked fine without restarting etc.
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)