Reformat popup library: move polyfills down

This commit is contained in:
Henrik Lissner 2018-06-17 02:07:14 +02:00
parent a6116c6547
commit d31052d9db
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -478,101 +478,6 @@ prevent the popup(s) from messing up the UI (or vice versa)."
prevent the popup(s) from messing up the UI (or vice versa)." prevent the popup(s) from messing up the UI (or vice versa)."
(save-popups! (apply orig-fn args))) (save-popups! (apply orig-fn args)))
;;
;; Popup actions
;;
(unless EMACS26+
(defvar window-sides-reversed nil)
(defun window--sides-reverse-on-frame-p (frame)
"Return non-nil when side windows should appear reversed on FRAME.
This uses some heuristics to guess the user's intentions when the
selected window of FRAME is a side window ."
(cond
;; Reverse when `window-sides-reversed' is t. Do not reverse when
;; `window-sides-reversed' is nil.
((memq window-sides-reversed '(nil t))
window-sides-reversed)
;; Reverse when FRAME's selected window shows a right-to-left buffer.
((let ((window (frame-selected-window frame)))
(when (and (not (window-parameter window 'window-side))
(or (not (window-minibuffer-p window))
(setq window (minibuffer-selected-window))))
(with-current-buffer (window-buffer window)
(eq bidi-paragraph-direction 'right-to-left)))))
;; Reverse when FRAME's `window-sides-main-selected-window' parameter
;; specifies a live window showing a right-to-left buffer.
((let ((window (frame-parameter
frame 'window-sides-main-selected-window)))
(when (window-live-p window)
(with-current-buffer (window-buffer window)
(eq bidi-paragraph-direction 'right-to-left)))))
;; Reverse when all windows in FRAME's main window show right-to-left
;; buffers.
(t
(catch 'found
(walk-window-subtree
(lambda (window)
(with-current-buffer (window-buffer window)
(when (eq bidi-paragraph-direction 'left-to-right)
(throw 'found nil))))
(window-main-window frame))
t))))
(defun window--make-major-side-window (buffer side slot &optional alist)
"Display BUFFER in a new major side window on the selected frame.
SIDE must be one of `left', `top', `right' or `bottom'. SLOT
specifies the slot to use. ALIST is an association list of
symbols and values as passed to `display-buffer-in-side-window'.
Return the new window, nil if its creation failed.
This is an auxiliary function of `display-buffer-in-side-window'
and may be called only if no window on SIDE exists yet."
(let* ((left-or-right (memq side '(left right)))
(next-to (window--make-major-side-window-next-to side))
(on-side (cond
((eq side 'top) 'above)
((eq side 'bottom) 'below)
(t side)))
(window--sides-inhibit-check t)
;; The following two bindings will tell `split-window' to take
;; the space for the new window from the selected frame's main
;; window and not make a new parent window unless needed.
(window-combination-resize 'side)
(window-combination-limit nil)
(window (ignore-errors (split-window next-to nil on-side))))
(when window
;; Initialize `window-side' parameter of new window to SIDE and
;; make that parameter persistent.
(set-window-parameter window 'window-side side)
(map-put window-persistent-parameters 'window-side 'writable)
;; Install `window-slot' parameter of new window and make that
;; parameter persistent.
(set-window-parameter window 'window-slot slot)
(map-put window-persistent-parameters 'window-slot 'writable)
;; Auto-adjust height/width of new window unless a size has been
;; explicitly requested.
(unless (if left-or-right
(cdr (assq 'window-width alist))
(cdr (assq 'window-height alist)))
(setq alist
(cons
(cons
(if left-or-right 'window-width 'window-height)
(/ (window-total-size (frame-root-window) left-or-right)
;; By default use a fourth of the size of the frame's
;; root window.
4))
alist)))
(with-current-buffer buffer
(setq window--sides-shown t))
;; Install BUFFER in new window and return WINDOW.
(window--display-buffer buffer window 'window alist 'side))))
(advice-add #'window--sides-check :override #'ignore))
;;;###autoload ;;;###autoload
(defun +popup-display-buffer-stacked-side-window (buffer alist) (defun +popup-display-buffer-stacked-side-window (buffer alist)
"A `display-buffer' action that serves as an alternative to "A `display-buffer' action that serves as an alternative to
@ -701,3 +606,98 @@ Accepts the same arguments as `display-buffer-in-side-window'. You must set
(setq window--sides-shown t)) (setq window--sides-shown t))
(window--display-buffer (window--display-buffer
buffer best-window 'reuse alist dedicated))))))))) buffer best-window 'reuse alist dedicated)))))))))
;;
;; Emacs backwards compatibility
;;
(unless EMACS26+
(defvar window-sides-reversed nil)
(defun window--sides-reverse-on-frame-p (frame)
"Return non-nil when side windows should appear reversed on FRAME.
This uses some heuristics to guess the user's intentions when the
selected window of FRAME is a side window ."
(cond
;; Reverse when `window-sides-reversed' is t. Do not reverse when
;; `window-sides-reversed' is nil.
((memq window-sides-reversed '(nil t))
window-sides-reversed)
;; Reverse when FRAME's selected window shows a right-to-left buffer.
((let ((window (frame-selected-window frame)))
(when (and (not (window-parameter window 'window-side))
(or (not (window-minibuffer-p window))
(setq window (minibuffer-selected-window))))
(with-current-buffer (window-buffer window)
(eq bidi-paragraph-direction 'right-to-left)))))
;; Reverse when FRAME's `window-sides-main-selected-window' parameter
;; specifies a live window showing a right-to-left buffer.
((let ((window (frame-parameter
frame 'window-sides-main-selected-window)))
(when (window-live-p window)
(with-current-buffer (window-buffer window)
(eq bidi-paragraph-direction 'right-to-left)))))
;; Reverse when all windows in FRAME's main window show right-to-left
;; buffers.
(t
(catch 'found
(walk-window-subtree
(lambda (window)
(with-current-buffer (window-buffer window)
(when (eq bidi-paragraph-direction 'left-to-right)
(throw 'found nil))))
(window-main-window frame))
t))))
(defun window--make-major-side-window (buffer side slot &optional alist)
"Display BUFFER in a new major side window on the selected frame.
SIDE must be one of `left', `top', `right' or `bottom'. SLOT
specifies the slot to use. ALIST is an association list of
symbols and values as passed to `display-buffer-in-side-window'.
Return the new window, nil if its creation failed.
This is an auxiliary function of `display-buffer-in-side-window'
and may be called only if no window on SIDE exists yet."
(let* ((left-or-right (memq side '(left right)))
(next-to (window--make-major-side-window-next-to side))
(on-side (cond
((eq side 'top) 'above)
((eq side 'bottom) 'below)
(t side)))
(window--sides-inhibit-check t)
;; The following two bindings will tell `split-window' to take
;; the space for the new window from the selected frame's main
;; window and not make a new parent window unless needed.
(window-combination-resize 'side)
(window-combination-limit nil)
(window (ignore-errors (split-window next-to nil on-side))))
(when window
;; Initialize `window-side' parameter of new window to SIDE and
;; make that parameter persistent.
(set-window-parameter window 'window-side side)
(map-put window-persistent-parameters 'window-side 'writable)
;; Install `window-slot' parameter of new window and make that
;; parameter persistent.
(set-window-parameter window 'window-slot slot)
(map-put window-persistent-parameters 'window-slot 'writable)
;; Auto-adjust height/width of new window unless a size has been
;; explicitly requested.
(unless (if left-or-right
(cdr (assq 'window-width alist))
(cdr (assq 'window-height alist)))
(setq alist
(cons
(cons
(if left-or-right 'window-width 'window-height)
(/ (window-total-size (frame-root-window) left-or-right)
;; By default use a fourth of the size of the frame's
;; root window.
4))
alist)))
(with-current-buffer buffer
(setq window--sides-shown t))
;; Install BUFFER in new window and return WINDOW.
(window--display-buffer buffer window 'window alist 'side))))
(advice-add #'window--sides-check :override #'ignore))