Skip to content
Newer
Older
100644 330 lines (302 sloc) 12.7 KB
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored Aug 30, 2010
1 (defvar magit-mode-map
2 (let ((map (make-keymap)))
3 (suppress-keymap map t)
4 (define-key map (kbd "n") 'magit-goto-next-section)
5 (define-key map (kbd "p") 'magit-goto-previous-section)
6 (define-key map (kbd "TAB") 'magit-toggle-section)
7 (define-key map (kbd "<backtab>") 'magit-expand-collapse-section)
8 (define-key map (kbd "1") 'magit-show-level-1)
9 (define-key map (kbd "2") 'magit-show-level-2)
10 (define-key map (kbd "3") 'magit-show-level-3)
11 (define-key map (kbd "4") 'magit-show-level-4)
12 (define-key map (kbd "M-1") 'magit-show-level-1-all)
13 (define-key map (kbd "M-2") 'magit-show-level-2-all)
14 (define-key map (kbd "M-3") 'magit-show-level-3-all)
15 (define-key map (kbd "M-4") 'magit-show-level-4-all)
16 (define-key map (kbd "M-h") 'magit-show-only-files)
17 (define-key map (kbd "M-H") 'magit-show-only-files-all)
18 (define-key map (kbd "M-s") 'magit-show-level-4)
19 (define-key map (kbd "M-S") 'magit-show-level-4-all)
20 (define-key map (kbd "<M-left>") 'magit-goto-parent-section)
21 (define-key map (kbd "g") 'magit-refresh)
22 (define-key map (kbd "G") 'magit-refresh-all)
23 (define-key map (kbd "?") 'magit-describe-item)
24 (define-key map (kbd "!") 'magit-shell-command)
25 (define-key map (kbd ":") 'magit-git-command)
26 (define-key map (kbd "RET") 'magit-visit-item)
27 (define-key map (kbd "SPC") 'magit-show-item-or-scroll-up)
28 (define-key map (kbd "DEL") 'magit-show-item-or-scroll-down)
29 (define-key map (kbd "C-w") 'magit-copy-item-as-kill)
30 (define-key map (kbd "R") 'magit-rebase-step)
31 (define-key map (kbd "r s") 'magit-rewrite-start)
32 (define-key map (kbd "r t") 'magit-rewrite-stop)
33 (define-key map (kbd "r a") 'magit-rewrite-abort)
34 (define-key map (kbd "r f") 'magit-rewrite-finish)
35 (define-key map (kbd "r *") 'magit-rewrite-set-unused)
36 (define-key map (kbd "r .") 'magit-rewrite-set-used)
37 (define-key map (kbd "P") 'magit-push)
38 (define-key map (kbd "f") 'magit-remote-update)
39 (define-key map (kbd "F") 'magit-pull)
40 (define-key map (kbd "c") 'magit-log-edit)
3c8bab4 @philjackson Run log hook from magit itself.
philjackson authored Aug 31, 2010
41 (define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored Aug 30, 2010
42 (define-key map (kbd "$") 'magit-display-process)
43 (define-key map (kbd "E") 'magit-interactive-rebase)
44 (define-key map (kbd "q") 'quit-window)
45 map))
46
47 (defvar magit-commit-mode-map
48 (let ((map (make-sparse-keymap)))
49 (define-key map (kbd "a") 'magit-apply-item)
50 (define-key map (kbd "A") 'magit-cherry-pick-item)
51 (define-key map (kbd "v") 'magit-revert-item)
52 map))
53
54 (defvar magit-status-mode-map
55 (let ((map (make-sparse-keymap)))
56 (define-key map (kbd "-") 'magit-diff-smaller-hunks)
57 (define-key map (kbd "+") 'magit-diff-larger-hunks)
58 (define-key map (kbd "0") 'magit-diff-default-hunks)
59 (define-key map (kbd "s") 'magit-stage-item)
60 (define-key map (kbd "S") 'magit-stage-all)
61 (define-key map (kbd "u") 'magit-unstage-item)
62 (define-key map (kbd "U") 'magit-unstage-all)
63 (define-key map (kbd "i") 'magit-ignore-item)
64 (define-key map (kbd "I") 'magit-ignore-item-locally)
65 (define-key map (kbd ".") 'magit-mark-item)
66 (define-key map (kbd "=") 'magit-diff-with-mark)
67 (define-key map (kbd "d") 'magit-diff-working-tree)
68 (define-key map (kbd "D") 'magit-diff)
69 (define-key map (kbd "a") 'magit-apply-item)
70 (define-key map (kbd "A") 'magit-cherry-pick-item)
71 (define-key map (kbd "v") 'magit-revert-item)
72 (define-key map (kbd "b") 'magit-branch-menu)
73 (define-key map (kbd "m") 'magit-manual-merge)
74 (define-key map (kbd "M") 'magit-automatic-merge)
75 (define-key map (kbd "k") 'magit-discard-item)
76 (define-key map (kbd "e") 'magit-interactive-resolve-item)
77 (define-key map (kbd "C") 'magit-add-log)
78 (define-key map (kbd "x") 'magit-reset-head)
79 (define-key map (kbd "X") 'magit-reset-working-tree)
80 (define-key map (kbd "t") 'magit-tag)
81 (define-key map (kbd "T") 'magit-annotated-tag)
82 (define-key map (kbd "z") 'magit-stash)
83 (define-key map (kbd "Z") 'magit-stash-snapshot)
84 map))
85
86 (defvar magit-stash-mode-map
87 (let ((map (make-sparse-keymap)))
88 (define-key map (kbd "-") 'magit-diff-smaller-hunks)
89 (define-key map (kbd "+") 'magit-diff-larger-hunks)
90 (define-key map (kbd "0") 'magit-diff-default-hunks)
91 (define-key map (kbd "a") 'magit-apply-item)
92 (define-key map (kbd "A") 'magit-cherry-pick-item)
93 (define-key map (kbd "v") 'magit-revert-item)
94 map))
95
96 (defvar magit-log-mode-map
97 (let ((map (make-sparse-keymap)))
98 (define-key map (kbd ".") 'magit-mark-item)
99 (define-key map (kbd "=") 'magit-diff-with-mark)
100 (define-key map (kbd "d") 'magit-diff-working-tree)
101 (define-key map (kbd "D") 'magit-diff)
102 (define-key map (kbd "a") 'magit-apply-item)
103 (define-key map (kbd "s") 'magit-log-grep)
104 (define-key map (kbd "A") 'magit-cherry-pick-item)
105 (define-key map (kbd "v") 'magit-revert-item)
106 (define-key map (kbd "b") 'magit-branch-menu)
107 (define-key map (kbd "m") 'magit-manual-merge)
108 (define-key map (kbd "M") 'magit-automatic-merge)
109 (define-key map (kbd "x") 'magit-reset-head)
110 (define-key map (kbd "e") 'magit-log-show-more-entries)
3c8bab4 @philjackson Run log hook from magit itself.
philjackson authored Aug 31, 2010
111 (define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored Aug 30, 2010
112 map))
113
114 (defvar magit-reflog-mode-map
115 (let ((map (make-sparse-keymap)))
116 (define-key map (kbd ".") 'magit-mark-item)
117 (define-key map (kbd "=") 'magit-diff-with-mark)
118 (define-key map (kbd "d") 'magit-diff-working-tree)
119 (define-key map (kbd "D") 'magit-diff)
120 (define-key map (kbd "a") 'magit-apply-item)
121 (define-key map (kbd "A") 'magit-cherry-pick-item)
122 (define-key map (kbd "v") 'magit-revert-item)
123 (define-key map (kbd "x") 'magit-reset-head)
124 map))
125
126 (defvar magit-diff-mode-map
127 (let ((map (make-sparse-keymap)))
128 (define-key map (kbd "-") 'magit-diff-smaller-hunks)
129 (define-key map (kbd "+") 'magit-diff-larger-hunks)
130 (define-key map (kbd "0") 'magit-diff-default-hunks)
131 (define-key map (kbd "a") 'magit-apply-item)
132 (define-key map (kbd "A") 'magit-cherry-pick-item)
133 (define-key map (kbd "v") 'magit-revert-item)
134 map))
135
136 (defvar magit-wazzup-mode-map
137 (let ((map (make-sparse-keymap)))
138 (define-key map (kbd ".") 'magit-mark-item)
139 (define-key map (kbd "=") 'magit-diff-with-mark)
140 (define-key map (kbd "d") 'magit-diff-working-tree)
141 (define-key map (kbd "D") 'magit-diff)
142 (define-key map (kbd "a") 'magit-apply-item)
143 (define-key map (kbd "A") 'magit-cherry-pick-item)
144 (define-key map (kbd "v") 'magit-revert-item)
145 (define-key map (kbd "b") 'magit-branch-menu)
146 (define-key map (kbd "m") 'magit-manual-merge)
147 (define-key map (kbd "M") 'magit-automatic-merge)
148 (define-key map (kbd "x") 'magit-reset-head)
149 (define-key map (kbd "i") 'magit-ignore-item)
150 map))
151
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
152 (defvar magit-key-mode-key-maps '()
153 "This will be filled lazily with proper `define-key' built
154 keymaps as they're reqeusted.")
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored Aug 30, 2010
155
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
156 (defvar magit-key-mode-buf-name "*magit-key*"
157 "Name of the buffer.")
158
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
159 (defvar magit-key-mode-groups
160 '((logging
161 (actions
162 ("l" "One line log" magit-log)
163 ("L" "Long log" magit-log-long)
164 ("h" "Reflog" magit-reflog)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
165 ("H" "Reflog on head" magit-reflog-head))
166 (switches
cba1be0 @philjackson Put '-' in front of switch keys.
philjackson authored Aug 31, 2010
167 ("-f" "First parent" "--first-parent")
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
168 ("-a" "All" "--all"))
169 (arguments
170 ("-g" "Grep" "--grep" read-from-minibuffer))))
955adde @philjackson Actions just about ready, keymap-wise.
philjackson authored Aug 30, 2010
171 "Holds the key, help, function mapping for the log-mode. If you
172 modify this make sure you reset `magit-key-mode-key-maps' to
173 nil.")
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
174
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
175 (defun magit-key-mode-options-for-group (for-group)
176 (or (cdr (assoc for-group magit-key-mode-groups))
177 (error "Unknown group '%s'" for-group)))
178
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
179 (defun magit-key-mode-build-keymap (for-group)
180 "Construct a normal looking keymap for the key mode to use and
181 put it in magit-key-mode-key-maps for fast lookup."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
182 (let* ((options (magit-key-mode-options-for-group for-group))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
183 (actions (cdr (assoc 'actions options)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
184 (switches (cdr (assoc 'switches options)))
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
185 (arguments (cdr (assoc 'arguments options))))
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored Aug 30, 2010
186 (let ((map (make-sparse-keymap)))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
187 ;; all maps should 'quit' with C-g
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
188 (define-key map (kbd "C-g") (lambda ()
189 (interactive)
190 (with-magit-key-mode-command
191 t)))
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored Aug 30, 2010
192 (when actions
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
193 (dolist (k actions)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
194 (define-key map (car k) `(lambda ()
195 (interactive)
196 (with-magit-key-mode-command
197 (funcall ',(nth 2 k)))))))
198 (when switches
199 (dolist (k switches)
200 (define-key map (car k) `(lambda ()
cba1be0 @philjackson Put '-' in front of switch keys.
philjackson authored Aug 31, 2010
201 (interactive)
202 (magit-key-mode-add-option
203 ',for-group
204 ,(nth 2 k))))))
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
205 (when arguments
206 (dolist (k arguments)
207 (define-key map (car k) `(lambda ()
208 (interactive)
209 (magit-key-mode-add-argument
210 ',for-group
211 ,(nth 2 k))))))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
212 (aput 'magit-key-mode-key-maps for-group map)
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored Aug 30, 2010
213 map)))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
214
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
215 (defvar magit-key-mode-current-options '()
216 "Current option set (which will eventually make it to the git
217 command-line).")
218
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
219 (defvar magit-key-mode-header-re
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
220 (rx line-start (| "Actions" "Switches" "Arguments") ":"))
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
221
222 (defvar magit-key-mode-action-re
223 (rx line-start
224 (char space)
225 (group
0298b47 @philjackson Fix RE for finding switch.
philjackson authored Aug 31, 2010
226 (* "-")
227 (char alpha))
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
228 ": "
229 (group
230 (* not-newline))))
231
232 (defvar magit-key-mode-font-lock-keywords
233 (list
234 (list magit-key-mode-header-re 0 'font-lock-keyword-face)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
235 (list magit-key-mode-action-re '(1 font-lock-builtin-face))))
236
237 (defmacro with-magit-key-mode-command (&rest body)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
238 (set-window-configuration magit-log-mode-window-conf)
602f257 @philjackson Executing with custom options implemented.
philjackson authored Aug 31, 2010
239 `(let ((magit-custom-options magit-key-mode-current-options))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
240 ,@body
241 (magit-key-mode-kill-buffer)))
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
242
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
243 (defun magit-key-mode-add-argument (for-group option-name))
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
244
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
245 (defun magit-key-mode-add-option (for-group option-name)
246 "Toggles the appearance of OPTION-NAME in
247 `magit-key-mode-current-options'."
248 (if (not (member option-name magit-key-mode-current-options))
249 (add-to-list 'magit-key-mode-current-options option-name)
250 (setq magit-key-mode-current-options
251 (delete option-name magit-key-mode-current-options)))
252 (magit-key-mode-redraw for-group))
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
253
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
254 (defun magit-key-mode-kill-buffer ()
c351215 @philjackson C-g kills buffer.
philjackson authored Aug 31, 2010
255 (interactive)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
256 (kill-buffer magit-key-mode-buf-name))
257
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
258 (defvar magit-log-mode-window-conf nil
259 "Pre-popup window configuration.")
260
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
261 (defun magit-key-mode (for-group &optional original-opts)
b335871 @philjackson Options var now buffer local.
philjackson authored Aug 31, 2010
262 "Mode for magit key selection."
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored Aug 30, 2010
263 (interactive)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
264
265 ;; save the window config to restore it as was
266 (setq magit-log-mode-window-conf
267 (current-window-configuration))
268
269 ;; setup the mode, draw the buffer
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
270 (let ((buf (get-buffer-create magit-key-mode-buf-name)))
b35413b @philjackson Use pop-to-buffer instead of splitting manually.
philjackson authored Aug 31, 2010
271 (pop-to-buffer buf)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
272 (kill-all-local-variables)
273 (set (make-variable-buffer-local
274 'magit-key-mode-current-options)
275 original-opts)
276 (magit-key-mode-redraw for-group)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
277
278 (defun magit-key-mode-redraw (for-group)
b335871 @philjackson Options var now buffer local.
philjackson authored Aug 31, 2010
279 "(re)draw the magit key buffer."
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
280 (let ((buffer-read-only nil))
281 (erase-buffer)
282 (make-local-variable 'font-lock-defaults)
283 (setq font-lock-defaults
284 '(magit-key-mode-font-lock-keywords t nil nil nil))
285 (use-local-map
286 (or (cdr (assoc for-group magit-key-mode-key-maps))
287 (magit-key-mode-build-keymap for-group)))
288 (magit-key-mode-draw for-group)
ec4cf70 @philjackson Fix buffer not being read-only.
philjackson authored Aug 31, 2010
289 (setq mode-name "magit-key-mode" major-mode 'magit-key-mode))
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored Aug 31, 2010
290 (setq buffer-read-only t)
291 (fit-window-to-buffer))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored Aug 30, 2010
292
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
293 (defun magit-key-mode-draw (for-group)
5be31a3 @philjackson Some font-locking.
philjackson authored Aug 30, 2010
294 "Function used to draw actions, switches and parameters."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
295 (let* ((options (magit-key-mode-options-for-group for-group))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
296 (switches (cdr (assoc 'switches options)))
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
297 (arguments (cdr (assoc 'arguments options)))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
298 (actions (cdr (assoc 'actions options))))
299 (insert "Actions:\n")
300 (dolist (action actions)
301 (insert
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
302 (concat " " (car action) ": " (nth 1 action) "\n")))
303 (insert "Switches:\n")
304 (dolist (switch switches)
305 (let ((option (nth 2 switch)))
306 (insert
307 (concat
308 " "
309 (car switch)
310 ": "
311 (nth 1 switch)
312 " ("
313 (if (member option magit-key-mode-current-options)
314 (propertize option 'font-lock-face 'font-lock-warning-face)
315 option)
0604574 @philjackson Basic argument display in place.
philjackson authored Aug 31, 2010
316 ")\n"))))
317 (insert "Arguments:\n")
318 (dolist (argument arguments)
319 (insert
320 (concat
321 " "
322 (car argument)
323 ": "
324 (nth 1 argument)
325 " ("
326 (nth 2 argument)
327 ")\n")))))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored Aug 30, 2010
328
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored Aug 31, 2010
329 (provide 'magit-key-mode)
Something went wrong with that request. Please try again.