Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 355 lines (327 sloc) 14.055 kB
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
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
41 (define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
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
111 (define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
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
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
155
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
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
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
165 ("H" "Reflog on head" magit-reflog-head))
166 (switches
bad6cc9 @philjackson Added merge commit switch.
philjackson authored
167 ("-m" "Only merge commits" "--merges")
cba1be0 @philjackson Put '-' in front of switch keys.
philjackson authored
168 ("-f" "First parent" "--first-parent")
0604574 @philjackson Basic argument display in place.
philjackson authored
169 ("-a" "All" "--all"))
170 (arguments
644cdf8 @philjackson Added branches arg.
philjackson authored
171 ("=b" "Branches" "--branches" read-from-minibuffer)
f68a3d1 @philjackson Changed the prefix for args to '='.
philjackson authored
172 ("=a" "Author" "--author" read-from-minibuffer)
173 ("=g" "Grep" "--grep" read-from-minibuffer))))
955adde @philjackson Actions just about ready, keymap-wise.
philjackson authored
174 "Holds the key, help, function mapping for the log-mode. If you
175 modify this make sure you reset `magit-key-mode-key-maps' to
176 nil.")
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
177
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
178 (defun magit-key-mode-options-for-group (for-group)
179 (or (cdr (assoc for-group magit-key-mode-groups))
180 (error "Unknown group '%s'" for-group)))
181
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
182 (defun magit-key-mode-build-keymap (for-group)
183 "Construct a normal looking keymap for the key mode to use and
184 put it in magit-key-mode-key-maps for fast lookup."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
185 (let* ((options (magit-key-mode-options-for-group for-group))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
186 (actions (cdr (assoc 'actions options)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
187 (switches (cdr (assoc 'switches options)))
0604574 @philjackson Basic argument display in place.
philjackson authored
188 (arguments (cdr (assoc 'arguments options))))
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored
189 (let ((map (make-sparse-keymap)))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
190 ;; all maps should 'quit' with C-g
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
191 (define-key map (kbd "C-g") (lambda ()
192 (interactive)
c0324a5 @philjackson Fixed quit.
philjackson authored
193 (magit-key-mode-command nil)))
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored
194 (when actions
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
195 (dolist (k actions)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
196 (define-key map (car k) `(lambda ()
197 (interactive)
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
198 (magit-key-mode-command ',(nth 2 k))))))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
199 (when switches
200 (dolist (k switches)
201 (define-key map (car k) `(lambda ()
cba1be0 @philjackson Put '-' in front of switch keys.
philjackson authored
202 (interactive)
203 (magit-key-mode-add-option
204 ',for-group
205 ,(nth 2 k))))))
0604574 @philjackson Basic argument display in place.
philjackson authored
206 (when arguments
207 (dolist (k arguments)
208 (define-key map (car k) `(lambda ()
209 (interactive)
210 (magit-key-mode-add-argument
211 ',for-group
217febc @philjackson Args being remembered.
philjackson authored
212 ,(nth 2 k)
213 ',(nth 3 k))))))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
214 (aput 'magit-key-mode-key-maps for-group map)
b5ad1b1 @philjackson Keymap installs for mode.
philjackson authored
215 map)))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
216
5be31a3 @philjackson Some font-locking.
philjackson authored
217 (defvar magit-key-mode-header-re
0604574 @philjackson Basic argument display in place.
philjackson authored
218 (rx line-start (| "Actions" "Switches" "Arguments") ":"))
5be31a3 @philjackson Some font-locking.
philjackson authored
219
220 (defvar magit-key-mode-action-re
221 (rx line-start
222 (char space)
223 (group
f68a3d1 @philjackson Changed the prefix for args to '='.
philjackson authored
224 (* (char "-="))
0298b47 @philjackson Fix RE for finding switch.
philjackson authored
225 (char alpha))
5be31a3 @philjackson Some font-locking.
philjackson authored
226 ": "
227 (group
228 (* not-newline))))
229
230 (defvar magit-key-mode-font-lock-keywords
231 (list
232 (list magit-key-mode-header-re 0 'font-lock-keyword-face)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
233 (list magit-key-mode-action-re '(1 font-lock-builtin-face))))
234
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
235 (defun magit-key-mode-command (func)
236 (let ((args '()))
237 ;; why can't maphash return a list?!
238 (maphash (lambda (k v)
239 (push (concat k "=" (shell-quote-argument v)) args))
240 magit-key-mode-current-args)
241 (let ((magit-custom-options (append args magit-key-mode-current-options)))
242 (set-window-configuration magit-log-mode-window-conf)
c0324a5 @philjackson Fixed quit.
philjackson authored
243 (when func
244 (funcall func))
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
245 (magit-key-mode-kill-buffer))))
5be31a3 @philjackson Some font-locking.
philjackson authored
246
217febc @philjackson Args being remembered.
philjackson authored
247 (defvar magit-key-mode-current-args nil
248 "A hash-table of current argument set (which will eventually
249 make it to the git command-line).")
250
251 (defun debug-args ()
252 (interactive)
253 (maphash (lambda (k v) (print (format "%s: %s" k v))) magit-key-mode-current-args))
254
255 (defun magit-key-mode-add-argument (for-group arg-name input-func)
256 (let ((input (funcall input-func (concat arg-name ": "))))
257 (puthash arg-name input magit-key-mode-current-args)
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
258 (magit-key-mode-redraw for-group)))
217febc @philjackson Args being remembered.
philjackson authored
259
260 (defvar magit-key-mode-current-options '()
261 "Current option set (which will eventually make it to the git
262 command-line).")
0604574 @philjackson Basic argument display in place.
philjackson authored
263
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
264 (defun magit-key-mode-add-option (for-group option-name)
265 "Toggles the appearance of OPTION-NAME in
266 `magit-key-mode-current-options'."
267 (if (not (member option-name magit-key-mode-current-options))
268 (add-to-list 'magit-key-mode-current-options option-name)
269 (setq magit-key-mode-current-options
270 (delete option-name magit-key-mode-current-options)))
271 (magit-key-mode-redraw for-group))
5be31a3 @philjackson Some font-locking.
philjackson authored
272
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
273 (defun magit-key-mode-kill-buffer ()
c351215 @philjackson C-g kills buffer.
philjackson authored
274 (interactive)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
275 (kill-buffer magit-key-mode-buf-name))
276
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
277 (defvar magit-log-mode-window-conf nil
278 "Pre-popup window configuration.")
279
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
280 (defun magit-key-mode (for-group &optional original-opts)
b335871 @philjackson Options var now buffer local.
philjackson authored
281 "Mode for magit key selection."
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
282 (interactive)
09ab17d @philjackson Doc.
philjackson authored
283 ;; save the window config to restore it as was (no need to make this
284 ;; buffer local)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
285 (setq magit-log-mode-window-conf
286 (current-window-configuration))
287 ;; setup the mode, draw the buffer
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
288 (let ((buf (get-buffer-create magit-key-mode-buf-name)))
b35413b @philjackson Use pop-to-buffer instead of splitting manually.
philjackson authored
289 (pop-to-buffer buf)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
290 (kill-all-local-variables)
291 (set (make-variable-buffer-local
292 'magit-key-mode-current-options)
293 original-opts)
217febc @philjackson Args being remembered.
philjackson authored
294 (set (make-variable-buffer-local
295 'magit-key-mode-current-args)
296 (make-hash-table))
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
297 (magit-key-mode-redraw for-group)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
298
299 (defun magit-key-mode-redraw (for-group)
b335871 @philjackson Options var now buffer local.
philjackson authored
300 "(re)draw the magit key buffer."
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
301 (let ((buffer-read-only nil))
302 (erase-buffer)
303 (make-local-variable 'font-lock-defaults)
304 (setq font-lock-defaults
305 '(magit-key-mode-font-lock-keywords t nil nil nil))
306 (use-local-map
307 (or (cdr (assoc for-group magit-key-mode-key-maps))
308 (magit-key-mode-build-keymap for-group)))
309 (magit-key-mode-draw for-group)
ec4cf70 @philjackson Fix buffer not being read-only.
philjackson authored
310 (setq mode-name "magit-key-mode" major-mode 'magit-key-mode))
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
311 (setq buffer-read-only t)
312 (fit-window-to-buffer))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
313
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
314 (defun magit-key-mode-draw (for-group)
5be31a3 @philjackson Some font-locking.
philjackson authored
315 "Function used to draw actions, switches and parameters."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
316 (let* ((options (magit-key-mode-options-for-group for-group))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
317 (switches (cdr (assoc 'switches options)))
0604574 @philjackson Basic argument display in place.
philjackson authored
318 (arguments (cdr (assoc 'arguments options)))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
319 (actions (cdr (assoc 'actions options))))
320 (insert "Actions:\n")
321 (dolist (action actions)
322 (insert
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
323 (concat " " (car action) ": " (nth 1 action) "\n")))
324 (insert "Switches:\n")
325 (dolist (switch switches)
326 (let ((option (nth 2 switch)))
327 (insert
328 (concat
329 " "
330 (car switch)
331 ": "
332 (nth 1 switch)
333 " ("
334 (if (member option magit-key-mode-current-options)
335 (propertize option 'font-lock-face 'font-lock-warning-face)
336 option)
0604574 @philjackson Basic argument display in place.
philjackson authored
337 ")\n"))))
338 (insert "Arguments:\n")
339 (dolist (argument arguments)
340 (insert
341 (concat
342 " "
343 (car argument)
344 ": "
345 (nth 1 argument)
346 " ("
347 (nth 2 argument)
a9bba80 @philjackson Output propertised arg value.
philjackson authored
348 ") "
349 (propertize
350 (gethash (nth 2 argument) magit-key-mode-current-args "")
351 'font-lock-face 'widget-field)
352 "\n")))))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
353
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
354 (provide 'magit-key-mode)
Something went wrong with that request. Please try again.