unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Advising quit-window
@ 2011-10-26  1:54 Christoph Scholtes
  2011-10-26  2:23 ` Juanma Barranquero
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-26  1:54 UTC (permalink / raw)
  To: emacs-devel

Sorry to dwell on `quit-window', but...

I really don't like the default behavior of `quit-window' burying the
buffer instead of killing it. I'd much rather have the default be kill
than bury, especially when it is bound to `q'.

Therefore, I have this in my .emacs:

;; Advise quit-window to kill buffer instead of burying it
(defadvice quit-window (before advise-quit-window activate)
  (ad-set-arg 0 (not (ad-get-arg 0))))

This works fine for cases where `quit-window' is bound to, for example,
`q' in a keymap. However, `quit-window' is also called internally, for
example by `quit-windows-on'. The latter is then called by vc mode to
kill the log buffer after a commit. It took me a while to figure out
that my advice actually caused the log buffer to be buried now, instead
of killed.

Can we please have a user option to select whether the default behavior
is kill or bury? Or can we add a `quit-window-internal' and
`quit-window' then calls `quit-window-internal'? I can then advise
`quit-window' to get the behavior I want without affecting the internal
function.

Other solutions welcome.

Christoph



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26  1:54 Advising quit-window Christoph Scholtes
@ 2011-10-26  2:23 ` Juanma Barranquero
  2011-10-26  2:52   ` Christoph Scholtes
  2011-10-26  9:21 ` martin rudalics
  2011-10-26 13:54 ` Stefan Monnier
  2 siblings, 1 reply; 12+ messages in thread
From: Juanma Barranquero @ 2011-10-26  2:23 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: emacs-devel

On Wed, Oct 26, 2011 at 03:54, Christoph Scholtes
<cschol2112@googlemail.com> wrote:

> ;; Advise quit-window to kill buffer instead of burying it
> (defadvice quit-window (before advise-quit-window activate)
>  (ad-set-arg 0 (not (ad-get-arg 0))))
>
> This works fine for cases where `quit-window' is bound to, for example,
> `q' in a keymap. However, `quit-window' is also called internally, for
> example by `quit-windows-on'.

Why don't you do

(defadvice quit-window (before advise-quit-window activate)
  (when (called-interactively-p 'any)
    (ad-set-arg 0 (not (ad-get-arg 0)))))

?

    Juanma



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26  2:23 ` Juanma Barranquero
@ 2011-10-26  2:52   ` Christoph Scholtes
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-26  2:52 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

Juanma Barranquero <lekktu@gmail.com> writes:

> Why don't you do
>
> (defadvice quit-window (before advise-quit-window activate)
>   (when (called-interactively-p 'any)
>     (ad-set-arg 0 (not (ad-get-arg 0)))))

Nice, thanks. I will give this a try.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26  1:54 Advising quit-window Christoph Scholtes
  2011-10-26  2:23 ` Juanma Barranquero
@ 2011-10-26  9:21 ` martin rudalics
  2011-10-27  3:53   ` Christoph Scholtes
  2011-10-26 13:54 ` Stefan Monnier
  2 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2011-10-26  9:21 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: emacs-devel

 > `q' in a keymap. However, `quit-window' is also called internally, for
 > example by `quit-windows-on'. The latter is then called by vc mode to
 > kill the log buffer after a commit. It took me a while to figure out
 > that my advice actually caused the log buffer to be buried now, instead
 > of killed.

IIRC `vc-mode' used to call `delete-windows-on' here which doesn't kill
the argument buffer.  The formulation "to be buried now" strikes me as
if the buffer were killed before.  Did you really observe such a change
in behavior?

martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26  1:54 Advising quit-window Christoph Scholtes
  2011-10-26  2:23 ` Juanma Barranquero
  2011-10-26  9:21 ` martin rudalics
@ 2011-10-26 13:54 ` Stefan Monnier
  2011-10-27  3:55   ` Christoph Scholtes
  2 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2011-10-26 13:54 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: emacs-devel

> ;; Advise quit-window to kill buffer instead of burying it
> (defadvice quit-window (before advise-quit-window activate)
>   (ad-set-arg 0 (not (ad-get-arg 0))))

You can also do

  (global-set-key [remap quit-window] (lambda () (interactive) (quit-window 'kill)))


-- Stefan



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26  9:21 ` martin rudalics
@ 2011-10-27  3:53   ` Christoph Scholtes
  2011-10-27  9:54     ` martin rudalics
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-27  3:53 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

martin rudalics <rudalics@gmx.at> writes:

> IIRC `vc-mode' used to call `delete-windows-on' here which doesn't kill
> the argument buffer.  The formulation "to be buried now" strikes me as
> if the buffer were killed before.  Did you really observe such a change
> in behavior?

I tested it with the Mercurial backend in Emacs 23 and the log buffer
was killed after committing. I am fairly sure that that is the behavior
I saw in SVN, too.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-26 13:54 ` Stefan Monnier
@ 2011-10-27  3:55   ` Christoph Scholtes
  2011-10-27  6:43     ` Juri Linkov
  2011-10-27 12:23     ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-27  3:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> ;; Advise quit-window to kill buffer instead of burying it
>> (defadvice quit-window (before advise-quit-window activate)
>>   (ad-set-arg 0 (not (ad-get-arg 0))))
>
> You can also do
>
>   (global-set-key [remap quit-window] (lambda () (interactive) (quit-window 'kill)))

Thanks. I didn't know that you could remap command like that. However,
this fixes quit-window to always kill. I like to be able to bury it with
`C-u q'.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-27  3:55   ` Christoph Scholtes
@ 2011-10-27  6:43     ` Juri Linkov
  2011-10-27 12:06       ` Christoph Scholtes
  2011-10-27 12:23     ` Stefan Monnier
  1 sibling, 1 reply; 12+ messages in thread
From: Juri Linkov @ 2011-10-27  6:43 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: Stefan Monnier, emacs-devel

> Thanks. I didn't know that you could remap command like that. However,
> this fixes quit-window to always kill. I like to be able to bury it with
> `C-u q'.

Yes, `C-u q' is an important requirement.  And no advice, no remapping, no hook
can do that.  So we need a new customizable variable `quit-window-kill-buffer'.

Then users could either customize it globally to t, or bind it buffer-locally
in mode hooks.  And `C-u q' will inverse its current behavior.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-27  3:53   ` Christoph Scholtes
@ 2011-10-27  9:54     ` martin rudalics
  0 siblings, 0 replies; 12+ messages in thread
From: martin rudalics @ 2011-10-27  9:54 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: emacs-devel

 >> IIRC `vc-mode' used to call `delete-windows-on' here which doesn't kill
 >> the argument buffer.  The formulation "to be buried now" strikes me as
 >> if the buffer were killed before.  Did you really observe such a change
 >> in behavior?
 >
 > I tested it with the Mercurial backend in Emacs 23 and the log buffer
 > was killed after committing. I am fairly sure that that is the behavior
 > I saw in SVN, too.

Could you please investigate where and how these killed the buffer?

I don't use vc-mode currently and we'd have to know whether killing them
was/is intentional.

Thanks, martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-27  6:43     ` Juri Linkov
@ 2011-10-27 12:06       ` Christoph Scholtes
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-27 12:06 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Stefan Monnier, emacs-devel

Juri Linkov <juri@jurta.org> writes:

>> Thanks. I didn't know that you could remap command like that. However,
>> this fixes quit-window to always kill. I like to be able to bury it with
>> `C-u q'.
>
> Yes, `C-u q' is an important requirement.  And no advice, no remapping, no hook
> can do that.  So we need a new customizable variable `quit-window-kill-buffer'.

Doesn't Juanma's solution achieve this?

(defadvice quit-window (before advise-quit-window activate)
  (when (called-interactively-p 'any)
    (ad-set-arg 0 (not (ad-get-arg 0)))))

> Then users could either customize it globally to t, or bind it buffer-locally
> in mode hooks.  And `C-u q' will inverse its current behavior.

+1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-27  3:55   ` Christoph Scholtes
  2011-10-27  6:43     ` Juri Linkov
@ 2011-10-27 12:23     ` Stefan Monnier
  2011-10-29  3:57       ` Christoph Scholtes
  1 sibling, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2011-10-27 12:23 UTC (permalink / raw)
  To: Christoph Scholtes; +Cc: emacs-devel

>> (global-set-key [remap quit-window] (lambda () (interactive) (quit-window 'kill)))
> Thanks. I didn't know that you could remap command like that.  However,
> this fixes quit-window to always kill.  I like to be able to bury it with
> `C-u q'.

Then use a different redefinition:
(global-set-key [remap quit-window]
  (lambda () (interactive) (quit-window (not current-prefix-arg))))


        Stefan



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advising quit-window
  2011-10-27 12:23     ` Stefan Monnier
@ 2011-10-29  3:57       ` Christoph Scholtes
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Scholtes @ 2011-10-29  3:57 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Then use a different redefinition:
> (global-set-key [remap quit-window]
>   (lambda () (interactive) (quit-window (not current-prefix-arg))))

This works great. Thanks.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-10-29  3:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-26  1:54 Advising quit-window Christoph Scholtes
2011-10-26  2:23 ` Juanma Barranquero
2011-10-26  2:52   ` Christoph Scholtes
2011-10-26  9:21 ` martin rudalics
2011-10-27  3:53   ` Christoph Scholtes
2011-10-27  9:54     ` martin rudalics
2011-10-26 13:54 ` Stefan Monnier
2011-10-27  3:55   ` Christoph Scholtes
2011-10-27  6:43     ` Juri Linkov
2011-10-27 12:06       ` Christoph Scholtes
2011-10-27 12:23     ` Stefan Monnier
2011-10-29  3:57       ` Christoph Scholtes

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).