Refactor popup init + defuns

This commit is contained in:
Henrik Lissner 2016-04-26 02:01:39 -04:00
parent f497aac0b8
commit f17082a657
2 changed files with 18 additions and 15 deletions

View file

@ -66,23 +66,9 @@
(defvar narf-popup-windows '() (defvar narf-popup-windows '()
"A list of windows that have been opened via shackle. Do not touch this!") "A list of windows that have been opened via shackle. Do not touch this!")
;; Popup hook ;; There is no shackle-popup hook, so I hacked one in
(defvar shackle-popup-hook '() "Hook run whenever a popup is opened.")
(defun narf|run-popup-hooks (&rest _)
(with-current-buffer shackle-last-buffer
(run-hooks 'shackle-popup-hook)))
(advice-add 'shackle-display-buffer :after 'narf|run-popup-hooks) (advice-add 'shackle-display-buffer :after 'narf|run-popup-hooks)
;; Keep track of popups ;; Keep track of popups
(defun narf|popup-init ()
(add-to-list 'narf-popup-windows (get-buffer-window))
(local-set-key [escape escape] 'narf/popup-close)
(when (or (bound-and-true-p repl-toggle-mode)
(derived-mode-p 'tabulated-list-mode)
(memq major-mode '(messages-buffer-mode flycheck-error-list-mode-hook esup-mode)))
(let ((map evil-normal-state-local-map))
(define-key map [escape] 'narf/popup-close)
(define-key map (kbd "ESC") 'narf/popup-close))))
(add-hook! 'shackle-popup-hook '(narf|popup-init narf|hide-mode-line)) (add-hook! 'shackle-popup-hook '(narf|popup-init narf|hide-mode-line))

View file

@ -79,5 +79,22 @@
(narf|hide-mode-line) (narf|hide-mode-line)
(goto-char (point-max)))) (goto-char (point-max))))
;;;###autoload
(defun narf|popup-init ()
(add-to-list 'narf-popup-windows (get-buffer-window))
(local-set-key [escape escape] 'narf/popup-close)
(when (or (bound-and-true-p repl-toggle-mode)
(derived-mode-p 'tabulated-list-mode)
(memq major-mode '(messages-buffer-mode flycheck-error-list-mode-hook esup-mode)))
(let ((map evil-normal-state-local-map))
(define-key map [escape] 'narf/popup-close)
(define-key map (kbd "ESC") 'narf/popup-close))))
(defvar shackle-popup-hook '() "Hook run whenever a popup is opened.")
;;;###autoload
(defun narf|run-popup-hooks (&rest _)
(with-current-buffer shackle-last-buffer
(run-hooks 'shackle-popup-hook)))
(provide 'defuns-popups) (provide 'defuns-popups)
;;; defuns-popups.el ends here ;;; defuns-popups.el ends here