all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Juri Linkov <juri@linkov.net>
Cc: 70949@debbugs.gnu.org
Subject: bug#70949: display-buffer-choose-some-window
Date: Wed, 29 May 2024 10:49:37 +0200	[thread overview]
Message-ID: <431cc3a7-141e-414f-8650-72771609c407@gmx.at> (raw)
In-Reply-To: <86zfsaaqm1.fsf@mail.linkov.net>

 > This is exactly what I already use in ~/.emacs, and it works nicely.
 > Any chance to add something like this optionally to window.el?
 >
 > (defvar-local display-buffer-previous-window nil)
 >
 > (add-to-list 'display-buffer-alist
 >               '((category . compilation)
 >                 display-buffer-in-previous-window
 >                 (previous-window . display-buffer-previous-window)))
 >
 > (define-advice compile-goto-error (:around (ofun &rest args) previous-window)
 >    (let ((buffer (current-buffer)))
 >      (apply ofun args)
 >      (with-current-buffer buffer
 >        (setq-local display-buffer-previous-window (selected-window)))))
 >
 > The main problem is where to set this buffer-local variable
 > (I think better to use the buffer-local variable instead
 > of the window parameter since visiting results from rgrep
 > is a property of the buffer, not the window).
 > Instead of the advice like above, 'display-buffer-previous-window'
 > should be set in every buffer displayed by 'display-buffer'.
 > Isn't setting this variable in all buffers too excessive?
 > But I see no other way because the user might want to
 > force displaying the results in the same rgrep window, then
 > display-buffer-in-previous-window should reuse the same window.

We are talking about displaying, in one and the same window, buffers
whose only relationship is that they appear in the results list of
compilation or grep output.  That's why I think that a buffer-local
variable doesn't make sense here.  It works for 'compile-goto-error' but
only if, as a user, you invoke 'display-buffer' from the results window.
If you are in the file window and want to display the next file, you
have to go back to the results window.  If you use one window to show
results and files, you have to redisplay the results in that window
first.  All this is tedious, especially given the fact that 'next-error'
already can guess from where to get the name of the next file to show.

I think we need a unified framework that supports 'compile-goto-error'
and 'next-error' out of the box, where the later command can be invoked
from anywhere (although the key-binding in the results buffer is
obscured by 'compilation-next-error').  Which means that we should use a
global variable, say 'compilation-previous-window', that these commands
use to show the next file buffer.

This variable should be set up by the first invocation of either
'compile-goto-error' or 'next-error' and should be reset by
'quit-window' and 'delete-window'.  In addition, we'd need
'grep-previous-window' and 'occur-previous-window' variables and
whatever else falls into this category.

'next-error' could first determine, as it does now, to which category
the user request belongs.  If it's the compilation category, it consults
'compilation-previous-window' and, if that's a live window, calls
'display-buffer' with a 'display-buffer-in-previous-window' action and
'compilation-previous-window' as 'previous-window' action alist entry.
If it's not a live window, it has to first find or make a suitable
window, set 'compilation-previous-window' to that window and maybe mark
the window as softly dedicated so it won't get used too soon by other
'display-buffer' calls.

Whether all this should be done by 'next-error' or within
'display-buffer' is to decide.  In the latter case, 'next-error' could
pass to 'display-buffer' a 'previous-window' entry whose value is
something like the symbol 'compilation-previous-window' and
'display-buffer' would have to do the work I sketched above.  This has
the advantage that 'compile-goto-error' could use the same underlying
mechanism and no code would be duplicated.  The disadvantage is that
people who know about the inner working of compilation buffers and
'next-error' would have to work within window.el.

martin





  reply	other threads:[~2024-05-29  8:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 16:56 bug#70949: display-buffer-choose-some-window Juri Linkov
2024-05-15  8:06 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-15 16:49   ` Juri Linkov
2024-05-16  8:20     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-17  6:40       ` Juri Linkov
2024-05-18  9:21         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-20  6:15           ` Juri Linkov
2024-05-20  8:01             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-20 16:54               ` Juri Linkov
2024-05-21  8:21                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-21 17:18                   ` Juri Linkov
2024-05-22  7:39                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-23  6:16                       ` Juri Linkov
2024-05-23  7:22                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-23 17:27                           ` Juri Linkov
2024-05-24  9:32                             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 17:38                               ` Juri Linkov
2024-05-26  8:54                                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-27 17:52                                   ` Juri Linkov
2024-05-28  8:05                                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-28 16:19                                       ` Juri Linkov
2024-05-29  8:49                                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-05-30  6:34                                           ` Juri Linkov
2024-05-30  8:54                                             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-31  6:18                                               ` Juri Linkov
2024-05-31  9:45                                                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02  6:39                                                   ` Juri Linkov
2024-06-04  8:20                                                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04 16:43                                                       ` Juri Linkov
2024-06-05  8:46                                                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 16:48                                                           ` Juri Linkov
2024-06-06  9:19                                                             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07  6:37                                                               ` Juri Linkov
2024-06-07  8:23                                                                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07 16:45                                                                   ` Juri Linkov
2024-06-08  9:12                                                                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-09 17:04                                                                       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=431cc3a7-141e-414f-8650-72771609c407@gmx.at \
    --to=bug-gnu-emacs@gnu.org \
    --cc=70949@debbugs.gnu.org \
    --cc=juri@linkov.net \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.