Consistent window commands
I like both my leader and ace-window for different reasons, and I need them to be consistent. Also, I want to split a window and immediately see a file or buffer.
This commit is contained in:
		
							parent
							
								
									b0d528d5d9
								
							
						
					
					
						commit
						fa30322b23
					
				
					 2 changed files with 118 additions and 50 deletions
				
			
		
							
								
								
									
										145
									
								
								ha-config.org
									
									
									
									
									
								
							
							
						
						
									
										145
									
								
								ha-config.org
									
									
									
									
									
								
							|  | @ -772,17 +772,30 @@ While it comes with Emacs, I use [[https://www.emacswiki.org/emacs/WinnerMode][w | ||||||
|     :config |     :config | ||||||
|     (winner-mode +1)) |     (winner-mode +1)) | ||||||
| #+end_src | #+end_src | ||||||
|  | 
 | ||||||
| Use the [[https://github.com/abo-abo/ace-window][ace-window]] project to jump to any window you see: | Use the [[https://github.com/abo-abo/ace-window][ace-window]] project to jump to any window you see: | ||||||
| #+begin_src emacs-lisp | #+begin_src emacs-lisp | ||||||
|   (use-package ace-window |   (use-package ace-window | ||||||
|  |     :init | ||||||
|  |     ;; Since I use numbers for the window, I can make the | ||||||
|  |     ;; commands more mnemonic: | ||||||
|  |     (setq aw-dispatch-alist | ||||||
|  |           '((?d aw-delete-window "Delete Window") | ||||||
|  |             (?m aw-swap-window "Swap Windows") | ||||||
|  |             (?M aw-move-window "Move Window") | ||||||
|  |             (?c aw-copy-window "Copy Window") | ||||||
|  |             (?j aw-switch-buffer-in-window "Select Buffer") | ||||||
|  |             (?n aw-flip-window) | ||||||
|  |             (?u aw-switch-buffer-other-window "Switch Buffer Other Window") | ||||||
|  |             (?c aw-split-window-fair "Split Fair Window") | ||||||
|  |             (?s aw-split-window-vert "Split Vert Window") | ||||||
|  |             (?v aw-split-window-horz "Split Horz Window") | ||||||
|  |             (?o delete-other-windows "Delete Other Windows") | ||||||
|  |             (?? aw-show-dispatch-help))) | ||||||
|  | 
 | ||||||
|     :bind ("s-w" . ace-window)) |     :bind ("s-w" . ace-window)) | ||||||
| #+end_src | #+end_src | ||||||
| This package, bound to ~SPC w w~, also allows operations specified before choosing the window: | Keep in mind, these shortcuts work with more than two windows open. For instance, ~SPC w w d 3~ closes the "3" window. | ||||||
| - ~x~ - delete window |  | ||||||
| - ~m~ - swap windows, which allows you to place the current buffer in any other window |  | ||||||
| - ~j~ - switch to a buffer in any other window |  | ||||||
| - ~?~ - show the rest of the command bindings |  | ||||||
| Keep in mind, these shortcuts work with more than two windows open. For instance, ~SPC w w x 3~ closes the "3" window. |  | ||||||
| 
 | 
 | ||||||
| To jump to a window even quicker, use the [[https://github.com/deb0ch/emacs-winum][winum package]]: | To jump to a window even quicker, use the [[https://github.com/deb0ch/emacs-winum][winum package]]: | ||||||
| #+begin_src emacs-lisp | #+begin_src emacs-lisp | ||||||
|  | @ -790,16 +803,7 @@ To jump to a window even quicker, use the [[https://github.com/deb0ch/emacs-winu | ||||||
|     :config |     :config | ||||||
|     (winum-mode +1)) |     (winum-mode +1)) | ||||||
| #+end_src | #+end_src | ||||||
| And when creating new windows, why isn't the new window selected? |  | ||||||
| #+begin_src emacs-lisp |  | ||||||
|   (defun jump-to-new-window (&rest _arg) |  | ||||||
|     "Advice function to jump to newly spawned window." |  | ||||||
|     (other-window 1)) |  | ||||||
| 
 | 
 | ||||||
|   (dolist (command '(split-window-below split-window-right |  | ||||||
|                                         evil-window-split evil-window-vsplit)) |  | ||||||
|     (advice-add command :after #'jump-to-new-window)) |  | ||||||
| #+end_src |  | ||||||
| This is nice since the window numbers are always present on a Doom modeline, but they order the window numbers /differently/ than =ace-window=. Let's see which I end up liking better. | This is nice since the window numbers are always present on a Doom modeline, but they order the window numbers /differently/ than =ace-window=. Let's see which I end up liking better. | ||||||
| 
 | 
 | ||||||
| The ~0~ key/window should be always associated with a project-specific tree window: | The ~0~ key/window should be always associated with a project-specific tree window: | ||||||
|  | @ -815,44 +819,49 @@ Let's try this out with a Hydra since some I can /repeat/ some commands (e.g. en | ||||||
|     :config |     :config | ||||||
|     (defhydra hydra-window-resize (:color blue :hint nil) " |     (defhydra hydra-window-resize (:color blue :hint nil) " | ||||||
|   _w_: select _m_: move/swap _u_: undo  _^_: taller (t)  _+_: text larger |   _w_: select _m_: move/swap _u_: undo  _^_: taller (t)  _+_: text larger | ||||||
|   _j_: go up  _x_: delete    _U_: undo+ _V_: shorter (T) _-_: text smaller |   _j_: go up  _d_: delete    _U_: undo+ _v_: shorter (T) _-_: text smaller | ||||||
|   _k_: down   _e_: balance   _r_: redo  _>_: wider       _F_: font larger |   _k_: down   _e_: balance   _r_: redo  _>_: wider       _F_: font larger | ||||||
|   _h_: left   _b_: h-split   _R_: redo+ _<_: narrower    _f_: font smaller |   _h_: left   _w_: h-split   _R_: redo+ _<_: narrower    _f_: font smaller | ||||||
|   _l_: right  _v_: v-split   _o_: only this window     _c_: choose (also 1-9) |   _l_: right  _s_: v-split   _o_: only this window     _c_: choose (also 1-9)" | ||||||
|   " |  | ||||||
|       ("w" ace-window) |       ("w" ace-window) | ||||||
|       ("c" other-window :color pink)      ; change window |       ("c" other-window                 :color pink) ; change window | ||||||
|       ("o" delete-other-windows)          ; Only this window |       ("o" delete-other-windows)          ; Only this window | ||||||
|       ("x" delete-window) |       ("d" delete-window)     ("x" delete-window) | ||||||
|       ("D" ace-delete-window) |       ("D" ace-delete-window) | ||||||
| 
 | 
 | ||||||
|       ("m" ace-swap-window) |       ("m" ace-swap-window) | ||||||
|       ("u" winner-undo) |       ("u" winner-undo) | ||||||
|       ("U" winner-undo :color pink) |       ("U" winner-undo                 :color pink) | ||||||
|       ("C-r" winner-redo) |       ("C-r" winner-redo) | ||||||
|       ("r" winner-redo) |       ("r" winner-redo) | ||||||
|       ("R" winner-redo :color pink) |       ("R" winner-redo                 :color pink) | ||||||
| 
 | 
 | ||||||
|       ("n" evil-window-new) |       ("n" evil-window-new) | ||||||
|       ("j" evil-window-up :color pink) |       ("j" evil-window-down            :color pink) | ||||||
|       ("k" evil-window-down :color pink) |       ("J" evil-window-down) | ||||||
|       ("h" evil-window-left :color pink) |       ("k" evil-window-up              :color pink) | ||||||
|       ("l" evil-window-right :color pink) |       ("K" evil-window-up) | ||||||
|  |       ("h" evil-window-left            :color pink) | ||||||
|  |       ("H" evil-window-left) | ||||||
|  |       ("l" evil-window-right           :color pink) | ||||||
|  |       ("L" evil-window-right) | ||||||
| 
 | 
 | ||||||
|       ("b" evil-window-split)     ; For below |       ("w" hydra-window-split-h/body)  ; Why `w', Why not? | ||||||
|       ("v" evil-window-vsplit) |       ("s" hydra-window-split-v/body) | ||||||
| 
 | 
 | ||||||
|       ("F" font-size-increase :color pink) |       ("F" font-size-increase          :color pink) | ||||||
|       ("f" font-size-decrease :color pink) |       ("f" font-size-decrease          :color pink) | ||||||
|       ("+" text-scale-increase :color pink) |       ("+" text-scale-increase         :color pink) | ||||||
|       ("=" text-scale-increase :color pink) |       ("=" text-scale-increase         :color pink) | ||||||
|       ("-" text-scale-decrease :color pink) |       ("-" text-scale-decrease         :color pink) | ||||||
|       ("^" evil-window-increase-height :color pink) |       ("^" evil-window-increase-height :color pink) | ||||||
|       ("V" evil-window-decrease-height :color pink) |       ("v" evil-window-decrease-height :color pink) | ||||||
|       ("t" evil-window-increase-height :color pink) |       ("t" evil-window-increase-height :color pink) | ||||||
|       ("T" evil-window-decrease-height :color pink) |       ("T" evil-window-decrease-height :color pink) | ||||||
|       (">" evil-window-increase-width :color pink) |       (">" evil-window-increase-width  :color pink) | ||||||
|       ("<" evil-window-decrease-width :color pink) |       ("<" evil-window-decrease-width  :color pink) | ||||||
|  |       ("." evil-window-increase-width  :color pink) | ||||||
|  |       ("," evil-window-decrease-width  :color pink) | ||||||
|       ("e" balance-windows) |       ("e" balance-windows) | ||||||
| 
 | 
 | ||||||
|       ("1" winum-select-window-1) |       ("1" winum-select-window-1) | ||||||
|  | @ -867,14 +876,68 @@ Let's try this out with a Hydra since some I can /repeat/ some commands (e.g. en | ||||||
|       ("0" neotree-toggle) |       ("0" neotree-toggle) | ||||||
| 
 | 
 | ||||||
|       ;; Extra bindings: |       ;; Extra bindings: | ||||||
|       ("t" evil-window-increase-height :color pink) |  | ||||||
|       ("T" evil-window-decrease-height :color pink) |  | ||||||
|       ("." evil-window-increase-width :color pink) |  | ||||||
|       ("," evil-window-decrease-width :color pink) |  | ||||||
|       ("q" nil :color blue))) |       ("q" nil :color blue))) | ||||||
| 
 | 
 | ||||||
|   (ha-leader "w" '("windows" . hydra-window-resize/body)) |   (ha-leader "w" '("windows" . hydra-window-resize/body)) | ||||||
| #+end_src | #+end_src | ||||||
|  | **** Window Splitting | ||||||
|  | When I split a window, I have a following intentions: | ||||||
|  |   - Split and open a file from the prespective/project in the new window | ||||||
|  |   - Split and change to a buffer from the prespective in the new window | ||||||
|  |   - Split and move focus to the new window … you know, to await a new command | ||||||
|  | 
 | ||||||
|  | And when creating new windows, why isn't the new window selected? Also, when I create a new window, I typically want a different buffer or file shown. | ||||||
|  | #+begin_src emacs-lisp | ||||||
|  |   (defun ha-new-window (side file-or-buffer) | ||||||
|  |     (pcase side | ||||||
|  |       (:left  (split-window-horizontally)) | ||||||
|  |       (:right (split-window-horizontally) | ||||||
|  |               (other-window 1)) | ||||||
|  |       (:above (split-window-vertically)) | ||||||
|  |       (:below (split-window-vertically) | ||||||
|  |               (other-window 1))) | ||||||
|  |     (pcase file-or-buffer | ||||||
|  |       (:file   (call-interactively 'consult-projectile-find-file)) | ||||||
|  |       (:buffer (call-interactively 'consult-projectile-switch-to-buffer)))) | ||||||
|  | #+end_src | ||||||
|  | 
 | ||||||
|  | Shame that hydra doesn’t have an /ignore-case/ feature. | ||||||
|  | #+begin_src emacs-lisp | ||||||
|  |   (use-package hydra | ||||||
|  |     :config | ||||||
|  |     (defhydra hydra-window-split-above (:color blue :hint nil) | ||||||
|  |       ("b" (lambda () (interactive) (ha-new-window :above :buffer))        "switch buffer") | ||||||
|  |       ("B" (lambda () (interactive) (ha-new-window :above :buffer))        "switch buffer") | ||||||
|  |       ("f" (lambda () (interactive) (ha-new-window :above :file))          "load file") | ||||||
|  |       ("F" (lambda () (interactive) (ha-new-window :above :file))          "load file") | ||||||
|  |       ("k" split-window-below                                         "split window") | ||||||
|  |       ("K" split-window-below                                         "split window")) | ||||||
|  | 
 | ||||||
|  |     (defhydra hydra-window-split-below (:color blue :hint nil) | ||||||
|  |       ("b" (lambda () (interactive) (ha-new-window :below :buffer))        "switch buffer") | ||||||
|  |       ("B" (lambda () (interactive) (ha-new-window :below :buffer))        "switch buffer") | ||||||
|  |       ("f" (lambda () (interactive) (ha-new-window :below :file))          "load file    ") | ||||||
|  |       ("F" (lambda () (interactive) (ha-new-window :below :file))          "load file    ") | ||||||
|  |       ("j" (lambda () (interactive) (split-window-below) (other-window 1)) "split window ") | ||||||
|  |       ("J" (lambda () (interactive) (split-window-below) (other-window 1)) "split window ")) | ||||||
|  | 
 | ||||||
|  |     (defhydra hydra-window-split-right (:color blue :hint nil) | ||||||
|  |       ("b" (lambda () (interactive) (ha-new-window :right :buffer))        "switch buffer") | ||||||
|  |       ("B" (lambda () (interactive) (ha-new-window :right :buffer))        "switch buffer") | ||||||
|  |       ("f" (lambda () (interactive) (ha-new-window :right :file))          "load file") | ||||||
|  |       ("F" (lambda () (interactive) (ha-new-window :right :file))          "load file") | ||||||
|  |       ("l" split-window-left                                         "split window") | ||||||
|  |       ("L" split-window-left                                         "split window")) | ||||||
|  | 
 | ||||||
|  |     (defhydra hydra-window-split-left (:color blue :hint nil) | ||||||
|  |       ("b" (lambda () (interactive) (ha-new-window :left :buffer))        "switch buffer") | ||||||
|  |       ("B" (lambda () (interactive) (ha-new-window :left :buffer))        "switch buffer") | ||||||
|  |       ("f" (lambda () (interactive) (ha-new-window :left :file))          "load file    ") | ||||||
|  |       ("F" (lambda () (interactive) (ha-new-window :left :file))          "load file    ") | ||||||
|  |       ("h" (lambda () (interactive) (split-window-left) (other-window 1)) "split window ") | ||||||
|  |       ("H" (lambda () (interactive) (split-window-left) (other-window 1)) "split window "))) | ||||||
|  | #+end_src | ||||||
|  | 
 | ||||||
| *** Search Operations | *** Search Operations | ||||||
| Ways to search for information goes under the ~s~ key. The venerable sage has always been =grep=, but we now have new-comers, like [[https://github.com/BurntSushi/ripgrep][ripgrep]], which are really fast. | Ways to search for information goes under the ~s~ key. The venerable sage has always been =grep=, but we now have new-comers, like [[https://github.com/BurntSushi/ripgrep][ripgrep]], which are really fast. | ||||||
| **** ripgrep | **** ripgrep | ||||||
|  |  | ||||||
|  | @ -56,18 +56,22 @@ Large screen, lots of windows, so where is the cursor? While I used to use =hl-l | ||||||
|                               other-window |                               other-window | ||||||
|                               delete-window |                               delete-window | ||||||
|                               delete-other-windows |                               delete-other-windows | ||||||
|  |                               aw-delete-window | ||||||
|                               forward-page |                               forward-page | ||||||
|                               backward-page |                               backward-page | ||||||
|                               scroll-up-command |                               scroll-up-command | ||||||
|                               scroll-down-command |                               scroll-down-command | ||||||
|                               windmove-right |                               evil-window-right | ||||||
|                               windmove-left |                               evil-window-left | ||||||
|                               windmove-up |                               evil-window-up | ||||||
|                               windmove-down |                               evil-window-down | ||||||
|                               windmove-swap-states-right |                               aw-move-window | ||||||
|                               windmove-swap-states-left |                               aw-swap-window | ||||||
|                               windmove-swap-states-up |                               aw-copy-window | ||||||
|                               windmove-swap-states-down |                               aw-split-window-vert | ||||||
|  |                               aw-split-window-horz | ||||||
|  |                               aw-split-window-fair | ||||||
|  |                               ha-new-window | ||||||
|                               winum-select-window-1 |                               winum-select-window-1 | ||||||
|                               winum-select-window-2 |                               winum-select-window-2 | ||||||
|                               winum-select-window-3 |                               winum-select-window-3 | ||||||
|  | @ -93,7 +97,8 @@ Large screen, lots of windows, so where is the cursor? While I used to use =hl-l | ||||||
|                               outline-up-heading)) |                               outline-up-heading)) | ||||||
|     (pulsar-face 'pulsar-magenta) |     (pulsar-face 'pulsar-magenta) | ||||||
|     (pulsar-delay 0.055) |     (pulsar-delay 0.055) | ||||||
|     :bind ("<f6>" . pulsar-pulse-line)) |     :bind ("<f6>" . pulsar-pulse-line) | ||||||
|  |     :config (pulsar-global-mode)) | ||||||
| #+end_src | #+end_src | ||||||
| * Themes | * Themes | ||||||
| One does get used to a particular collection of colors. Mine is Tomorrow: | One does get used to a particular collection of colors. Mine is Tomorrow: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue