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

Deferring evil-magit with use-package doesn't seem to work in strange cases #28

Closed jojojames closed 7 years ago

jojojames commented 7 years ago

Keybinds don't seem to work if I defer ag for some reason..

Evil is not deferred. (evil-mode 1)

;; Leaving it like this works.
(use-package ag
  :ensure t
  :config
  (add-to-list 'ag-arguments "-U") ;; ignore .ignore files by default
  (setq ag-highlight-search t)
  (setq ag-reuse-buffers t))

But this causes binds to break

(use-package ag
  :ensure t
  :commands (ag ag-project)
  :config
  (add-to-list 'ag-arguments "-U") ;; ignore .ignore files by default
  (setq ag-highlight-search t)
  (setq ag-reuse-buffers t))

;; C-h k r in git-status
r runs the command dired-do-redisplay, which is an interactive
autoloaded compiled Lisp function in ‘dired-aux.el’.

It is bound to r, <normal-state> r.

(dired-do-redisplay &optional ARG TEST-FOR-SUBDIR)

But then, it doesn't seem like AG is a problem (something it does side-effects and makes everything work though).

I comment out the entire ag use-package snippet, and it still fails. (evil-magit commands aren't bound)

(defmacro after-evil (&rest body)
  `(eval-after-load "evil"
     (lambda ()
       ,@body)))

(use-package magit
  :ensure t
  :commands (magit-toplevel magit-status magit-blame magit-log)
  :config
  (after-evil
   (evil-define-key 'normal magit-log-mode-map
     (kbd "`") 'magit-process-buffer
     (kbd "~") 'magit-diff-default-context
     (kbd "0") 'evil-digit-argument-or-evil-beginning-of-line
     (kbd "$") 'evil-end-of-line)
   (evil-define-key 'normal magit-status-mode-map
     (kbd "q") 'quit-window
     (kbd "`") 'magit-process-buffer
     (kbd "~") 'magit-diff-default-context
     (kbd "0") 'evil-digit-argument-or-evil-beginning-of-line
     (kbd "$") 'evil-end-of-line
     (kbd "Q") 'delete-window)
   (evil-define-key 'normal magit-repolist-mode-map
     (kbd "q") 'quit-window
     (kbd "Q") 'delete-window
     (kbd "RET") 'magit-repolist-status
     (kbd "gr") 'magit-list-repositories))

  (setq magit-repository-directories '("~/Developer"
                                       "~/Code"
                                       "~/.emacs.d"
                                       "~/.vim"
                                       "~/.dotfiles"
                                       "~/.zsh"))
  (setq magit-refresh-status-buffer nil)
  (setq magit-completing-read-function 'ivy-completing-read)
  (setq vc-handled-backends (delq 'Git vc-handled-backends))

  (defadvice magit-show-commit (around dont-select-commit-window activate)
    "magit-show-commit selects the window it opens unless magit-display-buffer-noselect is set.
Setting magit-display-buffer-noselect changes the selection logic for other parts of magit though.
Instead, advise magit-show-commit by setting magit-show-commit to t
before calling magit-show-commit and set it back to nil afterwards."
    (setq magit-display-buffer-noselect t)
    (setq ad-return-value ad-do-it)
    (setq magit-display-buffer-noselect nil))

  ;; https://github.com/magit/magit/issues/2541 (tweaked)
  ;; single window or special magit modes -> open in other window
  (setq magit-display-buffer-function
        (lambda (buffer)
          (display-buffer
           buffer
           (cond
            ((eq (count-windows) 1)
             nil)
            ((and (derived-mode-p 'magit-mode)
                  (eq (with-current-buffer buffer major-mode)
                      'magit-status-mode))
             nil)
            ((memq (with-current-buffer buffer major-mode)
                   '(magit-process-mode
                     magit-revision-mode
                     magit-diff-mode
                     magit-stash-mode))
             nil)
            (t
             '(display-buffer-same-window))))))

  ;; Add rebase argument to pull
  ;; https://github.com/magit/magit/issues/2597
  (magit-define-popup-switch 'magit-pull-popup ?R "Rebase" "--rebase"))

Tried various things,

;; This does not work if ag is deferred or commented out.
(use-package evil-magit
  :ensure t
  :after magit
  :init
  (setq evil-magit-want-horizontal-movement t))

;; This does work but it also auto-loads magit and evil..
(use-package evil-magit
  :ensure t
  :init
  (setq evil-magit-want-horizontal-movement t))

;; This doesn't seem to work.
(use-package magit
  :commands (random commands to defer magit)
  :config
  (after-evil
   (use-package evil-magit
     :ensure t
     :init
     (setq evil-magit-want-horizontal-movement t))))

I'm heaving ag in for now but it's definitely a little messy. Thanks for any help.

justbur commented 7 years ago

I'm having trouble figuring out what to test to reproduce this. Can you put up a minimal example that causes a problem?

jojojames commented 7 years ago

Sure, will do as time allows.

jojojames commented 7 years ago

Hmnn, gave a shot at trying to repro this. In a bare config, it seems to work properly but testing against my config (randomly commenting stuff out and back in) seems to cause the functionality to go in and out.

Oh well.