Skip to content

Avoid double-splitting windows when display-buffer-base-action is non-nil#21

Closed
ktfleming wants to merge 1 commit intokaorahi:masterfrom
ktfleming:fix-double-split
Closed

Avoid double-splitting windows when display-buffer-base-action is non-nil#21
ktfleming wants to merge 1 commit intokaorahi:masterfrom
ktfleming:fix-double-split

Conversation

@ktfleming
Copy link

If you set display-buffer-base-action like so:

(setopt display-buffer-base-action
          '((display-buffer-pop-up-window)))

then calling howm-list-all will create multiple, duplicate windows. There's some code that addresses this by binding pop-up-windows to nil; this PR does the same for display-buffer-base-action to avoid the multiple splits.

For the same reason that we bind pop-up-windows to nil: to avoid
double-splitting windows.
@kaorahi
Copy link
Owner

kaorahi commented Dec 15, 2024

Thank you for the PR!

(A) I couldn't reproduce the issue. Could you provide the steps starting from emacs -Q?

If possible, here's what works best for me:

  1. Download the source code of howm.
  2. Edit sample/dot.emacs if needed.
  3. Run make test (or emacs -Q -l sample/dot.emacs).
  4. Reproduce the issue. (You can ignore the sample notes' content.)
  5. Use M-x howm-bug-shot RET and share the output.

(B) From the elisp info (Windows > Displaying Buffers > Precedence of Action Functions), would (display-buffer-overriding-action '((display-buffer-same-window))) be a better option than (display-buffer-base-action nil)? Does the former work as expected too?

@ktfleming
Copy link
Author

Ah, sorry -- I was trying different values for display-buffer-base-action and indeed using display-buffer-pop-up-window does not cause the issue. However, using display-buffer-below-selected does seem to cause it. Here's the output of howm-bug-shot:

* Header:

[howm] 1.5.1 (compile: nil, make: nil, test: t)

[init]
(setq load-path (cons default-directory load-path))
(setq debug-on-error t)
(setq inhibit-startup-message t)

(setq howm-sample-directory (expand-file-name "sample/"))
(setq howm-directory howm-sample-directory)
(setq howm-keyword-file (expand-file-name ".howm-keys" howm-sample-directory))
(setq howm-history-file (expand-file-name ".howm-history" howm-sample-directory))
;(setq howm-menu-lang 'ja)
(setq howm-history-limit nil)  ;; Don't erase my ~/.howm-history.

(setq display-buffer-base-action '((display-buffer-below-selected)))

(require 'howm)
(howm-test)


* Emacs version:

[Emacs] 29.4 (aarch64-apple-darwin23.1.0) of 2024-11-04
[system] darwin
[window system] ns
[ENV] LC_ALL=en_US.UTF-8, LC_CTYPE=nil, LANGUAGE=nil, LANG=en_US.UTF-8

* Recent keys:

M-x h o w m - l i s t - a l l <return> n n p p n n p p M-x h o w m - b u g - s h o t <return>

* Recent messages:

For information about GNU Emacs and the GNU system, type C-h C-a.


* Screen shot:

--- #<window 7 on *howmS*> ---
search.txt            | = search
top.txt               | = top
                      | = title1
                      | body2
                      | = title3
                      | = タイトル1
                      | = タイトル2
bug-report.txt        | ※ make test や test.bat では, テスト用環境(ほぼ無設定の emac
--- #<window 8 on *howmC*> ---
= search

<<< 全文検索

一覧表示 or 連結表示 (ヒットしたファイルの中身を全部つないで)

これのおかげで, 断片的なメモをばんばんとれる :-)


--- #<window 3 on *howmS*> ---
search.txt            | = search
top.txt               | = top
                      | = title1
                      | body2
                      | = title3
                      | = タイトル1
                      | = タイトル2
bug-report.txt        | ※ make test や test.bat では, テスト用環境(ほぼ無設定の emacs)が起動します.
Makefile.in           | # Makefile.in generated by automake 1.16.3 from Makefile.am.
Makefile.am           | EXTRA_DIST = search.txt top.txt \
ChangeLog             | 2024-09-19  HIRAOKA Kazuyuki  <kakkokakko@gmail.com>
Makefile              | # Makefile.in generated by automake 1.16.3 from Makefile.am.
dot.emacs             | (setq load-path (cons default-directory load-path))


* Footer:

--- your comment ---

Regarding display-buffer-overriding-action, the documentation does make that sound promising but using the value '((display-buffer-same-window)) caused howm-list-all to behave strangely; the howmC buffer was now at the top of the screen and selected, while the howmS buffer was at the bottom of the screen. I also tried using '((display-buffer-reuse-window)), but that didn't give the desired behavior either, although I haven't yet determined why these don't work.

@kaorahi
Copy link
Owner

kaorahi commented Dec 16, 2024

thx! I can reproduce the issue now. Is this what we want to do?

--- a/riffle.el
+++ b/riffle.el
@@ -468,6 +468,8 @@ snap://Info-mode/emacs#File Variables
       (let ((even-window-heights (if size
                                      nil
                                    even-window-heights))
+            ;; Skip all user options and force the default behavior.
+            (display-buffer-overriding-action display-buffer-fallback-action)
             ;; Don't split windows further even when
             ;; riffle-pop-to-buffer is called twice.
             (pop-up-windows nil))

Though the following code also seems to work, the above one might be safer for backward compatibility.

            (display-buffer-overriding-action
             '((display-buffer-reuse-window display-buffer-use-some-window)))

@ktfleming
Copy link
Author

I can confirm that (display-buffer-overriding-action display-buffer-fallback-action) does work for me, and looking at https://www.gnu.org/software/emacs/manual/html_node/elisp/The-Zen-of-Buffer-Display.html:

display-buffer-alist and display-buffer-base-action are user options—Lisp programs must never set or rebind them. display-buffer-overriding-action, on the other hand, is reserved for applications—who seldom use that option and if they use it, then with utmost care.

So your solution is definitely preferable to mine that sets display-buffer-base-action, which I now know should only be set by users!

kaorahi added a commit that referenced this pull request Dec 22, 2024
kaorahi added a commit that referenced this pull request Dec 22, 2024
@kaorahi
Copy link
Owner

kaorahi commented Dec 22, 2024

fixed in 18d98c0.

I hadn't noticed this issue myself, and this PR gave me a chance to catch up on the modern approach to display-buffer. Thanks again for bringing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants