general.el icon indicating copy to clipboard operation
general.el copied to clipboard

How to use custom definer in use-package definition?

Open IllustratedMan-code opened this issue 1 year ago • 3 comments

Say I want to use a custom definer in a :general block like so:

(use-package general
    :config
    (general-create-definer leader :states '(normal) :prefix "SPC"))
  
 (use-package counsel 
    :general (leader "f" 'counsel-find-file))

When I do this, the binding is simply not created. I can however run the leader macro I created in the freshly started emacs.

Am I doing something wrong, or is this not supposed to work?

IllustratedMan-code avatar Jun 01 '23 20:06 IllustratedMan-code

In fact, I can't get any definer to work in any capacity.

This bit of code fails with (invalid-function my-leader-def)

  (use-package general
        :config
        (general-create-definer my-leader-def
        :prefix "C-c")

        (my-leader-def
        "a" 'org-agenda
        "b" 'counsel-bookmark
        "c" 'org-capture))

IllustratedMan-code avatar Jun 01 '23 21:06 IllustratedMan-code

I suspect there is a problem with your use-package config or config elsewhere. Can you provide a minimal init reproduction?

noctuid avatar Jun 01 '23 22:06 noctuid

I think I may have found the issue. It seems to have something to do with the fact that I am using a default.el instead of the normal init directory. I also use nix, so that may be a factor.

You might be able to reproduce with the following default.el

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(eval-when-compile (require 'use-package))
(require 'bind-key)

(use-package general
:ensure t
:config
(general-create-definer leader! :prefix "SPC")
(leader! "a" 'org-agenda))

If I start emacs with no config and M-x load-file RET default.el I can't reproduce this issue. It is only when the default.el is put in the standard search path for libraries in Emacs, see the manual.

If you happen to use nix, my derivation of emacs looks like this:

            (pkgs.emacsWithPackagesFromUsePackage
              {
                package = pkgs.emacsUnstable; #Emacs 29
                config = ./default.el;
                defaultInitFile= true;
                alwaysEnsure = false;
                extraEmacsPackages = epkgs: [
                  epkgs.use-package
                ];
              });

Notably, the :general use-package statement works fine on its own. I can bind keymaps normally. Only when declaring macros do I have trouble.

IllustratedMan-code avatar Jun 02 '23 13:06 IllustratedMan-code

I also just stumbled upon this. I can report to have the exact same issue. Is there any solution to it?

Kintaro avatar Apr 16 '24 02:04 Kintaro

If you are using elpaca see #556. Make sure the general-create-definer/config section is actually running. Really you don't need to put it in the :config section if you're loading general immediately. In any case, I don't think there is any issue with general here

noctuid avatar Apr 16 '24 13:04 noctuid

I also have exactly the same issue, and I'm also using emacs-overlay. @IllustratedMan-code Did you figure out a way to fix this issue?

gustavomedeiross avatar Apr 22 '24 20:04 gustavomedeiross

I did not, though I haven't looked at it in a while. I ended up just working around it by using the normal init directory for emacs

IllustratedMan-code avatar Apr 22 '24 20:04 IllustratedMan-code

Has anyone managed to solve this? I am having the same issue, also on emacs-overlay.

I saw that @gustavomedeiross is using general successfully (?) in their nix and emacs-overlay based emacs configuration here:

config.org emacs.nix

But i can't seem to replicate this, even though i should have a functionally identical setup.

image image

If i put my definer creations into the use-package :config block, they don't work, and the :general and :general-config use-package keywords don't work. Though if i evaluate a use-package block using those keywords at runtime, it works just fine.

If i evaluate use-package blocks using the keywords at runtime, they seem to function.

Edit: probably unrelated, but the diminish package seems to register it's use-package keywords just fine Edit 2: upon further testing, it seems that i am stupid, and specifically general-create-definer is broken, the :general keyword works emacs-lisp-macroexpanding the general-create-definer macro doesn't work either

Workaround for anyone that comes across this thread, instead of using definers, just use whatever your definer settings would be in the use-package keywords, e.g.

(use-package magit
  :general
  (:states '(normal visual) :prefix "SPC" :keymaps 'override
    "gg" 'magit-status))

thundertheidiot avatar Aug 10 '24 15:08 thundertheidiot

specifically general-create-definer is broken

I don't think so. That :after (evil which-key) is not recommended and is likely the issue if you are not loading evil/which-key immediately, and if you are, it's pointless. If that's not the issue, please open a new issue with a minimal config to reproduce.

noctuid avatar Aug 11 '24 12:08 noctuid

Apologies for that, this definition was pasted from my original config, and that was stolen from somewhere else, but i am pretty sure that i didn't do that when i tested this with a very minimal config, i'll retest that tomorrlw though, just in case i was being an idiot. Also evil and which-key have :demand t, so they should be loaded.

thundertheidiot avatar Aug 11 '24 18:08 thundertheidiot