threads / discuss / 25440

Manual hunk edit mode + emacs + ^G == garbage

Subject: Manual hunk edit mode + emacs + ^G == garbage

## tl;dr

10 messages between Oct 13, 2010 and Feb 22, 2012.

replies: 9people: 6as markdown or json

Kevin Ballard· Oct 13, 2010, 21:37 UTC · lore
I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e) and emacs together. It seems every time I hit ^G inside of emacs in this one circumstance, the entire process instantly shuts down, both emacs and `git add`, and it doesn't even give emacs a chance to clean up the terminal, so I'm left with garbage across my display (the remains of the emacs window) and the terminal settings are screwed up enough that I have to close and reopen it (even `reset` doesn't fix everything). Has anybody else seen this, and if so, do you know what's going on? I cannot reproduce this with emacs outside of `git add -p`, and I cannot reproduce this with vim even inside of `git add -p`.
-Kevin Ballard
Drew Northup· Oct 13, 2010, 21:48 UTC · re: Kevin Ballard · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Wed, 2010-10-13 at 14:37 -0700, Kevin Ballard wrote:
> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e) and emacs together. It seems every time I hit ^G inside of emacs in this one circumstance, the entire process instantly shuts down, both emacs and `git add`, and it doesn't even give emacs a chance to clean up the terminal, so I'm left with garbage across my display (the remains of the emacs window) and the terminal settings are screwed up enough that I have to close and reopen it (even `reset` doesn't fix everything). Has anybody else seen this, and if so, do you know what's going on? I cannot reproduce this with emacs outside of `git add -p`, and I cannot reproduce this with vim even inside of `git add -p`.

Is there some way to get a dump of the environment that emacs is seeing? If we have that it will be easier to tell if this is an emacs problem or a git problem.

-- 
-Drew Northup
________________________________________________
"As opposed to vegetable or mineral error?"
-John Pescatore, SANS NewsBites Vol. 12 Num. 59
Kevin Ballard· Oct 13, 2010, 21:53 UTC · re: Drew Northup · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Oct 13, 2010, at 2:48 PM, Drew Northup wrote:
Show 7 quoted lines
> 
> On Wed, 2010-10-13 at 14:37 -0700, Kevin Ballard wrote:
>> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e) and emacs together. It seems every time I hit ^G inside of emacs in this one circumstance, the entire process instantly shuts down, both emacs and `git add`, and it doesn't even give emacs a chance to clean up the terminal, so I'm left with garbage across my display (the remains of the emacs window) and the terminal settings are screwed up enough that I have to close and reopen it (even `reset` doesn't fix everything). Has anybody else seen this, and if so, do you know what's going on? I cannot reproduce this with emacs outside of `git add -p`, and I cannot reproduce this with vim even inside of `git add -p`.
> 
> Is there some way to get a dump of the environment that emacs is seeing?
> If we have that it will be easier to tell if this is an emacs problem or
> a git problem.
I've been investigating this on the emacs side as well. At the moment, my suspicion is that ^G causes emacs to trigger (keyboard-quit), but at the same time the surrounding environment (e.g. git) is sending a SIGINT to emacs, which normally acts like ^G but in this case may be triggering the emergency exit mode of emacs. Is there some reason that the interactive add would be sending SIGINT to emacs when I type ^G?
-Kevin Ballard
Andreas Schwab· Oct 13, 2010, 22:40 UTC · re: Kevin Ballard · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

Kevin Ballard <kevin@sb.org> writes:
> I've been investigating this on the emacs side as well. At the moment, my suspicion is that ^G causes emacs to trigger (keyboard-quit), but at the same time the surrounding environment (e.g. git) is sending a SIGINT to emacs, which normally acts like ^G but in this case may be triggering the emergency exit mode of emacs. Is there some reason that the interactive add would be sending SIGINT to emacs when I type ^G?

If you are using text mode (-nw) then Emacs redefines the INTR character of the terminal to ^G. On the other hand it should also put itself into its own process group, so the parent should not receive the terminal signals. And this is what happens here when I try it.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Kevin Ballard· Oct 13, 2010, 22:49 UTC · re: Andreas Schwab · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Oct 13, 2010, at 3:40 PM, Andreas Schwab wrote:
Show 8 quoted lines
> Kevin Ballard <kevin@sb.org> writes:
> 
>> I've been investigating this on the emacs side as well. At the moment, my suspicion is that ^G causes emacs to trigger (keyboard-quit), but at the same time the surrounding environment (e.g. git) is sending a SIGINT to emacs, which normally acts like ^G but in this case may be triggering the emergency exit mode of emacs. Is there some reason that the interactive add would be sending SIGINT to emacs when I type ^G?
> 
> If you are using text mode (-nw) then Emacs redefines the INTR character
> of the terminal to ^G.  On the other hand it should also put itself into
> its own process group, so the parent should not receive the terminal
> signals.  And this is what happens here when I try it.
I am indeed using text mode. And when I test, invoking `emacs` directly gives it its on process group, but invoking emacs from `git add -p`+e doesn't.

kevin@Brandybuck:~> ps -jp 34581 34540 USER PID PPID PGID SESS JOBC STAT TT TIME COMMAND kevin 34540 34539 34538 7d29d68 1 S+ s001 0:00.08 /usr/bin/perl /usr/local/libexec/git-core/git-add--interactive -- kevin 34581 34540 34538 7d29d68 1 S+ s001 0:00.61 /usr/bin/emacs /Users/kevin/Dev/Work/Standard9/inkling-ipad/.git/

Any idea why this would be?
-Kevin Ballard
Ævar Arnfjörð Bjarmason· Oct 14, 2010, 09:37 UTC · re: Kevin Ballard · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Wed, Oct 13, 2010 at 21:37, Kevin Ballard <kevin@sb.org> wrote:
> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e)

Aside from this bug you might want to check out magit.el, it's a much nicer hunk edit more for Emacs than running git add -p in an Emacs terminal is.

Kevin Ballard· Oct 14, 2010, 09:47 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Oct 14, 2010, at 2:37 AM, Ævar Arnfjörð Bjarmason wrote:
Show 7 quoted lines
> On Wed, Oct 13, 2010 at 21:37, Kevin Ballard <kevin@sb.org> wrote:
> 
>> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e)
> 
> Aside from this bug you might want to check out magit.el, it's a much
> nicer hunk edit more for Emacs than running git add -p in an Emacs
> terminal is.
Except I don't run it in an emacs terminal. I run it in my regular terminal, and only launch emacs when I need to in order to edit a hunk or whatnot.
BTW, it also appears that this happens in the normal `git commit` editor as well, I just hadn't noticed before since I rarely need to type ^G when writing a commit message.
-Kevin Ballard
Miles Bader· Oct 14, 2010, 09:51 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 5 quoted lines
>> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e)
>
> Aside from this bug you might want to check out magit.el, it's a much
> nicer hunk edit more for Emacs than running git add -p in an Emacs
> terminal is.
Yup, for that particular problem, magit is, well, like magic :)
-miles
-- 
Pray, v. To ask that the laws of the universe be annulled in behalf of a
single petitioner confessedly unworthy.
Kevin Ballard· Oct 15, 2010, 09:13 UTC · re: Miles Bader · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

On Oct 14, 2010, at 2:51 AM, Miles Bader wrote:
Show 8 quoted lines
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>>> I've been having a rather strange problem using manual hunk edit mode (`git add -p`, e)
>> 
>> Aside from this bug you might want to check out magit.el, it's a much
>> nicer hunk edit more for Emacs than running git add -p in an Emacs
>> terminal is.
> 
> Yup, for that particular problem, magit is, well, like magic :)
I tested out magit, and didn't particularly like it. First off, it seems to be throwing an error when I invoke magit-status, at least if there's no changes. I don't know if this is related to the fact that my emacs is only 22.1, but magit itself doesn't document any required version of emacs. Secondly, when there is a change, the coloration is really hard to read, and the navigation is quite poor as well (and I didn't find anything to make it better in the cheatsheet). And it's far slower than just using `git add -p` and only dropping into emacs occasionally for manual hunk edits.
I'm still very much interested in finding a solution to why ^G kills emacs when it's invoked by git. As I said earlier, it appears that emacs shares the same process group with the perl process that called it, even though Andreas Schwab says it puts itself into its own process group and invoking emacs from the shell does just that. Does anyone know why this might be happening?
-Kevin Ballard
Matt McClure· Feb 22, 2012, 21:43 UTC · re: Kevin Ballard · lore

Re: Manual hunk edit mode + emacs + ^G == garbage

Kevin Ballard <kevin <at> sb.org> writes:
Show 6 quoted lines
> I'm still very much interested in finding a solution to why ^G kills
> emacs when it's invoked by git. As I said earlier, it appears that emacs
> shares the same process group with the perl process that called it, even
> though Andreas Schwab says it puts itself into its own process group and
> invoking emacs from the shell does just that. Does anyone know why this
> might be happening?
Kevin,

I was having the same problem you described on Mac OS X Lion and found this old thread. A workaround that works for me is:

~/bin/emacs.sh:
#!/bin/bash -i
emacs "$@"
-- cut --
git config --global core.editor ~/bin/emacs.sh
Matt

← back to recent threads