jueves, 11 de octubre de 2018

staging hunks without magit

So there's magit that allows you to stage hunks as if you were doing "git add -p".  And I love it, but sometimes magit feels like too much, and it's slower than using vc.

I've been using git-gutter for some time, and I think there's a nice potential for staging hunks with it.

(use-package git-gutter
  :ensure t
  :config (global-git-gutter-mode t)
  :bind ("C-x v s" .  git-gutter:stage-hunk)
  ("C-x v n" .  git-gutter:next-hunk)
  ("C-x v p" .  git-gutter:previous-hunk))

With these configs (I'm using use-package), you can navigate through hunks with c-x v n/p (I'm basing the keybinds on vc "c-x v" ones) and stage them with "c-x v s". 

I'm pretty happy with those, only missing the ability of staging several hunks at once within a region.

2 comentarios:

alphapapa dijo...

Here's some code you might find helpful:

(use-package git-gutter-fringe

(defhydra hydra:git-gutter (:pre (git-gutter-mode 1)
:hint nil)
^File^ ^Hunk^ ^Repo^
_c_ommit _n_ext _P_ush
_d_iff _p_rev
^ ^ _s_tage
("c" magit-commit :exit nil)
("d" magit-diff-buffer-file)
("n" git-gutter:next-hunk)
("p" git-gutter:previous-hunk)
("P" magit-push-implicitly)
("s" git-gutter:stage-hunk)
("q" nil "quit"))

(general-def :prefix "M-SPC"
"gd" 'magit-diff-buffer-file
"gg" 'hydra:git-gutter/body
"ghn" 'git-gutter:next-hunk
"ghp" 'git-gutter:previous-hunk))

Raimon Grau dijo...

Thanks! I'll definitely try those.

I'm a bit more oldschool emacs in general (no hydra, no general.el), but this might be a good opportunity to delve into those "modern" things.