emacs-evil / evil-magit

Black magic or evil keys for magit
https://github.com/justbur/evil-magit
GNU General Public License v3.0
273 stars 16 forks source link

Doesn't take any effect #5

Closed justmytwospence closed 8 years ago

justmytwospence commented 8 years ago

This package isn't having any effect on my keybindings. Is it something wrong in my config?

(use-package magit
  :commands
  (magit-blame-mode
   magit-commit
   magit-diff
   magit-log
   magit-status)
  :init
  (with-eval-after-load 'evil-leader
    (evil-leader/set-key
      (kbd "gb") #'magit-blame
      (kbd "gc") #'magit-commit
      (kbd "gd") #'magit-diff
      (kbd "gl") #'magit-log
      (kbd "gr") #'magit-reflog
      (kbd "gs") #'magit-status))
  (with-eval-after-load 'which-key
    (which-key-declare-prefixes
      "<SPC>g" "Git"))
  :config
  (add-hook 'magit-diff-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-log-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-log-select-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-refs-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-revision-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-status-mode-hook #'hl-line-mode)
  (add-hook 'magit-status-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'with-editor-mode-hook 'evil-insert-state)
  (bind-keys
   :map magit-status-mode-map
   ("<C-tab>"   . nil)
   ("<backtab>" . magit-section-cycle))
  (set-face-background 'magit-diff-added-highlight "SeaGreen4")
  (set-face-background 'magit-diff-removed-highlight "IndianRed4")
  (setq magit-completing-read-function 'magit-ido-completing-read)
  (setq magit-push-always-verify nil)
  (use-package magit-gh-pulls
    :config
    (add-hook 'magit-mode-hook #'turn-on-magit-gh-pulls)))

(require 'evil-magit)
justbur commented 8 years ago

Looks like you are loading it too early. You want to load it after magit is loaded. Try this

(use-package magit
  :commands
  (magit-blame-mode
   magit-commit
   magit-diff
   magit-log
   magit-status)
  :init
  (with-eval-after-load 'evil-leader
    (evil-leader/set-key
      (kbd "gb") #'magit-blame
      (kbd "gc") #'magit-commit
      (kbd "gd") #'magit-diff
      (kbd "gl") #'magit-log
      (kbd "gr") #'magit-reflog
      (kbd "gs") #'magit-status))
  (with-eval-after-load 'which-key
    (which-key-declare-prefixes
      "<SPC>g" "Git"))
  :config
  (require 'evil-magit)
  (add-hook 'magit-diff-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-log-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-log-select-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-refs-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-revision-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'magit-status-mode-hook #'hl-line-mode)
  (add-hook 'magit-status-mode-hook (lambda () (setq cursor-type nil)))
  (add-hook 'with-editor-mode-hook 'evil-insert-state)
  (bind-keys
   :map magit-status-mode-map
   ("<C-tab>"   . nil)
   ("<backtab>" . magit-section-cycle))
  (set-face-background 'magit-diff-added-highlight "SeaGreen4")
  (set-face-background 'magit-diff-removed-highlight "IndianRed4")
  (setq magit-completing-read-function 'magit-ido-completing-read)
  (setq magit-push-always-verify nil)
  (use-package magit-gh-pulls
    :config
    (add-hook 'magit-mode-hook #'turn-on-magit-gh-pulls)))
justmytwospence commented 8 years ago

I should have mentioned that your suggestion was actually the first thing I tried. It seems that no matter where I move the require statement, none of the keybindings get overridden.

justbur commented 8 years ago

How are you loading evil?

justmytwospence commented 8 years ago

Ah its probably because I use evil-local-mode and not the global mode.

justbur commented 8 years ago

Could be. This package assumes evil-local-mode is used in magit buffers (and git-rebase-mode ones) On Tue, Nov 10, 2015 at 4:03 PM Spencer Boucher notifications@github.com wrote:

Ah its probably because I use evil-local-mode and not the global mode.

— Reply to this email directly or view it on GitHub https://github.com/justbur/evil-magit/issues/5#issuecomment-155565111.

justmytwospence commented 8 years ago

Yep, this works:

(use-package evil-magit
    :config
    (add-hook 'magit-mode-hook 'evil-local-mode))

Maybe evil-local-mode should be automatically turned on by this package if global evil mode is not on but evil is installed?

justbur commented 8 years ago

Possibly. Certainly worth making a note of it in the readme.

You probably want to use the git-rebase-mode-hook also On Tue, Nov 10, 2015 at 4:45 PM Spencer Boucher notifications@github.com wrote:

Yep, this works:

(use-package evil-magit :config (add-hook 'magit-mode-hook 'evil-local-mode))

Maybe evil-local-mode should be automatically turned on by this package if global evil mode is not on but evil is installed?

— Reply to this email directly or view it on GitHub https://github.com/justbur/evil-magit/issues/5#issuecomment-155576494.

vyp commented 8 years ago

Off topic but use-package now has an after keyword so you don't need nested use-package: https://github.com/jwiegley/use-package/pull/276 (although of course it doesn't make a difference)

justmytwospence commented 8 years ago

Thanks @justbur & @vyp

justbur commented 8 years ago

Added a note to the readme. I might add an option to add the right hooks automatically at some point if it's still something that comes up

Thanks for the report

decoursin commented 8 years ago

I have (evil-mode 1), yet I was having the same problem as @justmytwospence. It didn't work for me until I added:

(add-hook 'magit-mode-hook 'evil-local-mode)
(add-hook 'git-rebase-mode-hook 'evil-local-mode)

Thanks so much!

justbur commented 8 years ago

@decoursin that shouldn't be necessary. What order are you loading evil magit and this package in?

decoursin commented 8 years ago

I confirm that when I comment these lines out, it stops working. Loading goes like this: evil -> (evil-mode 1) -> magit -> evil-magit. Also, I started emacs fresh then eval-ed "(evil-mode 1)", and it still didn't work.

justbur commented 8 years ago

Latest versions of everything? On Sun, Nov 22, 2015 at 7:43 AM Nick DeCoursin notifications@github.com wrote:

I confirm that when I comment these lines out, it stops working. Loading goes like this: evil -> (evil-mode 1) -> magit -> evil-magit. Also, I started emacs fresh then eval-ed "(evil-mode 1)", and it still didn't work.

— Reply to this email directly or view it on GitHub https://github.com/justbur/evil-magit/issues/5#issuecomment-158769596.

decoursin commented 8 years ago

Well, I don't know for sure if I have the latest version of everything but pretty close. I'm on emacs 24.5, I reinstalled all my packages just a couple weeks ago, and I reinstalled magit and evil-magit like just yesterday trying to get this working.

justbur commented 8 years ago

@decoursin so (evil-mode 1) basically just enables evil-local-mode in each buffer. That's why your fix shouldn't be necessary. There could be something in your config that is changing this which may be why it works for you. It's just hard for me to say without more info. What you said of the loading order seems perfectly fine to me. If you enable evil after opening a magit buffer there could be a one time issue, but that's all that comes to mind.

Sorry no back ticks on my phone but this should work after emacs -Q

(require 'evil) (evil-mode 1) (require 'magit) (require 'evil-magit)

Actually the exact position of (evil-mode 1) shouldn't matter as long as it comes before you open a new magit buffer.

decoursin commented 8 years ago

Yeah, that's the order in which I'm loading things. Here, if you want, take a look at my emacs which the latest one that I'm using right now. Honestly, this fix is fine for me because it works, so only delve into my emacs if you wish, as it's kind of messy anyways.

justbur commented 8 years ago

I think I see the problem. You're setting the evil initial state for the magit buffers. Evil-magit picks an initial state too which is motion by default. You can configure this with evil-magit-state. Just be aware that the keybindings here are state dependent so you can either let evil-magit set up the defaults for you or your config needs to be consistent with what evil-magit is doing.

Try letting evil-magit manage the states first and then tweak after that if you need to.

I just flipped through your config but that seems to be the problem. Hope that makes enough sense. On Mon, Nov 23, 2015 at 2:54 PM Nick DeCoursin notifications@github.com wrote:

Yeah, that's the order in which I'm loading things. Here, if you want, take a look at my emacs https://github.com/decoursin/emacs.d which the latest one that I'm using right now. Honestly, this fix is fine for me because it works, so only delve into my emacs if you wish, as it's kind of messy anyways.

— Reply to this email directly or view it on GitHub https://github.com/justbur/evil-magit/issues/5#issuecomment-159093596.

decoursin commented 8 years ago

Hmm I think you were talking about this in my init-evil.el file, which I commented out:

;; (magit-mode . normal)
;; (magit-popup-mode . normal)
;; (magit-branch-manager-mode . emacs)

I also had init-git.el file which referenced magit, and I commented out those lines. Now, pretty much the only references to magit are in init-magit.el. Still not working though.

justbur commented 8 years ago

@decoursin that's what I was referring to yes. if that doesn't work then I don't know what to tell you. My guess is that it's something odd in your config somewhere. If you can give me some Sumple repro steps i can investigate further.