current-window-only icon indicating copy to clipboard operation
current-window-only copied to clipboard

Open things only in the current window. No other windows, no splits.

  • ~M-x current-window-only~

Open things only in the current window. No other windows, no splits.

In the ideal world, this package should not be necessary and one would simply configure ~display-buffer-alist~ to display buffers only in the current window. But not all commands respect this variable (e.g. ~org-agenda~), and so this package implements multiple tricks to achieve the desired behavior.

** Obligatory GIF section

My apologies for not recording key presses. I am basically just hitting enter to open things and ~q~ to close things.

| Command | Before | After | |--------------------+-----------------------------------------------+----------------------------------------------| | ~M-x calendar~ | [[images/calendar-before.gif?raw=1][GIF]] | [[images/calendar-after.gif?raw=1][GIF]] | | ~M-x org-agenda~ | [[images/org-agenda-before.gif?raw=1][GIF]] | [[images/org-agenda-after.gif?raw=1][GIF]] | | ~M-x magit-status~ | [[images/magit-status-before.gif?raw=1][GIF]] | [[images/magit-status-after.gif?raw=1][GIF]] | | ~M-x man~ | [[images/man-before.gif?raw=1][GIF]] | [[images/man-after.gif?raw=1][GIF]] |

Or you can [[https://www.youtube.com/watch?v=Qut1oO6nqgA][watch a short video]].

** Installation

The package is not available in MELPA yet. Please choose your preferred package manager to install.

Quelpa:

#+BEGIN_SRC emacs-lisp (use-package current-window-only :quelpa (current-window-only :fetcher github :repo "FrostyX/current-window-only") :config (current-window-only-mode)) #+END_SRC

Straight:

#+BEGIN_SRC emacs-lisp (use-package current-window-only :straight (current-window-only :type git :host github :repo "FrostyX/current-window-only") :config (current-window-only-mode)) #+END_SRC

** Motivation

The [[DemystifyingEmacs][Demystifying Emacs’s Window Manager]] article provides a great explanation of the key concepts, behavior, and configuration of the window manager. Are you ready for the red pill and seeing how deep the rabbit hole goes? The rest of us want reasonable behavior without being required to understand.

In short, a user can adjust how buffers should be displayed by adding new rules to the ~display-buffer-alist~ variable. The general consensus is that the rules are just too cryptic, too complicated, and not many people understand them. As a consequence third-party packages such as ~shackle~ and ~popwin~ appeared, allowing to define human-readable rules.

My humble guess is that the majority of people add rules for Emacs to stop breaking their /splits/, to open things in the current window, and nothing else. Why define some rules in the first place, when you can simply ~M-x current-window-only~?

** See also

  • [[DemystifyingEmacs][Demystifying Emacs’s Window Manager]]
  • [[https://karthinks.com/software/emacs-window-management-almanac/][The Emacs Window Management Almanac]]
  • [[https://www.youtube.com/watch?v=1-UIzYPn38s][Emacs: control where buffers are displayed]]
  • [[prot][Emacs: window rules and parameters]]
  • [[shackle][shackle]]
  • [[popwin][popwin]]

** Tips and tricks

You might need to adjust some workflows after enabling the package.

*** Magit commit

When creating a new commit, Magit spawns two buffers - diff with file changes and a commit message. It is useful to see the changes while writing the commit message but with ~current-window-only~, they will open in the same window and therefore only one of them remains visible. This is consistent with the goals of this package but if you don't like it, you can:

  • Use ~evil-switch-to-windows-last-buffer~ or ~C-x b RET~ to easily jump back and forth between the two buffers within one window.
  • Move the cursor to any appropriate window and manually open the other Magit buffer there
  • Use ~(setq magit-commit-diff-inhibit-same-window t)~ to sidestep ~current-window-only~

#+LINK: DemystifyingEmacs https://www.masteringemacs.org/article/demystifying-emacs-window-manager #+LINK: prot https://www.youtube.com/watch?v=rjOhJMbA-q0 #+LINK: shackle https://depp.brause.cc/shackle/ #+LINK: popwin https://github.com/emacsorphanage/popwin