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.

4 comentarios:

  1. Here's some code you might find helpful:

    (use-package git-gutter-fringe
    :config

    (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))

    ResponderEliminar
  2. 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.

    ResponderEliminar
  3. I added this one to avoid the confirmation of "are you sure you want to stage this hunk?", which you usually are.

    ("S" (lambda () (interactive) (let ((git-gutter:ask-p nil)) (git-gutter:stage-hunk))))

    ResponderEliminar
  4. You made some decent factors there. I seemed on the internet for the difficulty and found most people will associate with along with your website. online casino games

    ResponderEliminar