reddit / emacs

I broke my SPC key

Empik002 · 2022-06-13 23:19
Today I downloaded Doom Emacs and wanted to change a few key-binds but somehow i managed to break my SPC. Everything now says it is undefined. Could you please help me fix it? (i tried commenting out all my changed configs but id didn't work)
gravygrowinggreen · 2022-06-13 23:35
How did you try to change the bindings?
Empik002 · 2022-06-13 23:40
Well more ways, but the last thing i did (and after that it broke) was this in my .doom.d/config.el (also yes i want arrowkeys for moving in my splits i like it more that way) `(define-key key-translation-map (kbd "C-w <left>") (kbd "SPC w h"))` `(define-key key-translation-map (kbd "C-w <right>") (kbd "SPC w l"))` `(define-key key-translation-map (kbd "C-w <up>") (kbd "SPC w k"))` `(define-key key-translation-map (kbd "C-w <down>") (kbd "SPC w j"))` `(define-key key-translation-map (kbd "C-w x") (kbd "SPC o p"))`
gravygrowinggreen · 2022-06-14 00:05
That's a legacy function, and iirc not recommended for use anymore. I'm not sure about normal emacs, but in doom emacs, it also has advice that unbinds the keys you're using before it binds them. which might have unbound spc from being the doom leader key, leaving you with just the last spc binding. delete those lines, then type the following without quotes ":doom/reload", then press enter. That should get you back to normal. then rebind your commands with a better, more up-to-date macro. use the map! macro. for documentation, use SPC h f.
Empik002 · 2022-06-14 00:09
I deleted it but unfortunately reloading it didnt set the SPC key to the doom leader key
gravygrowinggreen · 2022-06-14 00:14
Have you tried a full restart of emacs (including killing any server being run)? Restarting with a config that's free of any of your bindings using the define-key macro is probably your best bet. The config files doom boots from (which you don't edit, the ones in emacs.d, not the ones in doom.d). should reload space as the doom leader key. They're run on every start-up of doom, load the default settings, then refer emacs to your private config to use.
Empik002 · 2022-06-14 00:21
I tried to even restart the whole pc. I didnt change anything in the .emacs.d folder. I will try to just uninstall emacs and delete both .emacs and .doom folders and try installing fresh. Thanks anyways, especially for the map! macro suggestion.
AdjectivePronoun · 2022-06-14 00:32
Use the `map! :leader` command. [Here’s an example I found on a blog](https://www.dschapman.com/notes/bde6e938-0984-4d60-974d-77178f1ecd9b).
Empik002 · 2022-06-14 00:50
Thank you! I managed to map SPC <left> (and the rest) to do the split moving. but how would I do that to Control-W <left>? EDIT: Figured it out! its: `(map! :g "C-w <left>" 'evil-window-left)` Hopefully nothing will break because of the global mapping
AdjectivePronoun · 2022-06-14 01:03
Sweet! Glad you got it
Empik002 · 2022-06-14 01:11
Huh, emacs is funny... Just now everything worked perfectly but when I restarted the daemon just to check everything is fine it started complaining that `error Key sequence C-w <left> starts with non-prefix key C-w` But when i then do `SPC h r r` to reload it actually binds those keys correctly
AdjectivePronoun · 2022-06-14 01:23
It must be because `C-w` is reserved. Digging deeper I found the relevant code: ```emacs-lisp ;; Defined in ~/.emacs.d/.local/straight/repos/general.el/general.el ;;;###autoload (defun general-auto-unbind-keys (&optional undo) "Advise `define-key' to automatically unbind keys when necessary. This will prevent errors when a sub-sequence of a key is already bound (e.g. the user attempts to bind \"SPC a\" when \"SPC\" is bound, resulting in a \"Key sequnce starts with non-prefix key\" error). When UNDO is non-nil, remove advice." ```
Empik002 · 2022-06-14 01:26
Yeah just found out from some searching that Keys like C-w and M-x and such are not usable for custom keybinds which sucks, as I am quite used to C-w arrow-keys, guess I will finally have to get used to using hjkl for navigation (or SPC arrowkeys) .
pushqrex · 2022-06-14 17:33
Idk why but all I thought about was you actually breaking your space by furiously smashing it
Empik002 · 2022-06-14 18:54
Imagine if this was just a rant about how emacs is difficult lol