Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

god-mode does not work with "un-initialized" projectile-mode-map #156

Open
dadinn opened this issue Apr 26, 2023 · 17 comments
Open

god-mode does not work with "un-initialized" projectile-mode-map #156

dadinn opened this issue Apr 26, 2023 · 17 comments

Comments

@dadinn
Copy link

dadinn commented Apr 26, 2023

Until projectile-mode-map prefix binding (e.g. C-c p p) has been called manually (i.e. without god-mode) at least once, the calling the enhanced binding with god-mode enabled (i.e. c SPC p p) does not work.

Once the prefix binding has been entered manually (without using god-mode) at least once, then calling it from god-mode with the enhanced binding starts to work too.

Choosing and executing one of the subcommands in the projectile-mode-map is not even necessary, it is enough to just enter the prefix binding (e.g. C-c p p) and then terminate the minibuffer with C-g.

@dadinn
Copy link
Author

dadinn commented Apr 26, 2023

This supersedes issue #155 I've opened/closed before.

@darth10
Copy link
Collaborator

darth10 commented Apr 26, 2023

It depends on how you initialise God mode.
As mentioned in the README, calling the god-mode function only affects future buffers.
To change both active and future buffers, you should call god-mode-all instead on loading your emacs configuration.

@dadinn
Copy link
Author

dadinn commented Apr 27, 2023

I do use god-mode-all, with the binding set.

The issue happens once Emacs is initialised, then I turn god-mode on using the binding.
After this the indicators show that god-mode is turned on, yet c SPC p p does not do anything.

Interestingly, if I add god-mode-all to the emacs-init-hook, god-mode does not get turned on after initialised.

@darth10
Copy link
Collaborator

darth10 commented Apr 27, 2023

Sorry, I can't seem to recreate this, although I'm using after-init-hook.

Calling god-mode-all through after-init-hook, or through doom-after-modules-config-hook if you're using Doom Emacs, works fine.
I can use the c SPC p prefix to call any projectile functions as soon as my Emacs starts up.

Would it be possible to share your Emacs config?
I can't find anything related to God mode in your .emacs.d repository.

@dadinn
Copy link
Author

dadinn commented May 1, 2023

Apologies, realised my github didn't contain the config I was working with.

Here is the version which reproduces the problem for me. The god-mode version in my config uses the latest commit 607aff1.

Also, I've disabled doom-modeline, but the problem still remains.

Since I am not using Doom Emacs, only the individual doom-modeline package, I don't have a doom-after-modules-config-hook.

Regarding the after-init-hook problem: I've accidentally added the -hook suffix in my use-package declaration. After fixing it, god-mode is indeed enabled on startup. Yet, this doesn't resolve the problem with the projectile key-map binding.

@dadinn
Copy link
Author

dadinn commented May 1, 2023

Actually, I've encountered another issue.

For some reason enabling god-mode on startup using the after-init-hook, causes the god-mode-enable-function-key-interaction to be ignored. Even though I've set it to be nil, when I try to press F11 after startup, I get the message: God: Unknown key binding for ‘C-<f11>‘.

The behaviour is present in my earlier config.
If I remove god-mode from the after-init-hook, then F11 works fine.

@darth10
Copy link
Collaborator

darth10 commented May 1, 2023

or some reason enabling god-mode on startup using the after-init-hook, causes the god-mode-enable-function-key-interaction to be ignored. Even though I've set it to be nil, when I try to press F11 after startup, I get the message: God: Unknown key binding for ‘C-<f11>‘.

Just had a quick look, and it looks like you're setting god-mode-enable-function-key-interaction too late.
Try setting it in the :init part of use-package, instead of in :custom.

I've not yet investigated the issue with projectile and God mode.
I'll get to that soon, but if you find anything, please post on this issue.

@dadinn
Copy link
Author

dadinn commented May 8, 2023

I've also tried using emacs-startup-hook instead of after-init-hook, which claims to be run later, and starts god-mode correctly, yet still captures the F11 key.

When I don't automatically start god-mode with either of the hooks, then setting god-mode-enable-function-key-interaction using :custom works fine, and F11 key registers correctly.

@dadinn
Copy link
Author

dadinn commented May 26, 2023

Uh, oh... just noticed somehow I've been using the wrong name for the function-key option!
It is named god-mode-enable-function-key-translation, not -interaction.

It seems I didn't notice the issue, because I usually press F11 as the first thing on my Emacs startup, and since I used the wrong hook, god-mode didn't get enabled on initialization... so F11 was working fine. But when I manually started god-mode afterwards, it turned out that function key translation wasn't disabled (because I was setting the wrong variable).

Sorry, my bad!

@darth10
Copy link
Collaborator

darth10 commented May 26, 2023

Not a problem.
So the F11 issue is not a bug, but you're still having a problem calling projectile functions on start-up from what I understand?

@dadinn
Copy link
Author

dadinn commented May 26, 2023

Yes, indeed. The issue with initializing projectile key-binding still exists.

@darth10
Copy link
Collaborator

darth10 commented May 26, 2023

Okay, looking at your config, it's because projectile key bindings aren't exposed through your package configuration that uses :bind-keymap.
Can you try this config for projectile and let me know if you're still having the issue?

(use-package projectile
  :hook
  (projectile-grep-finished . (lambda () (pop-to-buffer next-error-last-buffer)))
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :init 
  (require 'projectile)
  :config
  (dolist (dir (list "node_modules" "target"))
    (add-to-list 'projectile-globally-ignored-directories dir))
  (projectile-mode))

This is sort of what Doom Emacs does too.

@dadinn
Copy link
Author

dadinn commented May 26, 2023

I don't understand. My config is exactly the same as what you wrote.

@darth10
Copy link
Collaborator

darth10 commented May 26, 2023

Haha not exactly.
There's a call to (require 'projectile) you're missing.
I copied your config and added these lines:

(use-package projectile
  :hook
  (projectile-grep-finished . (lambda () (pop-to-buffer next-error-last-buffer)))
  :bind-keymap
  ("C-c p" . projectile-command-map)
+  :init 
+  (require 'projectile)
  :config
  (dolist (dir (list "node_modules" "target"))
    (add-to-list 'projectile-globally-ignored-directories dir))
  (projectile-mode))

@dadinn
Copy link
Author

dadinn commented Jun 9, 2023

Adding the :init (require 'projectile) doesn't seem to solve the issue for me.

@dadinn
Copy link
Author

dadinn commented Jun 9, 2023

This seems to have solved it though:

(use-package projectile
  :demand t
  :hook
  (projectile-grep-finished . (lambda () (pop-to-buffer next-error-last-buffer)))
  :bind
  ("C-c p" . projectile-command-map)
  :config
  (dolist (dir (list "node_modules" "target"))
    (add-to-list 'projectile-globally-ignored-directories dir))
  (projectile-mode))

The difference is that I've used :bind instead of :bind-keymap, and added the :demand t.
Not sure I understand what benefit :bind-keymap gives over plain :blind, but it seems the fact that it tries to do funny things, with loading the keymap and then using the binding again as prefix argument, could interfere with god-mode? At any rate, with :bind the behaviour is more straightforward, such that the :demand flag can circumvent the delayed loading.

...not sure how you've added those nice highlights on your code examples though! ;)

dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 9, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 10, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
@dadinn dadinn closed this as completed Jun 10, 2023
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 10, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
@dadinn
Copy link
Author

dadinn commented Jun 10, 2023

Still, it might worth looking into why god-mode does not work well with use-package's :bind-keymap option.

@dadinn dadinn reopened this Jun 10, 2023
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 13, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 13, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 16, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 24, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jun 28, 2023
This is to solve interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Jul 13, 2023
This also resolves interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Aug 27, 2023
This also resolves interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Sep 29, 2023
This also resolves interoperability issue with god-mode:
emacsorphanage/god-mode#156
dadinn pushed a commit to dadinn/.emacs.d that referenced this issue Nov 24, 2023
This also resolves interoperability issue with god-mode:
emacsorphanage/god-mode#156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants