doomemacs/core/core-popup.el

160 lines
6.7 KiB
EmacsLisp
Raw Normal View History

2016-01-30 21:16:10 -05:00
;;; core-popup.el --- taming stray windows
2015-11-19 05:50:04 -05:00
;; I use a slew of hackery to get Emacs to treat 'pop-ups' consistently. It goes
;; through great lengths to tame helm, flycheck, help buffers--*even* the beast
2016-10-02 23:26:29 +02:00
;; that is org-mode, with the help of `display-buffer-alist' and shackle.
2016-03-06 00:44:22 -05:00
;;
2016-10-02 23:26:29 +02:00
;; Be warned, an update could break this.
2016-03-06 00:44:22 -05:00
(use-package shackle
2015-11-19 05:50:04 -05:00
:config
(shackle-mode 1)
(setq shackle-rules
2016-05-24 21:57:25 -04:00
`(;; Util
2016-05-23 17:07:35 -04:00
("^\\*.+-Profiler-Report .+\\*$" :align below :size 0.3 :regexp t)
("*esup*" :align below :size 0.4 :noselect t)
2016-05-24 22:15:44 -04:00
("*minor-modes*" :align below :size 0.5 :noselect t)
("*eval*" :align below :size 16 :noselect t)
;; Doom
2016-06-18 01:30:12 -04:00
(" *doom*" :align below :size 35 :select t)
("^\\*doom:.+\\*$" :align below :size 35 :select t :regexp t)
("^\\*doom.+\\*$" :align below :size 12 :noselect t :regexp t)
2016-05-24 21:57:25 -04:00
;; Emacs
2016-05-24 22:15:44 -04:00
("*Pp Eval Output*" :align below :size 0.3)
("*Apropos*" :align below :size 0.3)
("*Backtrace*" :align below :size 25 :noselect t)
("*Help*" :align below :size 16 :select t)
("*Messages*" :align below :size 15 :select t)
("*Warnings*" :align below :size 10 :noselect t)
(compilation-mode :align below :size 15 :noselect t)
(eww-mode :align below :size 30 :select t)
2016-06-09 00:21:16 -04:00
("*command-log*" :align right :size 28 :noselect t)
2016-05-24 21:57:25 -04:00
;; vcs
2016-05-24 22:15:44 -04:00
("*vc-diff*" :align below :size 15 :noselect t)
("*vc-change-log*" :align below :size 15 :select t)
(vc-annotate-mode :same t)))
2015-11-19 05:50:04 -05:00
2016-10-02 23:26:29 +02:00
;; Emacs 25.1+ properly shows the completion window at the bottom of the
;; current frame.
2016-10-02 23:26:29 +02:00
(unless (version< emacs-version "25.1")
(push '("*Completions*" :align below :size 30 :noselect t) shackle-rules))
2016-10-02 23:26:29 +02:00
;; :noesc = Can't be closed with a single ESC
;; :nokill = Won't be killed when closed (only buried)
(defvar doom-popup-rules
'(("^\\*doom\\(:scratch\\)?\\*$" :noesc :nokill)
2016-06-13 02:11:33 -04:00
("^\\*doom.*\\*$" :noesc :nokill)
(ivy-occur-grep-mode :noesc)
(compilation-mode :noesc)
(comint-mode :noesc :nokill)
(eshell-mode :noesc :nokill)
(messages-buffer-mode :nokill)
(esup-mode :noesc)
(tabulated-list-mode :noesc)))
2016-10-07 00:26:45 +02:00
;; There is no shackle-popup hook, so I created one:
(advice-add 'shackle-display-buffer :around 'doom*popup-init)
2016-10-07 00:26:45 +02:00
;; Tell these functions not to mess with popups:
(advice-add 'balance-windows :around 'doom*save-neotree)
2016-09-05 12:24:16 +02:00
(advice-add 'balance-windows :around 'doom*save-popup)
(advice-add 'doom/evil-window-move :around 'doom*save-popup)
(advice-add 'evil-window-move-very-bottom :around 'doom*save-popup)
(advice-add 'evil-window-move-very-top :around 'doom*save-popup)
(advice-add 'evil-window-move-far-left :around 'doom*save-popup)
(advice-add 'evil-window-move-far-right :around 'doom*save-popup)
(advice-add 'evil-window-move-very-bottom :around 'doom*save-neotree)
(advice-add 'evil-window-move-very-top :around 'doom*save-neotree)
(advice-add 'evil-window-move-far-left :around 'doom*save-neotree)
(advice-add 'evil-window-move-far-right :around 'doom*save-neotree)
)
2016-05-20 09:23:46 -04:00
;;
;; Hacks
;;
(after! help-mode
;; Help buffers use itself (or `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.
2016-05-20 09:23:46 -04:00
(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)))
(let ((location (find-function-search-for-symbol fun nil file)))
(doom/popup-close)
(switch-to-buffer (car location) nil t)
(if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file")))))
2016-05-20 09:23:46 -04:00
(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)))
(let ((location (find-variable-noselect var file)))
(doom/popup-close)
(switch-to-buffer (car location) nil t)
(if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file")))))
2016-05-20 09:23:46 -04:00
(define-button-type 'help-face-def
:supertype 'help-xref
'help-function (lambda (fun file)
(require 'find-func)
(let ((location
(find-function-search-for-symbol fun 'defface file)))
(doom/popup-close)
(switch-to-buffer (car location) nil t)
(if (cdr location)
(goto-char (cdr location))
(message "Unable to find location in file"))))))
2017-01-03 22:50:52 -05:00
(add-hook! org-load
;; Ensures org-src-edit yields control of its buffer to shackle.
(defun org-src-switch-to-buffer (buffer context)
(pop-to-buffer buffer))
;; And these for org-todo, org-link and org-agenda
(defun org-pop-to-buffer-same-window (&optional buffer-or-name norecord label)
"Pop to buffer specified by BUFFER-OR-NAME in the selected window."
(display-buffer buffer-or-name))
(defun org-switch-to-buffer-other-window (&rest args)
(car-safe
(mapc (lambda (b)
(let ((buf (if (stringp b) (get-buffer-create b) b)))
(pop-to-buffer buf t t)))
args)))
(defun doom/org-agenda-quit ()
"Necessary to finagle org-agenda into shackle popups and behave properly on quit."
(interactive)
(if org-agenda-columns-active
(org-columns-quit)
(let ((buf (current-buffer)))
(and (not (eq org-agenda-window-setup 'current-window))
(not (one-window-p))
(delete-window))
(kill-buffer buf)
(setq org-agenda-archives-mode nil
org-agenda-buffer nil))))
(after! org-agenda
(map! :map org-agenda-mode-map
:e "<escape>" 'doom/org-agenda-quit
:e "ESC" 'doom/org-agenda-quit
:e [escape] 'doom/org-agenda-quit
"q" 'doom/org-agenda-quit
"Q" 'doom/org-agenda-quit)))
2015-11-19 05:50:04 -05:00
(provide 'core-popup)
;;; core-popup.el ends here