bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#45688: 28.0.50; New action for display-buffer?


From: Juri Linkov
Subject: bug#45688: 28.0.50; New action for display-buffer?
Date: Tue, 12 Jan 2021 20:36:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> We're asking too much from 'display-buffer' here.  It can't second-guess
>> a user's intentions in particular with the interpretation of grep and
>> xref hits.  I see three basic patterns here:
>
> I'm wondering whether there should be a separate
> `display-buffer-command' that's bound to `C-x 4 C-o' with its own
> display rules.  :-)  That is, when the user is using this command
> explicitly, then it's not obvious that the user wants the same rules as
> with the "automatic" display-buffer stuff (popping from *grep* buffers
> and the like).

Currently I'm using windmove-display-* group of commands to
instruct display-buffer where I want to display the buffer, e.g.:

's-<down> C-o' to open a grep/xref hit in the bottom window,
's-<left> C-o' to open a grep/xref hit in the left window, etc.

It's quite tedious to type that prefix before every key that
visits a grep hit.  What is still missing is some kind of DWIM
to make display-buffer smarter.

Here is what seems to work to visit grep/xref hits in the same window
where all previous hits were visited:

#+begin_src emacs-lisp
(defun display-buffer-from-grep-p (_buffer-name _action)
  (with-current-buffer (window-buffer)
    (derived-mode-p 'compilation-mode)))

(push '(display-buffer-from-grep-p display-buffer-reuse-previous-window)
      display-buffer-alist)

(defvar-local display-buffer-previous-window nil)

(defun display-buffer-reuse-previous-window (buffer alist)
  "Display BUFFER in the same window that was already used as destination."
  (let ((window display-buffer-previous-window))
    (if (window-live-p window)
        (window--display-buffer buffer window 'reuse alist)
      (setq window (display-buffer-use-some-window
                    buffer (cons (cons 'inhibit-same-window t) alist)))
      (setq-local display-buffer-previous-window window)
      window)))
#+end_src

One problem is that other display-buffer actions don't set
'display-buffer-previous-window'.  It would be nice to do
this in some low-level function in window.el.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]