dkellner-windows-and-navigation.el 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ;; dkellner-windows-and-navigation.el
  2. (use-package shackle
  3. :config
  4. (setq shackle-rules
  5. '((("^\\*Capture\\*$"
  6. "^CAPTURE.*\\.org$"
  7. "^\\*eshell")
  8. :regexp t
  9. :custom dkellner/shackle-dynamic-split)))
  10. (shackle-mode 1))
  11. ;; see https://emacs.stackexchange.com/a/37652
  12. (defun dkellner/shackle-smart-split-dir ()
  13. (if (>= (window-pixel-height)
  14. (window-pixel-width))
  15. 'below
  16. 'right))
  17. (defun dkellner/shackle-dynamic-split (buffer alist plist)
  18. (let
  19. ((frame (shackle--splittable-frame))
  20. (window (if (eq (dkellner/shackle-smart-split-dir) 'below)
  21. (split-window-below)
  22. (split-window-right))))
  23. (prog1
  24. (window--display-buffer buffer window
  25. 'window alist display-buffer-mark-dedicated)
  26. (when window
  27. (setq shackle-last-window window
  28. shackle-last-buffer buffer))
  29. (unless (cdr (assq 'inhibit-switch-frame alist))
  30. (window--maybe-raise-frame frame)))))
  31. ;; from https://github.com/hlissner/doom-emacs/blob/master/core/core-popups.el
  32. (defun dkellner/suppress-delete-other-windows (orig-fn &rest args)
  33. (cl-letf (((symbol-function 'delete-other-windows)
  34. (symbol-function 'ignore)))
  35. (apply orig-fn args)))
  36. (advice-add #'org-capture-place-template
  37. :around #'dkellner/suppress-delete-other-windows)
  38. (defun dkellner/org-pop-to-buffer (&rest args)
  39. "Use `pop-to-buffer' instead of `switch-to-buffer' to open buffer.'"
  40. (let ((buf (car args)))
  41. (pop-to-buffer
  42. (cond ((stringp buf) (get-buffer-create buf))
  43. ((bufferp buf) buf)
  44. (t (error "Invalid buffer %s" buf))))))
  45. (advice-add #'org-switch-to-buffer-other-window
  46. :override #'dkellner/org-pop-to-buffer)
  47. ;; Enable winner-mode and enhance its functionality by making the keybindings
  48. ;; "sticky" - i.e. let you press C-c <left> to undo once, and then just <left>
  49. ;; for another undo, and so on.
  50. (winner-mode 1)
  51. (defhydra dkellner/winner-undo (:body-pre (winner-undo))
  52. ("<left>" winner-undo)
  53. ("<right>" winner-redo))
  54. (bind-key* "C-c <left>" #'dkellner/winner-undo/body)
  55. (provide 'dkellner-windows-and-navigation)