Guest User

Untitled

a guest
Mar 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. (defun split-window-sensibly-prefer-horizontal (&optional window)
  2. "Based on split-window-sensibly, but designed to prefer a horizontal split,
  3. i.e. windows tiled side-by-side."
  4. (let ((window (or window (selected-window))))
  5. (or (and (window-splittable-p window t)
  6. ;; Split window horizontally
  7. (with-selected-window window
  8. (split-window-right)))
  9. (and (window-splittable-p window)
  10. ;; Split window vertically
  11. (with-selected-window window
  12. (split-window-below)))
  13. (and
  14. ;; If WINDOW is the only usable window on its frame (it is
  15. ;; the only one or, not being the only one, all the other
  16. ;; ones are dedicated) and is not the minibuffer window, try
  17. ;; to split it horizontally disregarding the value of
  18. ;; `split-height-threshold'.
  19. (let ((frame (window-frame window)))
  20. (or
  21. (eq window (frame-root-window frame))
  22. (catch 'done
  23. (walk-window-tree (lambda (w)
  24. (unless (or (eq w window)
  25. (window-dedicated-p w))
  26. (throw 'done nil)))
  27. frame)
  28. t)))
  29. (not (window-minibuffer-p window))
  30. (let ((split-width-threshold 0))
  31. (when (window-splittable-p window t)
  32. (with-selected-window window
  33. (split-window-right))))))))
  34.  
  35. (defun split-window-really-sensibly (&optional window)
  36. (let ((window (or window (selected-window))))
  37. (if (> (window-total-width window) (* 2 (window-total-height window)))
  38. (with-selected-window window (split-window-sensibly-prefer-horizontal window))
  39. (with-selected-window window (split-window-sensibly window)))))
  40.  
  41. (setq
  42. split-height-threshold 4
  43. split-width-threshold 40
  44. split-window-preferred-function 'split-window-really-sensibly)
Add Comment
Please, Sign In to add comment