-
Notifications
You must be signed in to change notification settings - Fork 1
/
yandex-arc-branches.el
71 lines (54 loc) · 2.43 KB
/
yandex-arc-branches.el
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
;; -*- lexical-binding: t; -*-
(provide 'yandex-arc-branches)
(require 'yandex-arc-properties)
(require 'yandex-arc-shell)
(require 'yandex-arc-util)
(require 'eieio)
(require 'magit-section)
(defclass yandex-arc/branches-section (magit-section) ())
(defclass yandex-arc/branch-section (magit-section) ())
(define-derived-mode yandex-arc-branches-mode yandex-arc-mode "arc-branches"
"Yandex Arc Branches Major Mode."
(setq-local revert-buffer-function 'yandex-arc/branches/revert-branches-buffer))
(defun yandex-arc/branches/show-all-branches ()
(let ((buffer (get-buffer-create (concat "arc-branches: " (file-name-nondirectory default-directory)))))
(set-buffer buffer)
(yandex-arc-branches-mode)
(revert-buffer)
(switch-to-buffer buffer)))
(defun yandex-arc/branches/revert-branches-buffer (ignore-auto noconfirm)
(ignore ignore-auto noconfirm)
(yandex-arc/branches/redraw-branches-buffer
(append (slot-value (yandex-arc/shell/branch-list) 'value) nil))) ; Append converts vector to list.
(defun yandex-arc/branches/redraw-branches-buffer (branch-infos)
(yandex-arc/util/save-line-and-column
(let ((inhibit-read-only t))
(erase-buffer)
(magit-insert-section (yandex-arc/root-section)
(yandex-arc/branches/insert-branches-section
"Local branches" nil
(seq-filter (lambda (branch-info) (gethash "local" branch-info)) branch-infos))
(yandex-arc/branches/insert-branches-section
"Remote branches" t
(seq-filter (lambda (branch-info) (not (gethash "local" branch-info))) branch-infos))))))
(defun yandex-arc/branches/insert-branches-section (section-name hide-section branch-infos)
(magit-insert-section (yandex-arc/branches-section section-name hide-section)
(magit-insert-heading
(yandex-arc/properties/section-heading section-name)
":") ; Column at the end of the heading is replaced on subsections number.
(dolist (branch-info branch-infos)
(yandex-arc/branches/insert-branch-section
(gethash "name" branch-info)
(gethash "current" branch-info)))
(insert ?\n)))
(defun yandex-arc/branches/insert-branch-section (name is-head)
(magit-insert-section (yandex-arc/branch-section name)
(insert
(if is-head
(concat
(yandex-arc/properties/section-heading "@ ")
(yandex-arc/properties/current-branch-name name))
(concat
" "
(yandex-arc/properties/branch-name name)))
"\n")))