Skip to content

Commit

Permalink
resize windows horizontally
Browse files Browse the repository at this point in the history
  • Loading branch information
papercatlol committed Sep 3, 2021
1 parent d6a29bf commit a2d81c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom/configure-lisp.el
Expand Up @@ -61,6 +61,8 @@ when cursor is directly inside the in-package form."
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)

(define-key paredit-mode-map (kbd "C-}") nil)
(define-key paredit-mode-map (kbd "C-{") nil)

;;* skip parens when reading symbol-at-point
(defun symbol-at-point--skip-parens (orig-fn &rest args)
Expand Down
43 changes: 43 additions & 0 deletions init.el
Expand Up @@ -1249,6 +1249,49 @@ enable `hydra-flyspell'."
(with-eval-after-load 'evil
(define-key custom-mode-map "n" 'evil-search-next))

;;* resize windows horizontally
(defun get-window-resize-delta ()
(if current-prefix-arg
(prefix-numeric-value current-prefix-arg)
4))

(defun window-right-aligned-p (&optional window)
"T if WINDOW's center is horizontally to the right of the
center of the frame."
(destructuring-bind (left top right bottom)
(window-edges window)
(let ((window-center (/ (+ left right) 2))
(frame-center (/ (frame-width) 2)))
(> window-center frame-center))))

(defun window-grow-horizontally (delta)
(interactive (list (get-window-resize-delta)))
(window-resize (selected-window) delta t))

(defun window-shrink-horizontally (delta)
(interactive (list (get-window-resize-delta)))
(window-grow-horizontally (- delta)))

(defun window-resize-left (delta)
"Grow window horizontally if it is right-aligned, otherwise
shrink it. Think 'drag window's left border to the left' (this
isn't that intuitive if you have more that two horizontal
windows)."
(interactive (list (get-window-resize-delta)))
(if (window-right-aligned-p)
(window-grow-horizontally delta)
(window-shrink-horizontally delta)))

(defun window-resize-right (delta)
"Inverse of `window-resize-left'."
(interactive (list (get-window-resize-delta)))
(if (window-right-aligned-p)
(window-shrink-horizontally delta)
(window-grow-horizontally delta)))

(global-set-key (kbd "C-}") 'window-resize-right)
(global-set-key (kbd "C-{") 'window-resize-left)

;;* keybindings
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "M-/") 'hippie-expand)
Expand Down

0 comments on commit a2d81c4

Please sign in to comment.