doomemacs/modules/ui/popup
Henrik Lissner 51d3b1b424
💥 revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.

In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.

  doom*shut-up -> doom-shut-up-a
  doom*recenter -> doom-recenter-a
  +evil*static-reindent -> +evil--static-reindent-a

The rationale behind this change is:

1. Elisp's own formatting/indenting tools would occasionally struggle
   with | and * (particularly pp and cl-prettyprint). They have no
   problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
   github markdown) struggle with it, sometimes refusing to highlight
   code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
   intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
   on haphazardly way back when Doom was simply "my private config".

Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.

Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
  macro. The old pair weren't as useful. The new def-advice! saves on a
  lot of space.
- Removed "stage" assertions to make sure you were using the right
  macros in the right place. Turned out to not be necessary, we'll
  employ better checks later.
2019-07-22 02:27:45 +02:00
..
autoload Refactor +popup/other 2019-06-30 18:12:16 +02:00
test
+hacks.el 💥 revise advice naming convention (1/2) 2019-07-22 02:27:45 +02:00
config.el Add default popup rule for M-x calc 2019-07-09 19:55:37 +02:00
README.org One dot in wrong place 2019-05-03 14:38:29 +02:00

ui/popup

Description

This module provides a customizable popup window management system.

Not all windows are created equally. Some are less important. Some I want gone once they have served their purpose, like code output or a help buffer. Others I want to stick around, like a scratch buffer or org-capture popup.

More than that, popups ought to be the second class citizens of my editor; spawned off to the side, discarded with the push of a button (e.g. ESC or C-g), and easily restored if I want to see them again. Of course, this system should clean up after itself and kill off buffers I mark as transient.

Module Flags

  • +all Enables fallback rules to ensure all temporary/special buffers (whose name begins with a space or asterix) are treated as popups.
  • +defaults Enables reasonable default popup rules for a variety of buffers.

Prerequisites

This module has no external prerequisites.

Configuration

set-popup-rule! and set-popup-rules!

This module has two functions for defining your own rules for popups:

(set-popup-rule! PREDICATE &key IGNORE ACTIONS SIDE SIZE WIDTH HEIGHT SLOT VSLOT TTL QUIT SELECT MODELINE AUTOSAVE PARAMETERS)
(set-popup-rules! &rest RULESETS)

PREDICATE is a predicate function or regexp string to match against the buffer's name. You'll find comprehensive documentation on the other keywords in set-popup-rule!'s docstring (SPC h f set-popup-rule!).

Popup rules end up in display-buffer-alist, which instructs display-buffer calls on how to set up windows for buffers that meet certain conditions. However, some plugins can avoid it entirely if they use set-buffer or switch-to-buffer, which don't obey display-buffer-alist.

Multiple popup rules can be defined with set-popup-rules!:

(set-popup-rules!
 '(("^ \\*" :slot -1) ; fallback rule for special buffers
   ("^\\*" :select t)
   ("^\\*Completions" :slot -1 :transient 0)
   ("^\\*\\(?:scratch\\|Messages\\)" :transient t)
   ("^\\*Help" :slot -1 :size 0.2 :select t)
   ("^\\*doom:"
    :size 0.35 :select t :modeline t :quit t :transient t)))

Omitted parameters in a set-popup-rules! will use the defaults set in +popup-defaults.

Disabling hidden mode-line in popups

The mode-line is hidden in popups, by default. To disable this, you can either:

  1. Change the default :modeline property in +popup-defaults:

    ;; put in private/$USER/config.el
    (map-put +popup-defaults :modeline t)

    A value of t will instruct popups to use the default mode-line. Any popup rule with a :modeline property can still override this.

  2. Completely disable management of the mode-line in popups:

    ;; in ~/.doom.d/config.el
    (remove-hook '+popup-buffer-mode-hook #'+popup|set-modeline-on-enable)

Appendix

Commands

  • +popup/other (aliased to other-popup, bound to C-x p)
  • +popup/toggle
  • +popup/close
  • +popup/close-all
  • +popup/toggle
  • +popup/restore
  • +popup/raise

Library

  • Functions

    • +popup-window-p WINDOW
    • +popup-buffer-p BUFFER
    • +popup-buffer BUFFER &optional ALIST
    • +popup-parameter PARAMETER &optional WINDOW
    • +popup-parameter-fn PARAMETER &optional WINDOW
    • +popup-windows
  • Macros

    • without-popups!
    • save-popups!
  • Hooks

    • +popup|adjust-fringes
    • +popup|set-modeline
    • +popup|close-on-escape
    • +popup|cleanup-rules
  • Minor modes

    • +popup-mode
    • +popup-buffer-mode

Hacks

  • help-mode has been advised to follow file links in the buffer you were in before entering the popup, rather than in a new window.
  • wgrep buffers are advised to close themselves when aborting or committing changes.
  • persp-mode is advised to restore popup windows when loading a session from file.
  • Interactive calls to windmove-* commands (used by evil-window-* commands) will ignore the no-other-window window parameter, allowing you to switch to popup windows as if they're ordinary windows.
  • balance-windows has been advised to close popups while it does its business, then restore them afterwards.
  • neotree advises balance-windows, which causes major slow-downs when paired with our balance-window advice, so we removes neotree's advice.
  • org-mode is an ongoing (and huge) effort. It has a scorched-earth window management system I'm not fond of. ie. it kills all windows and monopolizes the frame. On top of that, it really likes to use switch-to-buffer for most of its buffer management, which completely bypasses display-buffer-alist. Some work has gone into reversing this.