2017-06-08 11:47:56 +02:00
|
|
|
;;; core-popups.el -*- lexical-binding: t; -*-
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-24 19:57:57 -05:00
|
|
|
;; I want a "real"-buffer-first policy in my Emacsian utpoia; popup buffers
|
|
|
|
;; ought to be second-class citizens to "real" buffers. No need for a wall or
|
2017-06-08 11:47:56 +02:00
|
|
|
;; controversial immigration policies -- all we need is `shackle' (and it will
|
|
|
|
;; actually work).
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-06-08 11:47:56 +02:00
|
|
|
;; The gist is: popups should be displayed on one side of the frame, away from
|
|
|
|
;; 'real' buffers. They should be easy to dispose of when we don't want to see
|
|
|
|
;; them and easily brought back in case we change our minds. Also, popups should
|
|
|
|
;; typically have no mode-line.
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-06-08 11:47:56 +02:00
|
|
|
;; Be warned, this requires a lot of hackery voodoo that could break with an
|
2017-02-24 19:57:57 -05:00
|
|
|
;; emacs update or an update to any of the packages it tries to tame (like helm
|
2017-01-28 02:00:38 -05:00
|
|
|
;; or org-mode).
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-03 08:03:48 -05:00
|
|
|
(defvar doom-popup-history nil
|
|
|
|
"A list of popups that were last closed. Used by `doom/popup-restore' and
|
2017-02-08 17:56:27 -05:00
|
|
|
`doom*popups-save'.")
|
2017-02-03 08:03:48 -05:00
|
|
|
|
|
|
|
(defvar doom-popup-remember-history t
|
|
|
|
"If non-nil, DOOM will remember the last popup(s) that were open in
|
|
|
|
`doom-popup-history'.")
|
|
|
|
|
|
|
|
(defvar doom-popup-other-window nil
|
|
|
|
"The last window selected before a popup was opened.")
|
|
|
|
|
|
|
|
(defvar-local doom-popup-rules nil
|
|
|
|
"The shackle rule that caused this buffer to be recognized as a popup.")
|
|
|
|
|
2017-05-12 12:14:17 +02:00
|
|
|
(defvar doom-popup-window-parameters
|
|
|
|
'(:noesc :modeline :autokill :autoclose)
|
2017-02-22 21:54:10 -05:00
|
|
|
"A list of window parameters that are set (and cleared) when `doom-popup-mode
|
|
|
|
is enabled/disabled.'")
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-setting! :popup (&rest rules)
|
2017-02-04 21:09:33 -05:00
|
|
|
"Prepend a new popup rule to `shackle-rules'."
|
2017-02-19 18:02:40 -05:00
|
|
|
(if (cl-every 'listp rules)
|
2017-02-25 22:18:16 -05:00
|
|
|
`(setq shackle-rules (nconc ',rules shackle-rules))
|
2017-02-19 18:02:40 -05:00
|
|
|
`(push ',rules shackle-rules)))
|
2017-02-04 21:09:33 -05:00
|
|
|
|
2017-02-03 08:03:48 -05:00
|
|
|
|
2017-02-04 02:53:57 -05:00
|
|
|
;;
|
|
|
|
;; Bootstrap
|
|
|
|
;;
|
2017-01-28 02:00:38 -05:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(def-package! shackle
|
|
|
|
:demand t
|
2017-02-04 02:53:57 -05:00
|
|
|
:init
|
|
|
|
(setq shackle-default-alignment 'below
|
2017-05-19 03:00:42 +02:00
|
|
|
shackle-default-size 8
|
2017-02-19 18:12:12 -05:00
|
|
|
;;; Baseline popup-window rules
|
2017-03-01 21:38:26 -05:00
|
|
|
;; Several custom properties have been added that are not part of
|
|
|
|
;; shackle and are used by doom's popup system. They are:
|
|
|
|
;;
|
2017-05-15 14:07:12 +02:00
|
|
|
;; :noesc If non-nil, pressing ESC *inside* the popup will close it.
|
|
|
|
;; Used by `doom/popup-close-maybe'.
|
2017-03-01 21:38:26 -05:00
|
|
|
;; :modeline By default, mode-lines are hidden in popups unless this
|
|
|
|
;; is non-nil. If it is a symbol, it'll use `doom-modeline'
|
2017-05-15 14:07:12 +02:00
|
|
|
;; to fetch a modeline config (in `doom-popup-mode').
|
|
|
|
;; :autokill If non-nil, the popup's buffer will be killed when the
|
|
|
|
;; popup is closed. Used by `doom*delete-popup-window'.
|
|
|
|
;; NOTE `doom/popup-restore' can't restore non-file popups
|
|
|
|
;; that have an :autokill property.
|
|
|
|
;; :autoclose If non-nil, close popup if ESC is pressed from outside
|
|
|
|
;; the popup window.
|
2017-02-19 18:12:12 -05:00
|
|
|
shackle-rules
|
2017-05-19 03:00:42 +02:00
|
|
|
'(("^\\*ftp " :noselect t :autokill t :noesc t)
|
2017-05-15 14:07:12 +02:00
|
|
|
;; doom
|
2017-05-19 03:00:42 +02:00
|
|
|
("^\\*doom:" :regexp t :size 0.35 :noesc t :select t :modeline t)
|
2017-05-15 14:07:12 +02:00
|
|
|
("^\\*doom " :regexp t :noselect t :autokill t :autoclose t)
|
|
|
|
;; built-in (emacs)
|
2017-05-19 03:00:42 +02:00
|
|
|
(apropos-mode :size 0.3 :autokill t :autoclose t)
|
|
|
|
(Buffer-menu-mode :size 20 :autokill t)
|
|
|
|
(comint-mode :noesc t)
|
|
|
|
(grep-mode :size 25 :noselect t :autokill t)
|
|
|
|
(profiler-report-mode :size 0.3 :regexp t :autokill t :modeline minimal)
|
|
|
|
(tabulated-list-mode :noesc t)
|
2017-05-27 13:26:47 +02:00
|
|
|
(special-mode :noselect t :autokill t :autoclose t)
|
|
|
|
("*info*" :size 0.5 :select t :autokill t)
|
|
|
|
("*Backtrace*" :size 20 :noselect t)
|
|
|
|
("*Warnings*" :size 5 :noselect t :autokill t :autoclose t)
|
|
|
|
("*Messages*" :size 12 :noselect t :autokill nil)
|
|
|
|
("*Help*" :size 0.3)
|
|
|
|
("^\\*.*Shell Command.*\\*$" :regexp t :size 20 :noselect t :autokill t)
|
|
|
|
("^\\*" :regexp t :noselect t :autokill t)
|
|
|
|
("^ \\*" :regexp t :size 12 :noselect t :autokill t :autoclose t)))
|
2017-02-04 02:53:57 -05:00
|
|
|
|
|
|
|
:config
|
2017-06-08 11:47:56 +02:00
|
|
|
(add-transient-hook! 'after-make-frame-functions (shackle-mode +1))
|
|
|
|
(add-hook 'window-setup-hook #'shackle-mode)
|
2017-02-22 21:54:10 -05:00
|
|
|
|
|
|
|
(defun doom*shackle-always-align (plist)
|
|
|
|
"Ensure popups are always aligned and selected by default. Eliminates the need
|
|
|
|
for :align t on every rule."
|
|
|
|
(when plist
|
2017-02-24 19:58:47 -05:00
|
|
|
(unless (or (plist-member plist :align)
|
|
|
|
(plist-member plist :same)
|
|
|
|
(plist-member plist :frame))
|
2017-02-22 21:54:10 -05:00
|
|
|
(plist-put plist :align t))
|
|
|
|
(unless (or (plist-member plist :select)
|
|
|
|
(plist-member plist :noselect))
|
|
|
|
(plist-put plist :select t)))
|
|
|
|
plist)
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'shackle--match :filter-return #'doom*shackle-always-align))
|
2017-02-08 01:58:11 -05:00
|
|
|
|
|
|
|
|
2017-02-08 17:56:27 -05:00
|
|
|
;;
|
2017-02-22 21:54:10 -05:00
|
|
|
;; Integration
|
2017-02-08 17:56:27 -05:00
|
|
|
;;
|
|
|
|
|
2017-02-24 19:57:57 -05:00
|
|
|
;; Tell `window-state-get' and `current-window-configuration' to recognize these
|
|
|
|
;; custom parameters. Helpful for `persp-mode' and persisting window configs
|
|
|
|
;; that have popups in them.
|
2017-05-14 16:49:46 +02:00
|
|
|
(dolist (param (cons 'popup doom-popup-window-parameters))
|
2017-02-22 21:54:10 -05:00
|
|
|
(push (cons param 'writable) window-persistent-parameters))
|
2017-02-08 17:56:27 -05:00
|
|
|
|
2017-02-25 02:11:56 -05:00
|
|
|
(defvar doom-popup-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map [escape] 'doom/popup-close-maybe)
|
|
|
|
(define-key map (kbd "ESC") 'doom/popup-close-maybe)
|
2017-03-04 18:32:16 -05:00
|
|
|
(define-key map [remap doom-kill-buffer] 'kill-this-buffer)
|
|
|
|
(define-key map [remap doom/kill-this-buffer] 'kill-this-buffer)
|
2017-03-18 01:23:56 -04:00
|
|
|
(define-key map [remap split-window-right] 'ignore)
|
|
|
|
(define-key map [remap split-window-below] 'ignore)
|
|
|
|
(define-key map [remap split-window-horizontally] 'ignore)
|
|
|
|
(define-key map [remap split-window-vertically] 'ignore)
|
|
|
|
(define-key map [remap mouse-split-window-horizontally] 'ignore)
|
|
|
|
(define-key map [remap mouse-split-window-vertically] 'ignore)
|
2017-02-25 02:11:56 -05:00
|
|
|
map)
|
|
|
|
"Active keymap in popup windows.")
|
|
|
|
|
2017-02-08 01:58:11 -05:00
|
|
|
(define-minor-mode doom-popup-mode
|
2017-02-08 17:56:27 -05:00
|
|
|
"Minor mode for popup windows."
|
2017-02-08 01:58:11 -05:00
|
|
|
:init-value nil
|
|
|
|
:keymap doom-popup-mode-map
|
2017-02-22 21:54:10 -05:00
|
|
|
(let ((window (selected-window)))
|
2017-05-15 14:07:12 +02:00
|
|
|
;; If `doom-popup-rules' isn't set for some reason, try to set it
|
|
|
|
(when-let (plist (and (not doom-popup-rules)
|
|
|
|
(window-parameter window 'popup)))
|
|
|
|
(setq-local doom-popup-rules (window-parameter window 'popup)))
|
2017-02-22 21:54:10 -05:00
|
|
|
;; Ensure that buffer-opening functions/commands (like
|
|
|
|
;; `switch-to-buffer-other-window' won't use this window).
|
|
|
|
(set-window-parameter window 'no-other-window doom-popup-mode)
|
|
|
|
;; Makes popup window resist interactively changing its buffer.
|
|
|
|
(set-window-dedicated-p window doom-popup-mode)
|
|
|
|
(cond (doom-popup-mode
|
|
|
|
;; Save metadata into window parameters so it can be saved by window
|
|
|
|
;; config persisting plugins like workgroups or persp-mode.
|
|
|
|
(set-window-parameter window 'popup (or doom-popup-rules t))
|
|
|
|
(when doom-popup-rules
|
|
|
|
(dolist (param doom-popup-window-parameters)
|
|
|
|
(when-let (val (plist-get doom-popup-rules param))
|
|
|
|
(set-window-parameter window param val)))))
|
|
|
|
|
|
|
|
(t
|
|
|
|
;; Ensure window parameters are cleaned up
|
|
|
|
(set-window-parameter window 'popup nil)
|
|
|
|
(dolist (param doom-popup-window-parameters)
|
|
|
|
(set-window-parameter window param nil))))))
|
2017-02-08 01:58:11 -05:00
|
|
|
|
2017-04-18 04:59:46 -04:00
|
|
|
;; Major mode changes (and other things) may call `kill-all-local-variables',
|
|
|
|
;; turning off things like `doom-popup-mode'. This prevents that.
|
|
|
|
(put 'doom-popup-mode 'permanent-local t)
|
|
|
|
(put 'doom-popup-rules 'permanent-local t)
|
|
|
|
|
|
|
|
;; Don't show modeline in popup windows without a :modeline rule. If
|
|
|
|
;; one exists and it's a symbol, use `doom-modeline' to grab the
|
|
|
|
;; format. If non-nil, show the mode-line as normal. If nil (or
|
|
|
|
;; omitted, by default), then hide the modeline entirely.
|
|
|
|
(add-hook! 'doom-popup-mode-hook
|
|
|
|
(if doom-popup-mode
|
|
|
|
(let ((modeline (plist-get doom-popup-rules :modeline)))
|
|
|
|
(cond ((or (eq modeline 'nil)
|
|
|
|
(not modeline))
|
|
|
|
(doom-hide-modeline-mode +1))
|
|
|
|
((and (symbolp modeline)
|
|
|
|
(not (eq modeline 't)))
|
2017-04-25 22:55:57 -04:00
|
|
|
(setq-local doom--modeline-format (doom-modeline modeline))
|
|
|
|
(when doom--modeline-format
|
|
|
|
(doom-hide-modeline-mode +1)))))
|
2017-04-18 04:59:46 -04:00
|
|
|
;; show modeline
|
|
|
|
(when doom-hide-modeline-mode
|
|
|
|
(doom-hide-modeline-mode -1))))
|
2017-02-21 03:44:02 -05:00
|
|
|
|
2017-02-19 18:12:12 -05:00
|
|
|
;;
|
2017-02-08 01:58:11 -05:00
|
|
|
(defun doom*popup-init (orig-fn &rest args)
|
2017-02-24 19:57:57 -05:00
|
|
|
"Initializes a window as a popup window by enabling `doom-popup-mode' in it
|
|
|
|
and setting `doom-popup-rules' within it. Returns the window."
|
2017-02-08 01:58:11 -05:00
|
|
|
(unless (doom-popup-p)
|
|
|
|
(setq doom-popup-other-window (selected-window)))
|
2017-05-15 14:07:12 +02:00
|
|
|
(let* ((plist (or (nth 2 args)
|
|
|
|
(cond ((windowp (car args))
|
|
|
|
(shackle-match (window-buffer (car args))))
|
|
|
|
((bufferp (car args))
|
|
|
|
(shackle-match (car args))))))
|
|
|
|
(buffer (get-buffer (car args)))
|
|
|
|
(window-min-height (if (plist-get plist :modeline) 4 2))
|
|
|
|
window)
|
2017-05-14 14:35:58 +02:00
|
|
|
(when (and (doom-real-buffer-p buffer)
|
|
|
|
(get-buffer-window-list buffer nil t))
|
2017-05-12 12:11:40 +02:00
|
|
|
(setq plist (append (list :autokill t) plist))
|
|
|
|
(setcar args (clone-indirect-buffer (buffer-name (car args)) nil t)))
|
2017-05-13 00:14:15 +02:00
|
|
|
(unless (setq window (apply orig-fn args))
|
2017-02-22 21:54:10 -05:00
|
|
|
(error "No popup window was found for %s: %s" (car args) plist))
|
|
|
|
(with-selected-window window
|
|
|
|
(unless (eq plist t)
|
|
|
|
(setq-local doom-popup-rules plist))
|
|
|
|
(doom-popup-mode +1))
|
|
|
|
window))
|
2017-02-08 01:58:11 -05:00
|
|
|
|
2017-02-08 17:56:27 -05:00
|
|
|
(defun doom*popups-save (orig-fn &rest args)
|
2017-02-22 21:54:10 -05:00
|
|
|
"Sets aside all popups before executing the original function, usually to
|
|
|
|
prevent the popup(s) from messing up the UI (or vice versa)."
|
2017-02-08 01:58:11 -05:00
|
|
|
(let ((in-popup-p (doom-popup-p))
|
|
|
|
(popups (doom-popup-windows))
|
|
|
|
(doom-popup-remember-history t))
|
|
|
|
(when popups
|
2017-04-17 02:17:10 -04:00
|
|
|
(mapc #'doom/popup-close popups))
|
2017-02-08 01:58:11 -05:00
|
|
|
(unwind-protect (apply orig-fn args)
|
2017-01-28 02:00:38 -05:00
|
|
|
(when popups
|
2017-02-08 01:58:11 -05:00
|
|
|
(let ((origin (selected-window)))
|
|
|
|
(doom/popup-restore)
|
|
|
|
(unless in-popup-p
|
|
|
|
(select-window origin)))))))
|
|
|
|
|
2017-02-22 21:54:10 -05:00
|
|
|
(defun doom*delete-popup-window (&optional window)
|
2017-02-21 01:08:57 -05:00
|
|
|
"Ensure that popups are deleted properly, and killed if they have :autokill
|
|
|
|
properties."
|
2017-02-22 21:54:10 -05:00
|
|
|
(let ((window (or window (selected-window))))
|
2017-02-08 01:58:11 -05:00
|
|
|
(when (doom-popup-p window)
|
2017-02-22 20:50:23 -05:00
|
|
|
(when doom-popup-remember-history
|
|
|
|
(setq doom-popup-history (list (doom--popup-data window))))
|
2017-05-14 14:36:49 +02:00
|
|
|
(let ((autokill-p (plist-get doom-popup-rules :autokill)))
|
2017-02-22 20:50:23 -05:00
|
|
|
(with-selected-window window
|
2017-02-22 21:54:10 -05:00
|
|
|
(doom-popup-mode -1)
|
|
|
|
(when autokill-p
|
|
|
|
(kill-buffer (current-buffer))))))))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'shackle-display-buffer :around #'doom*popup-init)
|
|
|
|
(advice-add #'balance-windows :around #'doom*popups-save)
|
|
|
|
(advice-add #'delete-window :before #'doom*delete-popup-window)
|
2017-02-19 18:12:12 -05:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Hacks
|
|
|
|
;;
|
|
|
|
|
2017-05-10 05:26:13 +02:00
|
|
|
(progn ; hacks for built-in functions
|
|
|
|
(defun doom*buffer-menu (&optional arg)
|
|
|
|
"Open `buffer-menu' in a popup window."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((buf (list-buffers-noselect arg)))
|
|
|
|
(doom-popup-buffer buf)
|
|
|
|
(with-current-buffer buf
|
|
|
|
(setq mode-line-format "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %; q to quit; ? for help."))))
|
2017-05-27 13:26:47 +02:00
|
|
|
(advice-add #'buffer-menu :override #'doom*buffer-menu)
|
|
|
|
|
|
|
|
(defun doom*suppress-pop-to-buffer-same-window (orig-fn &rest args)
|
|
|
|
(cl-letf (((symbol-function 'pop-to-buffer-same-window)
|
|
|
|
(symbol-function 'pop-to-buffer)))
|
|
|
|
(apply orig-fn args)))
|
|
|
|
(advice-add #'info :around #'doom*suppress-pop-to-buffer-same-window))
|
2017-05-10 05:26:13 +02:00
|
|
|
|
|
|
|
|
2017-05-25 12:19:51 +02:00
|
|
|
(after! comint
|
|
|
|
(defun doom|popup-close-comint-buffer ()
|
|
|
|
(when (and (doom-popup-p)
|
|
|
|
(derived-mode-p 'comint-mode)
|
|
|
|
(not (process-live-p (get-buffer-process (current-buffer)))))
|
|
|
|
(delete-window)))
|
|
|
|
(add-hook '+evil-esc-hook #'doom|popup-close-comint-buffer t))
|
|
|
|
|
|
|
|
|
2017-05-12 12:10:04 +02:00
|
|
|
(after! eshell
|
|
|
|
;; By tying buffer life to its process, we ensure that we land back in the
|
|
|
|
;; eshell buffer after term dies. May cause problems with short-lived
|
|
|
|
;; processes.
|
|
|
|
;; FIXME replace with a 'kill buffer' keybinding.
|
|
|
|
(setq eshell-destroy-buffer-when-process-dies t)
|
|
|
|
|
2017-05-19 17:21:52 +02:00
|
|
|
;; When eshell runs a visual command (see `eshell-visual-commands'), it spawns
|
|
|
|
;; a term buffer to run it in, but where it spawns it is the problem...
|
2017-05-12 12:10:04 +02:00
|
|
|
(defun doom*eshell-undedicate-popup (orig-fn &rest args)
|
|
|
|
"Force spawned term buffer to share with the eshell popup (if necessary)."
|
|
|
|
(when (doom-popup-p)
|
|
|
|
(set-window-dedicated-p nil nil)
|
2017-06-05 16:41:39 +02:00
|
|
|
(add-transient-hook! #'eshell-query-kill-processes :after
|
2017-05-12 12:10:04 +02:00
|
|
|
(set-window-dedicated-p nil t)))
|
|
|
|
(apply orig-fn args))
|
|
|
|
(advice-add #'eshell-exec-visual :around #'doom*eshell-undedicate-popup))
|
|
|
|
|
|
|
|
|
2017-03-04 18:55:47 -05:00
|
|
|
(after! evil
|
|
|
|
(let ((map doom-popup-mode-map))
|
2017-05-19 13:04:14 +02:00
|
|
|
(define-key map [remap evil-window-delete] #'doom/popup-close)
|
|
|
|
(define-key map [remap evil-save-modified-and-close] #'doom/popup-close)
|
|
|
|
(define-key map [remap evil-window-move-very-bottom] #'ignore)
|
|
|
|
(define-key map [remap evil-window-move-very-top] #'ignore)
|
|
|
|
(define-key map [remap evil-window-move-far-left] #'ignore)
|
|
|
|
(define-key map [remap evil-window-move-far-right] #'ignore)
|
|
|
|
(define-key map [remap evil-window-split] #'ignore)
|
|
|
|
(define-key map [remap evil-window-vsplit] #'ignore))
|
|
|
|
|
|
|
|
(defun doom|popup-close-maybe ()
|
2017-05-25 12:22:05 +02:00
|
|
|
"If current window is a popup, close it. If minibuffer is open, close it. If
|
|
|
|
not in a popup, close all popups with an :autoclose property."
|
|
|
|
(cond ((doom-popup-p)
|
|
|
|
(unless (doom-popup-prop :noesc)
|
|
|
|
(delete-window)))
|
|
|
|
(t
|
|
|
|
(doom/popup-close-all))))
|
|
|
|
(add-hook '+evil-esc-hook #'doom|popup-close-maybe t)
|
2017-03-04 18:55:47 -05:00
|
|
|
|
|
|
|
;; Make evil-mode cooperate with popups
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'evil-command-window :override #'doom*popup-evil-command-window)
|
|
|
|
(advice-add #'evil-command-window-execute :override #'doom*popup-evil-command-window-execute)
|
2017-03-04 18:55:47 -05:00
|
|
|
|
|
|
|
(defun doom*popup-evil-command-window (hist cmd-key execute-fn)
|
|
|
|
"The evil command window has a mind of its own (uses `switch-to-buffer'). We
|
2017-01-28 02:00:38 -05:00
|
|
|
monkey patch it to use pop-to-buffer, and to remember the previous window."
|
2017-03-04 18:55:47 -05:00
|
|
|
(when (eq major-mode 'evil-command-window-mode)
|
|
|
|
(user-error "Cannot recursively open command line window"))
|
|
|
|
(dolist (win (window-list))
|
|
|
|
(when (equal (buffer-name (window-buffer win))
|
|
|
|
"*Command Line*")
|
|
|
|
(kill-buffer (window-buffer win))
|
|
|
|
(delete-window win)))
|
|
|
|
(setq evil-command-window-current-buffer (current-buffer))
|
|
|
|
(ignore-errors (kill-buffer "*Command Line*"))
|
|
|
|
(with-current-buffer (pop-to-buffer "*Command Line*")
|
|
|
|
(setq-local evil-command-window-execute-fn execute-fn)
|
|
|
|
(setq-local evil-command-window-cmd-key cmd-key)
|
|
|
|
(evil-command-window-mode)
|
|
|
|
(evil-command-window-insert-commands hist)))
|
|
|
|
|
|
|
|
(defun doom*popup-evil-command-window-execute ()
|
|
|
|
"Execute the command under the cursor in the appropriate buffer, rather than
|
2017-02-08 17:56:27 -05:00
|
|
|
the command buffer."
|
2017-03-04 18:55:47 -05:00
|
|
|
(interactive)
|
|
|
|
(let ((result (buffer-substring (line-beginning-position)
|
|
|
|
(line-end-position)))
|
|
|
|
(execute-fn evil-command-window-execute-fn)
|
|
|
|
(popup (selected-window)))
|
|
|
|
(select-window doom-popup-other-window)
|
|
|
|
(unless (equal evil-command-window-current-buffer (current-buffer))
|
|
|
|
(user-error "Originating buffer is no longer active"))
|
|
|
|
;; (kill-buffer "*Command Line*")
|
|
|
|
(doom/popup-close popup)
|
|
|
|
(funcall execute-fn result)
|
|
|
|
(setq evil-command-window-current-buffer nil)))
|
|
|
|
|
|
|
|
;; Don't mess with popups
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'doom-evil-window-move :around #'doom*popups-save)
|
|
|
|
(advice-add #'evil-window-move-very-bottom :around #'doom*popups-save)
|
|
|
|
(advice-add #'evil-window-move-very-top :around #'doom*popups-save)
|
|
|
|
(advice-add #'evil-window-move-far-left :around #'doom*popups-save)
|
|
|
|
(advice-add #'evil-window-move-far-right :around #'doom*popups-save)
|
2017-03-04 18:55:47 -05:00
|
|
|
|
|
|
|
;; Don't block moving to/from popup windows
|
|
|
|
(defun doom*ignore-window-parameters-in-popups (dir &optional arg window)
|
|
|
|
(window-in-direction (cond ((eq dir 'up) 'above)
|
|
|
|
((eq dir 'down) 'below)
|
|
|
|
(t dir))
|
|
|
|
window t arg windmove-wrap-around t))
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'windmove-find-other-window :override #'doom*ignore-window-parameters-in-popups))
|
2017-03-04 18:55:47 -05:00
|
|
|
|
|
|
|
|
2017-06-10 01:53:51 +02:00
|
|
|
(after! helm
|
|
|
|
;; Helm tries to clean up after itself, but shackle has already done this.
|
|
|
|
;; This fixes that. To reproduce, add a helm rule in `shackle-rules', open two
|
|
|
|
;; splits side-by-side, move to the buffer on the right and invoke helm. It
|
|
|
|
;; will close all but the left-most buffer.
|
|
|
|
(setq-default helm-reuse-last-window-split-state t
|
|
|
|
helm-split-window-in-side-p t)
|
|
|
|
|
|
|
|
(after! helm-swoop
|
|
|
|
(setq helm-swoop-split-window-function #'pop-to-buffer))
|
|
|
|
|
|
|
|
(after! helm-ag
|
|
|
|
;; This prevents helm-ag from switching between windows and buffers.
|
|
|
|
(defun doom*helm-ag-edit-done (orig-fn &rest args)
|
|
|
|
(cl-letf (((symbol-function 'select-window) #'ignore))
|
|
|
|
(apply orig-fn args))
|
|
|
|
(doom/popup-close))
|
|
|
|
(advice-add #'helm-ag--edit-commit :around #'doom*helm-ag-edit-done)
|
|
|
|
(advice-add #'helm-ag--edit-abort :around #'doom*helm-ag-edit-done)
|
|
|
|
|
|
|
|
(defun doom*helm-ag-edit (orig-fn &rest args)
|
|
|
|
(cl-letf (((symbol-function 'other-window) #'ignore)
|
|
|
|
((symbol-function 'switch-to-buffer) #'doom-popup-buffer))
|
|
|
|
(apply orig-fn args)
|
|
|
|
(with-current-buffer (get-buffer "*helm-ag-edit*")
|
|
|
|
(use-local-map helm-ag-edit-map))))
|
|
|
|
(advice-add #'helm-ag--edit :around #'doom*helm-ag-edit)))
|
|
|
|
|
|
|
|
|
2017-03-04 18:55:47 -05:00
|
|
|
(after! help-mode
|
|
|
|
;; Help buffers use `other-window' to decide where to open followed links,
|
|
|
|
;; which can be unpredictable. It should *only* replace the original buffer we
|
|
|
|
;; opened the popup from. To fix this these three button types need to be
|
|
|
|
;; redefined to set aside the popup before following a link.
|
|
|
|
(defsubst doom--switch-from-popup (location)
|
|
|
|
(doom/popup-close)
|
|
|
|
(switch-to-buffer (car location) nil t)
|
|
|
|
(if (not (cdr location))
|
|
|
|
(message "Unable to find location in file")
|
|
|
|
(goto-char (cdr location))
|
|
|
|
(recenter)))
|
|
|
|
|
|
|
|
(define-button-type 'help-function-def
|
|
|
|
:supertype 'help-xref
|
|
|
|
'help-function
|
|
|
|
(lambda (fun file)
|
|
|
|
(require 'find-func)
|
|
|
|
(when (eq file 'C-source)
|
|
|
|
(setq file (help-C-file-name (indirect-function fun) 'fun)))
|
|
|
|
(doom--switch-from-popup (find-function-search-for-symbol fun nil file))))
|
|
|
|
|
|
|
|
(define-button-type 'help-variable-def
|
|
|
|
:supertype 'help-xref
|
|
|
|
'help-function
|
|
|
|
(lambda (var &optional file)
|
|
|
|
(when (eq file 'C-source)
|
|
|
|
(setq file (help-C-file-name var 'var)))
|
|
|
|
(doom--switch-from-popup (find-variable-noselect var file))))
|
|
|
|
|
|
|
|
(define-button-type 'help-face-def
|
|
|
|
:supertype 'help-xref
|
|
|
|
'help-function
|
|
|
|
(lambda (fun file)
|
|
|
|
(require 'find-func)
|
|
|
|
(doom--switch-from-popup (find-function-search-for-symbol fun 'defface file)))))
|
|
|
|
|
|
|
|
|
2017-05-17 17:28:04 +02:00
|
|
|
(after! magit
|
|
|
|
(set! :popup "^\\*magit" :regexp t :size 0.5 :noesc t :autokill t)
|
|
|
|
|
|
|
|
;; magit doesn't need much coercing. It works with shackle as is, except for
|
|
|
|
;; one problem: following non-file magit links tends to open additional
|
|
|
|
;; popups. We want all this to be contained within one window, so...
|
|
|
|
(defun doom-magit-popup-buffer (buffer)
|
|
|
|
"Pop up the magit window with shackle."
|
|
|
|
(cond ((doom-popup-p)
|
|
|
|
(prog1 (doom-popup-switch-to-buffer buffer)
|
|
|
|
(doom-hide-modeline-mode +1)))
|
|
|
|
(t
|
|
|
|
(magit-display-buffer-traditional buffer))))
|
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun doom-magit-quit-window (_kill-buffer)
|
2017-05-17 17:28:04 +02:00
|
|
|
"Close the current magit window properly."
|
|
|
|
(let ((last (current-buffer)))
|
|
|
|
(cond ((when-let (dest (doom-buffers-in-mode
|
|
|
|
'magit-mode
|
|
|
|
(cl-remove-if (lambda (buf) (eq buf last))
|
|
|
|
(mapcar #'car (window-prev-buffers)))
|
|
|
|
t))
|
|
|
|
(doom-popup-switch-to-buffer (car dest)))
|
|
|
|
(kill-buffer last))
|
|
|
|
(t
|
|
|
|
(mapc #'kill-buffer
|
|
|
|
(doom-buffers-in-mode '(magit-mode magit-process-mode)
|
|
|
|
(buffer-list) t))))))
|
|
|
|
|
|
|
|
(setq magit-display-buffer-function #'doom-magit-popup-buffer
|
|
|
|
magit-bury-buffer-function #'doom-magit-quit-window))
|
|
|
|
|
|
|
|
|
2017-05-14 09:49:09 +02:00
|
|
|
(after! mu4e
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun doom*mu4e-popup-window (buf _height)
|
2017-05-14 09:49:09 +02:00
|
|
|
(doom-popup-buffer buf :size 10 :noselect t)
|
|
|
|
buf)
|
|
|
|
(advice-add #'mu4e~temp-window :override #'doom*mu4e-popup-window))
|
|
|
|
|
|
|
|
|
2017-05-15 14:08:04 +02:00
|
|
|
(after! multi-term
|
|
|
|
(setq multi-term-buffer-name "doom:terminal"))
|
|
|
|
|
|
|
|
|
2017-03-04 18:55:47 -05:00
|
|
|
(after! neotree
|
2017-05-08 10:32:49 +02:00
|
|
|
;; Neotree has its own window/popup management built-in, which is difficult to
|
|
|
|
;; police. For example, switching perspectives will cause neotree to forget it
|
|
|
|
;; is a neotree pane.
|
|
|
|
;;
|
|
|
|
;; By handing neotree over to shackle, which is better integrated into the
|
|
|
|
;; rest of my config (and persp-mode), this is no longer a problem.
|
|
|
|
(set! :popup " *NeoTree*" :align 'left :size 25)
|
|
|
|
|
|
|
|
(defun +evil-neotree-display-fn (buf _alist)
|
2017-05-16 17:39:42 +02:00
|
|
|
"Hand neotree off to shackle."
|
|
|
|
(let ((win (doom-popup-buffer buf)))
|
|
|
|
(setq neo-global--buffer (window-buffer win)
|
|
|
|
neo-global--window win)))
|
2017-05-17 18:26:50 +02:00
|
|
|
(setq neo-display-action '(+evil-neotree-display-fn))
|
2017-05-16 17:39:42 +02:00
|
|
|
|
|
|
|
(defun +evil|neotree-fix-popup ()
|
|
|
|
"Repair neotree state whenever its popup state is restored. This ensures
|
|
|
|
that `doom*popup-save' won't break it."
|
|
|
|
(when (equal (buffer-name) neo-buffer-name)
|
|
|
|
(setq neo-global--window (selected-window))))
|
|
|
|
(add-hook 'doom-popup-mode-hook #'+evil|neotree-fix-popup))
|
2017-04-09 22:09:33 -04:00
|
|
|
|
|
|
|
|
2017-05-14 09:49:09 +02:00
|
|
|
(after! quickrun
|
|
|
|
;; don't auto-focus quickrun windows, shackle handles that
|
|
|
|
(setq quickrun-focus-p nil))
|
2017-02-26 02:18:03 -05:00
|
|
|
|
|
|
|
|
2017-04-09 21:55:33 -04:00
|
|
|
(after! twittering-mode
|
2017-04-17 02:17:10 -04:00
|
|
|
(setq twittering-pop-to-buffer-function #'pop-to-buffer))
|
2017-04-09 21:55:33 -04:00
|
|
|
|
|
|
|
|
2017-05-17 18:23:17 +02:00
|
|
|
(after! wgrep
|
|
|
|
;; close the popup after you're done with a wgrep buffer
|
|
|
|
(advice-add #'wgrep-abort-changes :after #'doom/popup-close)
|
|
|
|
(advice-add #'wgrep-finish-edit :after #'doom/popup-close))
|
|
|
|
|
|
|
|
|
2017-04-18 05:00:39 -04:00
|
|
|
(after! xref
|
2017-05-08 10:32:57 +02:00
|
|
|
(defun doom*xref-follow-and-close (orig-fn &rest args)
|
2017-04-18 05:00:39 -04:00
|
|
|
"Jump to the xref on the current line, select its window and close the popup
|
|
|
|
you came from."
|
|
|
|
(interactive)
|
|
|
|
(let ((popup-p (doom-popup-p))
|
|
|
|
(window (selected-window)))
|
|
|
|
(apply orig-fn args)
|
2017-05-08 10:32:57 +02:00
|
|
|
(when popup-p (doom/popup-close window))))
|
|
|
|
(advice-add 'xref-goto-xref :around 'doom*xref-follow-and-close))
|
2017-04-18 05:00:39 -04:00
|
|
|
|
|
|
|
|
2017-03-04 18:55:47 -05:00
|
|
|
;; Ensure these settings are attached to org-load-hook as late as possible,
|
2017-05-17 01:32:19 +02:00
|
|
|
;; giving other modules a chance to add their own hooks.
|
2017-06-08 11:47:56 +02:00
|
|
|
(add-hook! 'emacs-startup-hook
|
2017-02-26 02:18:03 -05:00
|
|
|
(add-hook! 'org-load-hook
|
|
|
|
(set! :popup
|
|
|
|
'("*Calendar*" :size 0.4 :noselect t)
|
2017-03-04 18:55:47 -05:00
|
|
|
'(" *Org todo*" :size 5 :noselect t)
|
2017-02-26 02:18:03 -05:00
|
|
|
'("*Org Note*" :size 10)
|
2017-03-04 18:55:47 -05:00
|
|
|
'("*Org Select*" :size 20 :noselect t)
|
|
|
|
'("*Org Links*" :size 5 :noselect t)
|
2017-04-07 19:23:19 -04:00
|
|
|
'("*Org Export Dispatcher*" :noselect t)
|
2017-02-26 02:18:03 -05:00
|
|
|
'(" *Agenda Commands*" :noselect t)
|
|
|
|
'("^\\*Org Agenda" :regexp t :size 30)
|
|
|
|
'("*Org Clock*" :noselect t)
|
2017-05-13 00:12:23 +02:00
|
|
|
'("^\\*Org Src" :regexp t :size 0.35 :noesc t)
|
2017-02-26 02:18:03 -05:00
|
|
|
'("*Edit Formulas*" :size 10)
|
2017-04-28 01:44:00 -04:00
|
|
|
'("^\\*Org-Babel" :regexp t :size 25 :noselect t)
|
2017-02-26 02:18:03 -05:00
|
|
|
'("^CAPTURE.*\\.org$" :regexp t :size 20))
|
|
|
|
|
2017-05-13 00:12:23 +02:00
|
|
|
;; Org has its own window management system with a scorched earth philosophy
|
2017-05-17 01:32:19 +02:00
|
|
|
;; I'm not fond of. i.e. it kills all windows and monopolizes the frame. No
|
|
|
|
;; thanks. We can do better with shackle's help.
|
2017-02-26 02:18:03 -05:00
|
|
|
(defun doom*suppress-delete-other-windows (orig-fn &rest args)
|
2017-05-13 00:12:23 +02:00
|
|
|
(cl-letf (((symbol-function 'delete-other-windows)
|
2017-05-08 10:32:57 +02:00
|
|
|
(symbol-function 'ignore)))
|
|
|
|
(apply orig-fn args)))
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'org-add-log-note :around #'doom*suppress-delete-other-windows)
|
2017-05-08 10:32:57 +02:00
|
|
|
(advice-add #'org-capture-place-template :around #'doom*suppress-delete-other-windows)
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'org-export--dispatch-ui :around #'doom*suppress-delete-other-windows)
|
2017-02-26 02:18:03 -05:00
|
|
|
|
2017-05-13 00:12:23 +02:00
|
|
|
;; `org-edit-src-code' simply clones and narrows the buffer to a src block,
|
|
|
|
;; so we are secretly manipulating the same buffer. Since truely killing it
|
|
|
|
;; would kill the original org buffer we've got to do things differently.
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun doom*org-src-switch-to-buffer (buffer _context)
|
2017-05-13 00:12:23 +02:00
|
|
|
(if (eq org-src-window-setup 'switch-invisibly)
|
|
|
|
(set-buffer buffer)
|
|
|
|
(pop-to-buffer buffer)))
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'org-src-switch-to-buffer :override #'doom*org-src-switch-to-buffer)
|
2017-04-10 02:53:32 -04:00
|
|
|
|
2017-05-13 00:12:23 +02:00
|
|
|
;; Ensure todo, agenda, and other minor popups handed off to shackle.
|
2017-05-08 10:32:57 +02:00
|
|
|
(defun doom*org-pop-to-buffer (&rest args)
|
2017-04-10 02:53:32 -04:00
|
|
|
(let ((buf (car args)))
|
|
|
|
(pop-to-buffer
|
|
|
|
(cond ((stringp buf) (get-buffer-create buf))
|
|
|
|
((bufferp buf) buf)
|
|
|
|
(t (error "Invalid buffer %s" buf))))))
|
2017-05-08 10:32:57 +02:00
|
|
|
(advice-add #'org-switch-to-buffer-other-window :override #'doom*org-pop-to-buffer)
|
2017-02-26 02:18:03 -05:00
|
|
|
|
|
|
|
(after! org-agenda
|
2017-04-27 14:23:48 -04:00
|
|
|
(setq org-agenda-window-setup 'other-window
|
|
|
|
org-agenda-restore-windows-after-quit nil)
|
|
|
|
|
2017-05-08 10:32:57 +02:00
|
|
|
;; Hide modeline in org-agenda
|
|
|
|
(add-hook 'org-agenda-finalize-hook #'doom-hide-modeline-mode)
|
2017-05-13 00:12:23 +02:00
|
|
|
;; Don't monopolize frame!
|
2017-04-27 14:23:48 -04:00
|
|
|
(advice-add #'org-agenda :around #'doom*suppress-delete-other-windows)
|
|
|
|
|
2017-02-26 02:18:03 -05:00
|
|
|
(after! evil
|
|
|
|
(map! :map* org-agenda-mode-map
|
|
|
|
:m [escape] 'org-agenda-Quit
|
|
|
|
:m "ESC" 'org-agenda-Quit))
|
|
|
|
(let ((map org-agenda-mode-map))
|
|
|
|
(define-key map "q" 'org-agenda-Quit)
|
2017-03-04 18:55:47 -05:00
|
|
|
(define-key map "Q" 'org-agenda-Quit)))))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
|
|
|
(provide 'core-popups)
|
|
|
|
;;; core-popups.el ends here
|