-
Notifications
You must be signed in to change notification settings - Fork 5
/
shampoo-list-mode.el
151 lines (130 loc) · 4.53 KB
/
shampoo-list-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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;;; shampoo-list-mode.el --- a "Basic class" for Shampoo list modes
;;
;; Copyright (C) 2010 - 2012 Dmitry Matveev <[email protected]>
;;
;; This software is released under terms of the MIT license,
;; please refer to the LICENSE file for details.
(eval-when-compile (require 'cl))
(require 'shampoo-state)
(require 'shampoo-utils)
(require 'shampoo-faces)
(require 'shampoo-requests)
(define-derived-mode shampoo-list-mode
text-mode "Shampoo generic mode for list buffers"
(setq buffer-read-only t)
(shampoo-mklocal set-current-item)
(shampoo-mklocal produce-request)
(shampoo-mklocal pre-insert-hook)
(shampoo-mklocal dependent-buffer)
(shampoo-mklocal update-source-buffer)
(shampoo-mklocal force-update-buffer)
(shampoo-mklocal code-compile 'shampoo-compile-method)
(shampoo-mklocal remove-item)
(shampoo-mklocal fileout-item))
(defun shampoo-open-at-list (list-buff-name item)
(with-current-buffer list-buff-name
(save-excursion
(goto-char (point-min))
(if (null item)
;; Just open the fist item
(shampoo-list-on-select)
;; Search for the specified one
(block search-block
(while (search-forward item nil t)
(when (equal item (shampoo-this-line))
(shampoo-open-from-list)
(return-from search-block))))))))
(defun shampoo-open-from-list ()
(interactive)
(let ((this-line (shampoo-this-line)))
(when (not (equal this-line ""))
(shampoo-reset-buffer-faces)
(shampoo-set-line-face 'shampoo-selected-list-item)
(when-shampoo-t set-current-item
(funcall set-current-item this-line))
(shampoo-send-message
(funcall (shampoo-getv produce-request) this-line)))))
(defun shampoo-clear-buffer-with-dependent ()
(let ((buffer-read-only nil))
(erase-buffer)
(when-shampoo-t depd-buffer
(with-current-buffer depd-buffer
(shampoo-clear-buffer-with-dependent)))))
(defun shampoo-list-on-select ()
(interactive)
(shampoo-setq *shampoo-code-compile* (shampoo-getv code-compile))
(when-shampoo-t dependent-buffer
(shampoo-open-from-list))
(when-shampoo-t update-source-buffer
(funcall update-source-buffer)))
(defun shampoo-list-on-click (event)
(interactive "e")
(let ((window (posn-window (event-end event)))
(pos (posn-point (event-end event))))
(when (windowp window)
(with-current-buffer (window-buffer window)
(goto-char pos)
(shampoo-list-on-select)))))
(defun shampoo-list-remove-item ()
(interactive)
(when-shampoo-t remove-item
(let ((this-line (shampoo-this-line)))
(when (not (equal this-line ""))
(funcall remove-item this-line)))))
(defun shampoo-list-fileout-item ()
(interactive)
(when-shampoo-t fileout-item
(let ((this-line (shampoo-this-line)))
(when (not (equal this-line ""))
(funcall fileout-item this-line)))))
(define-key shampoo-list-mode-map
[return]
'shampoo-list-on-select)
(define-key shampoo-list-mode-map
[mouse-1]
'shampoo-list-on-click)
(define-key shampoo-list-mode-map
"\C-c\C-t"
'shampoo-toggle-side)
(define-key shampoo-list-mode-map
"\C-c\C-d"
'shampoo-list-remove-item)
(define-key shampoo-list-mode-map
"\C-c\C-f"
'shampoo-list-fileout-item)
(defun shampoo-make-class-opener (class-to-open)
(lexical-let ((class class-to-open))
(lambda (resp)
(shampoo-open-at-list "*shampoo-classes*" class))))
(defun shampoo-make-category-opener (cat-to-open)
(lexical-let ((cat cat-to-open))
(lambda (resp)
(shampoo-open-at-list "*shampoo-categories*" cat))))
(defun* shampoo-make-class-reloader (&optional class-to-open)
(lexical-let ((open-then class-to-open))
(lambda (resp)
(when (shampoo-response-is-success resp)
(shampoo-reload-class-list open-then)))))
(defun* shampoo-reload-class-list (&optional open-then)
(let ((request-id (shampoo-give-id)))
(shampoo-subscribe
request-id
(shampoo-make-class-opener open-then))
(shampoo-send-message
(shampoo-make-classes-rq
:id request-id
:ns (shampoo-get-current-namespace)))))
(defun* shampoo-reload-categories-list (&key open-then need-open)
(let ((request-id (shampoo-give-id)))
(when need-open
(shampoo-subscribe
request-id
(shampoo-make-category-opener open-then)))
(shampoo-send-message
(shampoo-make-cats-rq
:id request-id
:ns (shampoo-get-current-namespace)
:class (shampoo-get-current-class)
:side (shampoo-side)))))
(provide 'shampoo-list-mode)
;;; shampoo-list-mode.el ends here.