2 years ago

#22720

test-img

zynkd

Doom Emacs: Key binding SPC-SPC for easy file navigation

For a couple of days, I've been trying to bind SPC SPC (now find-file or project-find-file) to a bottom popup that would display easy navigation to my files.

Possible solution - method 1 (modifying the below code snippet):

Here's the simple popup code (works perfectly and gets activated upon SPC e)

    (map! :leader
          (:prefix ("e" . "open config files")
           :desc "alacritty.yml" "a" #'(lambda () (interactive) (find-file "~/.config/alacritty/alacritty.yml"))
           :desc "nvim" "n" #'(lambda () (interactive) (find-file "~/.config/nvim/init.vim"))
           :desc "polybar" "p" #'(lambda () (interactive) (find-file "~/.config/polybar/config")))

But I'd like to use SPC SPC instead of SPC e. When I change :prefix from e to SPC, I get this error:

Key sequence SPC starts with non-prefix key SPC.

How can I bind SPC SPC to a similar navigation (i.e. the above "open config files" menu activated with "SPC e"?

Possible solution - method 2 (creating custom function):

I suspect that what I want could also be done by the (custom) functioin. I managed to get SPC SPC to invoke my-own-nav-function (see the code below), but I could not make it work. This is how I trigger the function (upon hitting "SPC SPC", the code triggers my-own-nav-function as expected):

    (map! :leader
          :desc "navigation function" "SPC" #'my-own-nav-function)

The function that I tried to create is this:

(defun my-own-nav-function ()
(interactive)
:desc "alacritty.yml" "a" #'(lambda () (interactive) (find-file "~/.config/alacritty/alacritty.yml"))
:desc "nvim" "n" #'(lambda () (interactive) (find-file "~/.config/nvim/init.vim"))
:desc "polybar" "p" #'(lambda () (interactive) (find-file "~/.config/polybar/config")))

I can navigate to this function via M-x and execute it, but it doesn't seem to be doing anything. If I could get that function work, it would solve my problem.


Note: I'm running Doom Emacs on Linux (GNU Emacs 27.2)

emacs

key-bindings

emacs

key-bindings

0 Answers

Your Answer

Accepted video resources