Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use guide-key with window-purpose [fixes #915] #1072

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions spacemacs/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
volatile-highlights
whitespace
window-numbering
window-purpose
winner
yasnippet
zenburn-theme
Expand Down Expand Up @@ -1256,6 +1257,69 @@ which require an initialization must be listed explicitly in the list.")
bzg-big-fringe-mode)
ad-do-it))

(eval-after-load 'window-purpose
'(progn
(defun spacemacs/horizontal-position-p (window-position)
(member window-position '(left right)))

(defun spacemacs/display-guide-key (buffer alist)
(let* ((display-fn
(cl-case guide-key/popup-window-position
(top 'purpose-display-at-top)
(bottom 'purpose-display-at-bottom)
(left 'purpose-display-at-left)
(right 'purpose-display-at-right)
(otherwise
(error "Invalid guide-key/popup-window-position: %s"
guide-key/popup-window-position))))
(size (guide-key/popup-window-size
(spacemacs/horizontal-position-p
guide-key/popup-window-position)))
(window (funcall display-fn buffer alist size)))
(when window
(purpose-set-window-purpose-dedicated-p window t)
window)))

(defun spacemacs/sync-guide-key-and-window-purpose ()
(if guide-key-mode
(progn
(purpose-set-extension-configuration
:guide-key
(purpose-conf "guide-key"
:name-purposes
`((,guide-key/guide-buffer-name . guide-key))))
(add-to-list 'purpose-special-action-sequences
'(guide-key purpose-display-reuse-window-buffer
purpose-display-reuse-window-purpose
spacemacs/display-guide-key)))
(purpose-del-extension-configuration :guide-key)
(setq purpose-special-action-sequences
(cl-delete 'guide-key purpose-special-action-sequences
:key 'car))))

(defadvice guide-key/popup-guide-buffer
(around spacemacs/guide-buffer-with-window-purpose activate)
"Use window-purpose instead of popwin to popup guide-key buffer."
(if purpose--active-p
(or (display-buffer (get-buffer guide-key/guide-buffer-name))
ad-do-it)
(let ((buffer (get-buffer guide-key/guide-buffer-name)))
(or (purpose-display-reuse-window-buffer buffer nil)
(purpose-display-reuse-window-purpose buffer nil)
(spacemacs/display-guide-key buffer nil)
ad-do-it))))

(defadvice guide-key/close-guide-buffer
(around spacemacs/guide-buffer-with-window-purpose activate)
"Use window-purpose instead of popwin to close guide-key buffer."
(mapc 'delete-window (purpose-windows-with-purpose 'guide-key))
(guide-key/turn-off-idle-timer))

(defadvice guide-key-mode
(after spacemacs/guide-buffer-with-window-purpose activate)
(spacemacs/sync-guide-key-and-window-purpose))
(spacemacs/sync-guide-key-and-window-purpose)))

(evil-leader/set-key "tk" 'spacemacs/toggle-guide-key)
(setq guide-key/guide-key-sequence `("C-x"
"C-c"
Expand Down Expand Up @@ -2675,6 +2739,9 @@ displayed in the mode-line.")
windows))
(add-hook 'window-numbering-before-hook 'spacemacs//window-numbering-assign)))

(defun spacemacs/init-window-purpose ()
(use-package window-purpose))

(defun spacemacs/init-winner ()
(use-package winner
:init
Expand Down