init-windows.el 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. ;;; init-windows.el --- Window/Buffer Configuration File -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;;; Code:
  4. (use-feature emacs
  5. :custom
  6. (switch-to-buffer-obey-display-actions t)
  7. (split-height-threshold nil)
  8. (split-width-threshold 200))
  9. (use-feature ibuffer
  10. :bind
  11. ("C-x M-b" . ibuffer)
  12. (:map ibuffer-mode-map
  13. ("{" . ibuffer-backwards-next-marked)
  14. ("}" . ibuffer-forward-next-marked)
  15. ("[" . ibuffer-backward-filter-group)
  16. ("]" . ibuffer-forward-filter-group)
  17. ("$" . ibuffer-toggle-filter-group))
  18. :hook (ibuffer-mode . ibuffer-auto-mode))
  19. (use-feature casual-ibuffer
  20. :after ibuffer
  21. :bind (:map ibuffer-mode-map
  22. ("C-o" . casual-ibuffer-tmenu)
  23. ("F" . casual-ibuffer-filter-tmenu)
  24. ("s" . casual-ibuffer-sortby-tmenu)))
  25. (use-feature winner
  26. :defer 5
  27. :custom (winner-boring-buffers-regexp "\*Minibuf-[0-9]+")
  28. :config
  29. (winner-mode +1)
  30. (defvar winner-repeat-map
  31. (let ((map (make-sparse-keymap)))
  32. (define-key map (kbd "<left>") #'winner-undo)
  33. (define-key map (kbd "<right>") #'winner-redo)
  34. map))
  35. (dolist (cmd '(winner-undo winner-redo))
  36. (put cmd 'repeat-map 'winner-repeat-map)))
  37. (use-feature windmove
  38. :defer 5
  39. :config (windmove-default-keybindings)
  40. :bind (("C-c M-<up>" . windmove-delete-up)
  41. ("C-c M-<down>" . windmove-delete-down)
  42. ("C-c M-<left>" . windmove-delete-left)
  43. ("C-c M-<right>" . windmove-delete-right)))
  44. (use-package buffer-move
  45. :bind (("C-S-<up>" . buf-move-up)
  46. ("C-S-<down>" . buf-move-down)
  47. ("C-S-<left>" . buf-move-left)
  48. ("C-S-<right>" . buf-move-right)))
  49. (use-feature uniquify
  50. :custom
  51. (uniquify-buffer-name-style 'forward))
  52. (use-package fullframe
  53. :defer 4
  54. :config
  55. (fullframe magit-status magit-mode-bury-buffer)
  56. (fullframe vc-annotate quit-window)
  57. (fullframe elpaca-fetch-all quit-window))
  58. (use-package transpose-frame
  59. :bind (:map ctl-x-4-map ("t" . transpose-frame)))
  60. (use-package ace-window
  61. :diminish
  62. :config
  63. (defun ace-window-always-dispatch (arg)
  64. "Call `ace-window' with `aw-dispatch-always' set to t, passing through `ARG'."
  65. (interactive "p")
  66. (let ((aw-dispatch-always t))
  67. (ace-window arg)))
  68. :bind
  69. ([remap other-window] . ace-window)
  70. ("C-x O" . ace-window-always-dispatch)
  71. :custom
  72. (aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
  73. :custom-face
  74. (aw-leading-char-face
  75. ((t (:foreground "white" :background "red"
  76. :weight bold :height 2.5 :box (:line-width 10 :color "red"))))))
  77. (use-package popper
  78. :bind (("M-`" . popper-toggle)
  79. ("M-¬" . popper-cycle)
  80. ("C-`" . popper-toggle-type))
  81. :custom
  82. (popper-group-function #'popper-group-by-perspective)
  83. (popper-reference-buffers
  84. '("\\*Messages\\*"
  85. "\\*HTTP Response\\*"
  86. "Output\\*$"
  87. "\\*Async Shell Command\\*"
  88. help-mode
  89. helpful-mode
  90. compilation-mode))
  91. :hook (elpaca-after-init . (lambda ()
  92. (popper-mode +1)
  93. (popper-echo-mode +1))))
  94. (use-package frog-jump-buffer
  95. :config
  96. (defun frog-jump-buffer-filter-buffer-ring (buffer)
  97. "Check if a BUFFER is in current buffer ring."
  98. (let ((bfr-ring (buffer-ring-current-ring)))
  99. (when bfr-ring
  100. (let ((ring (buffer-ring-ring-ring bfr-ring)))
  101. (unless (dynaring-empty-p ring)
  102. (dynaring-contains-p ring (buffer-ring--parse-buffer buffer)))))))
  103. (defun frog-jump-buffer-filter-same-mode-in-persp (buffer)
  104. "Check if a BUFFER is the same as the current major mode and perspective."
  105. (let ((current-mode major-mode))
  106. (and
  107. (with-current-buffer buffer
  108. (eq major-mode current-mode))
  109. (persp-is-current-buffer buffer))))
  110. (defun frog-jump-buffer-filter-persp-buffer-ring-or-same-mode (buffer)
  111. "Check if BUFFER is in the buffer-ring, falling back to persp + major mode."
  112. (let* ((bfr-ring (buffer-ring-current-ring))
  113. (ring (buffer-ring-ring-ring bfr-ring)))
  114. (if (dynaring-empty-p ring)
  115. (frog-jump-buffer-filter-same-mode-in-persp buffer)
  116. (frog-jump-buffer-filter-buffer-ring buffer))))
  117. (set-face-background 'frog-menu-posframe-background-face "black")
  118. (setq frog-jump-buffer-include-current-buffer nil
  119. frog-jump-buffer-default-filter 'frog-jump-buffer-filter-persp-buffer-ring-or-same-mode
  120. frog-jump-buffer-use-default-filter-actions nil
  121. frog-jump-buffer-filter-actions '(("A" "[all]" frog-jump-buffer-filter-all)
  122. ("M" "[mode]" frog-jump-buffer-filter-same-mode-in-persp)
  123. ("F" "[files]" frog-jump-buffer-filter-file-buffers)
  124. ("R" "[recentf]" frog-jump-buffer-filter-recentf) ;; TODO filter/replace frog-jump-buffer-recentf-buffers
  125. ("B" "[ring]" frog-jump-buffer-filter-buffer-ring)
  126. ("P" "[project]" frog-jump-buffer-filter-same-project)
  127. ("S" "[similar]" frog-jump-buffer-filter-similar-name)))
  128. :bind
  129. ("C-c C-," . frog-jump-buffer)
  130. ("C-x 4 C-," . frog-jump-buffer-other-window))
  131. (use-package buffer-ring
  132. :diminish
  133. :config
  134. (defun persp-buffer-ring-create-and-switch ()
  135. "Create and switch to the buffer-ring for the current perspective."
  136. ;; Creating a ring automatically switches to it
  137. (buffer-ring-torus--create-ring (persp-current-name)))
  138. (defun persp-buffer-ring-switch ()
  139. "Switch to the buffer-ring for the current perspective."
  140. (buffer-ring-torus-switch-to-ring (persp-current-name)))
  141. ;; This is mostly just a convenience, to stop buffer-ring from prompting for the ring to use
  142. (defun persp-buffer-ring-add-buffer ()
  143. "Add the current buffer to ring for the current perspective."
  144. (interactive)
  145. (let ((inhibit-message t))
  146. (buffer-ring-add (persp-current-name))))
  147. :hook
  148. (elpaca-after-init . buffer-ring-mode)
  149. (persp-created . persp-buffer-ring-create-and-switch)
  150. (persp-switch . persp-buffer-ring-switch)
  151. :bind
  152. (:map buffer-ring-mode-map
  153. ("C-c C-b a" . persp-buffer-ring-add-buffer)
  154. ("C-<" . buffer-ring-prev-buffer)
  155. ("C->" . buffer-ring-next-buffer)))
  156. (use-package buffer-flip
  157. :custom (buffer-flip-skip-patterns '("^[*]"))
  158. :config
  159. (defun persp-buffer-flip-skip-buffer (orig &rest args)
  160. (or (apply orig args)
  161. (persp-buffer-filter (car args))))
  162. (advice-add 'buffer-flip-skip-buffer :around 'persp-buffer-flip-skip-buffer)
  163. :bind (("C-c C-<left>" . buffer-flip)
  164. (:map buffer-flip-map
  165. ( "C-<left>" . buffer-flip-forward)
  166. ( "C-<right>" . buffer-flip-backward)
  167. ( "C-g" . buffer-flip-abort))))
  168. (use-package iflipb
  169. :config
  170. (defun iflipb-persp-buffer-list ()
  171. "Buffer list for iflipb."
  172. (seq-filter 'buffer-live-p (persp-current-buffers* t)))
  173. (defun iflibp-abort ()
  174. "Abort buffer flipping and return to the original buffer."
  175. (interactive)
  176. (iflipb-restore-buffers))
  177. (defun iflipb-kill-current-buffer ()
  178. "Same as `kill-current-buffer' but keep the iflipb buffer list state.
  179. Modified from `iflipb-kill-buffer'."
  180. (interactive)
  181. (call-interactively #'kill-current-buffer)
  182. (if (iflipb-first-iflipb-buffer-switch-command)
  183. (setq last-command 'kill-current-buffer)
  184. (if (< iflipb-current-buffer-index (length (iflipb-interesting-buffers)))
  185. (iflipb-select-buffer iflipb-current-buffer-index)
  186. (iflipb-select-buffer (1- iflipb-current-buffer-index)))
  187. (setq last-command 'iflipb-kill-current-buffer)))
  188. :custom (iflipb-buffer-list-function 'iflipb-persp-buffer-list)
  189. :bind
  190. ("C-x k" . iflipb-kill-current-buffer)
  191. ("<f12>" . iflipb-previous-buffer)
  192. ("<f11>" . iflipb-next-buffer)
  193. ("<f10>" . iflibp-abort))
  194. (provide 'init-windows)
  195. ;;; init-windows.el ends here