-
Notifications
You must be signed in to change notification settings - Fork 6
/
ecloud-mode.el
115 lines (95 loc) · 4.07 KB
/
ecloud-mode.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;; ecloud-mode.el --- ecloud mode -*- lexical-binding: t -*-
;; Author: Ramanathan Sivagurunathan
;; Maintainer: Ramanathan Sivagurunathan
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (magit "2.13.0") (ht "2.2") (s "1.12.0") (pcache "0.4.2"))
;; Homepage: homepage
;; Keywords: keywords
;; This file is not part of GNU Emacs
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Contains code for ecloud mode
;;; Code:
(defvar ecloud-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [tab] 'magit-section-toggle)
map))
(define-derived-mode ecloud-mode special-mode "ecloud"
"Base mode for ecloud.
\\{ecloud-mode-map}"
:group 'ecloud
(buffer-disable-undo)
(setq truncate-lines t)
(setq buffer-read-only t)
(setq-local line-move-visual t)
(setq show-trailing-whitespace nil)
(setq list-buffers-directory (abbreviate-file-name default-directory))
(hack-dir-local-variables-non-file-buffer)
(make-local-variable 'text-property-default-nonsticky)
(push (cons 'keymap t) text-property-default-nonsticky)
(add-hook 'post-command-hook #'magit-section-update-highlight t t)
(add-hook 'deactivate-mark-hook #'magit-section-update-highlight t t)
(setq-local redisplay-highlight-region-function 'magit-highlight-region)
(setq-local redisplay-unhighlight-region-function 'magit-unhighlight-region)
(when (bound-and-true-p global-linum-mode)
(linum-mode -1))
(when (and (fboundp 'nlinum-mode)
(bound-and-true-p global-nlinum-mode))
(nlinum-mode -1))
(when (and (fboundp 'display-line-numbers-mode)
(bound-and-true-p global-display-line-numbers-mode))
(display-line-numbers-mode -1))
;; TODO
;; (add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache)
)
(defun ecloud-mode-get-buffers ()
"Function to get all ecloud mode buffers."
(--filter (with-current-buffer it
(and (derived-mode-p 'ecloud-mode)))
(buffer-list)))
(defun ecloud-mode-get-buffer (mode &optional create frame value)
"Function to get ecloud buffer with `MODE.
Optional `CREATE for creating a new buffer.
`FRAME to use a frame. `VALUE for buffer."
(or (--first (with-current-buffer it
(and (eq major-mode mode)
(if value
(and magit-buffer-locked-p
(equal (magit-buffer-lock-value) value))
(not magit-buffer-locked-p))))
(if frame
(mapcar #'window-buffer
(window-list (unless (eq frame t) frame)))
(buffer-list)))
(and create
(magit-generate-new-buffer mode value))))
(defun ecloud-mode-setup (mode &rest args)
"Setup up a MODE buffer using ARGS to generate its content."
(ecloud-mode-setup-internal mode args))
(defun ecloud-mode-setup-internal (mode args &optional locked)
"Setup up a MODE buffer using ARGS to generate its content.
When optional LOCKED is non-nil, then create a buffer that is
locked to its value, which is derived from MODE and ARGS."
(let ((buffer (ecloud-mode-get-buffer
mode t nil
(and locked (magit-buffer-lock-value mode args))))
(section (magit-current-section)))
(with-current-buffer buffer
(setq magit-previous-section section)
(setq magit-refresh-args args)
(funcall mode))
(magit-display-buffer buffer)
(with-current-buffer buffer
(run-hooks 'magit-mode-setup-hook)
(magit-refresh-buffer))))
(provide 'ecloud-mode)
;;; ecloud-mode.el ends here