Prevent magit`:` from switching to another window
Asked Answered
K

3

10

After several hours of using git in the shell, I switched to magit.

It's pretty neat and efficient: I don't need to type "git" to invoke a git command anymore!

But I still found one drawback comparing to the shell command line.

Every time I typed : to invoke a git command, the output popped out in the other window. I had to type C-x o to switch back then type the git command again.

Is there a better way to keep typing and watching on the output at the same time other than shell-mode in Emacs?

Should I rebind the output to some other mode? Which one? or a more elegant solution?

Kwang answered 15/4, 2011 at 12:49 Comment(0)
X
6

I agree with Brian, what are you trying to do that magit can't do via a simple key trigger? There's probably a key-binding for it already. If not I just C-z to drop to shell and run the command, then type fg to bring emacs back in foreground.

Edit: My flow goes like this.

  1. I start the day at work. I type git diff in command line just to see if I have any uncommitted changes from the previous day (don't forget to enabled colors!) The reason I do this in command line as apposed to magit is because I'm not in emacs yet.
  2. I either open the uncomitted files in emacs emacs file1 file2 or I open some files I'm about to work on.
  3. I code until I've fixed a bug or finished a new feature.
  4. In emacs I type C-c i to open up the Magit status window.
  5. I scroll down to the Changes section and next to each file press tab to see a diff of each changes. I either press s to stage those changes or u to unstage those changes.
  6. Optionally, I can look through diffs code and do the same s and u to stage and unstage sections of the code. Useful if I had some debug code somewhere and want to kill it.
  7. After I've confirmed all my changes look good and are staged I type c to open the magit-edit-log. I type my commit message and then type C-c C-c to commit it. Then P to push it. Done!

Note that this sounds like a lot of steps but it becomes quickly natural and the whole process literally takes 30 seconds for me to diff my entire set of changes, stage them, and commit them with a message. All while staying in Emacs. So much easier than dropping down to command line.

Sometimes an error is returned when I do a push via Magit usually caused by new code in the remote repo that I have to pull before I push. In this case F to pull changes then P again to push. Honestly for some reason, instead of pulling through magit, I generally just Ctrl-z in this situation, drop down to shell, git pull, and git push.

Edit: I think I remember Magit's default diff colors being pretty atrocious. I use the following in my .emacs I'm sure I stole from somewhere:

;; change magit diff colors                                                                                                                                                                                 
(eval-after-load 'magit                                                                                                                                                                                     
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'magit-diff-add "green3")                                                                                                                                                         
     (set-face-foreground 'magit-diff-del "red3")                                                                                                                                                           
     (when (not window-system)                                                                                                                                                                              
       (set-face-background 'magit-item-highlight "black"))))                                                                                                                                               

(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode))                                                                                                                                             
(eval-after-load 'diff-mode                                                                                                                                                                                 
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'diff-added "green4")                                                                                                                                                             
     (set-face-foreground 'diff-removed "red3")))
Xylotomous answered 1/5, 2011 at 8:8 Comment(0)
R
2

I usually use Magit's built in commands for most of my work when I'm using Magit, and just use a regular terminal when I need to do things that I can't do from Magit's built in commands. Magit has built in commands for almost all of my day to day usage; what are you using regularly that Magit doesn't supply and you wouldn't be doing in a full-fledged terminal anyhow?

Reactance answered 15/4, 2011 at 15:30 Comment(1)
Sigh, I think it's because Magit is so great that I don't wanna go back to terminal anymore. Get every thing done in emacs:-] thanksKwang
R
0

An advice on magit-run* solves this. Might disrupts other calls to magit-run*, I didn't test this further...

(defadvice magit-run* (around stay-in-magit activate)
  (flet ((pop-to-buffer (buf &optional act rec) (display-buffer buf act)))
    ad-do-it))
Retro answered 26/11, 2012 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.