aboutsummaryrefslogtreecommitdiffstats
path: root/elpa/switch-window-20210808.742/switch-window-mvborder.el
blob: b6bb77042a528856793df1db1415accb9a5ca524 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;;; switch-window-mvborder.el --- Move border of emacs window.     -*- lexical-binding: t -*-

;; * Header
;; Copyright (c) the unknown original author

;; I found the original code on a blog where the blog author
;; is also saying that he is not the author.
;; So, no one knows who is the author.

;; If you are the author, please send me a word.

;; Author: Unknown
;; URL: https://www.emacswiki.org/emacs/WindowResize
;;      https://www.emacswiki.org/emacs/GrowShrinkWindows
;;      https://github.com/ramnes/move-border
;;

;;; Commentary:

;;; Code:

;; * Code                                                                 :code:

(defcustom switch-window-mvborder-increment 5
  "A value to resize the window by when no prefix is specified."
  :type 'integer
  :group 'switch-window)

(defun switch-window--xor (b1 b2)
  (or (and b1 b2)
      (and (not b1) (not b2))))

(defun switch-window--mvborder-left-or-right (arg dir)
  "General function covering switch-window-mvborder-left and switch-window-mvborder-right.
If DIR is t, then move left, otherwise move right."
  (when (null arg)
    (setq arg switch-window-mvborder-increment))
  (let ((left-edge (nth 0 (window-edges))))
    (if (switch-window--xor (= left-edge 0) dir)
        (shrink-window arg t)
      (enlarge-window arg t))))

(defun switch-window--mvborder-up-or-down (arg dir)
  "General function covering switch-window-mvborder-up and switch-window-mvborder-down.
If DIR is t, then move up, otherwise move down."
  (when (null arg)
    (setq arg switch-window-mvborder-increment))
  (let ((top-edge (nth 1 (window-edges))))
    (if (switch-window--xor (= top-edge 0) dir)
        (shrink-window arg nil)
      (enlarge-window arg nil))))

(defun switch-window-mvborder-left (arg)
  (interactive "P")
  (switch-window--mvborder-left-or-right arg t))

(defun switch-window-mvborder-right (arg)
  (interactive "P")
  (switch-window--mvborder-left-or-right arg nil))

(defun switch-window-mvborder-up (arg)
  (interactive "P")
  (switch-window--mvborder-up-or-down arg t))

(defun switch-window-mvborder-down (arg)
  (interactive "P")
  (switch-window--mvborder-up-or-down arg nil))

;; * Footer
(provide 'switch-window-mvborder)

;;; switch-window-mvborder.el ends here