Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 505 lines (449 sloc) 18.312 kb
987272d @wrog Rearrange load order
wrog authored
1 (require 'magit)
2
ee84d43 @philjackson Require assoc.
philjackson authored
3 (require 'assoc)
2a53872 @elibarzilay Use a little utility function to do the key binding.
elibarzilay authored
4 (eval-when-compile (require 'cl))
ee84d43 @philjackson Require assoc.
philjackson authored
5
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
6 (defvar magit-key-mode-key-maps '()
7 "This will be filled lazily with proper `define-key' built
1a4df17 @greenrd Spelling
greenrd authored
8 keymaps as they're requested.")
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
9
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
10 (defvar magit-key-mode-buf-name "*magit-key*"
11 "Name of the buffer.")
12
2af8e2e @philjackson Fixed compile warnings by adding missing defvars.
philjackson authored
13 (defvar magit-key-mode-current-args '()
14 "Will contain the arguments to be passed to git.")
15
16 (defvar magit-key-mode-current-options '()
17 "Will contain the arguments to be passed to git.")
18
19 (defvar magit-log-mode-window-conf nil
20 "Will hold the pre-menu configuration of magit.")
21
d4743e1 @wrog Declare magit-key-mode-groups with (defvar ...)
wrog authored
22 (defvar magit-key-mode-groups
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
23 '((logging
82a7d90 @philjackson Added a help function.
philjackson authored
24 (man-page "git-log")
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
25 (actions
fae37b8 @asn-the-goblin-slayer Rename magit-display-log* commands to magit-log.
asn-the-goblin-slayer authored
26 ("l" "Short" magit-log)
a3f38d4 @philjackson Docs.
philjackson authored
27 ("L" "Long" magit-log-long)
80ee094 @philjackson Reflog commands a bit more like the log commands now.
philjackson authored
28 ("h" "Reflog" magit-reflog)
fae37b8 @asn-the-goblin-slayer Rename magit-display-log* commands to magit-log.
asn-the-goblin-slayer authored
29 ("rl" "Ranged short" magit-log-ranged)
96f9a1e @philjackson New ranged log command.
philjackson authored
30 ("rL" "Ranged long" magit-log-long-ranged)
80ee094 @philjackson Reflog commands a bit more like the log commands now.
philjackson authored
31 ("rh" "Ranged reflog" magit-reflog-ranged))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
32 (switches
bad6cc9 @philjackson Added merge commit switch.
philjackson authored
33 ("-m" "Only merge commits" "--merges")
cba1be0 @philjackson Put '-' in front of switch keys.
philjackson authored
34 ("-f" "First parent" "--first-parent")
1a4df17 @greenrd Spelling
greenrd authored
35 ("-i" "Case insensitive patterns" "-i")
0d84cfe @philjackson New opts/args.
philjackson authored
36 ("-pr" "Pickaxe regex" "--pickaxe-regex")
37 ("-n" "Name only" "--name-only")
38 ("-am" "All match" "--all-match")
7aafcb0 @philjackson Remove conflicting binding.
philjackson authored
39 ("-al" "All" "--all"))
0604574 @philjackson Basic argument display in place.
philjackson authored
40 (arguments
0d84cfe @philjackson New opts/args.
philjackson authored
41 ("=r" "Relative" "--relative=" read-directory-name)
96ba818 @philjackson Fix --committer option.
philjackson authored
42 ("=c" "Committer" "--committer=" read-from-minibuffer)
0d84cfe @philjackson New opts/args.
philjackson authored
43 ("=>" "Since" "--since=" read-from-minibuffer)
44 ("=<" "Before" "--before=" read-from-minibuffer)
7058e07 @philjackson Added Pickaxe options.
philjackson authored
45 ("=s" "Pickaxe search" "-S" read-from-minibuffer)
46 ("=a" "Author" "--author=" read-from-minibuffer)
47 ("=g" "Grep" "--grep=" read-from-minibuffer)))
e882f3c @philjackson Put rebasing commands in menu.
philjackson authored
48
0282351 @philjackson Added commands for running stuff.
philjackson authored
49 (running
50 (actions
51 ("!" "Command from root" magit-shell-command)
7b1ccc9 @mbunkus Run "git gui" and "gitk --all" from the "actions" popup
mbunkus authored
52 (":" "Git command" magit-git-command)
53 ("g" "git gui" magit-run-git-gui)
54 ("k" "gitk" magit-run-gitk)))
0282351 @philjackson Added commands for running stuff.
philjackson authored
55
548b2e5 @philjackson Separation of fetch and remote update.
philjackson authored
56 (fetching
3e91027 @philjackson Added more man-page declarations.
philjackson authored
57 (man-page "git-fetch")
548b2e5 @philjackson Separation of fetch and remote update.
philjackson authored
58 (actions
2123b72 @philjackson Added fetch-other and removed useless fetch option.
philjackson authored
59 ("f" "Current" magit-fetch-current)
60 ("a" "All" magit-remote-update)
5546fef @bastianbeischer Added --prune option to magit-fetch and magit-remote-update functions.
bastianbeischer authored
61 ("o" "Other" magit-fetch))
62 (switches
63 ("-p" "Prune" "--prune")))
548b2e5 @philjackson Separation of fetch and remote update.
philjackson authored
64
c02fffb @philjackson Added push/pull menus.
philjackson authored
65 (pushing
3e91027 @philjackson Added more man-page declarations.
philjackson authored
66 (man-page "git-push")
c02fffb @philjackson Added push/pull menus.
philjackson authored
67 (actions
3e7bd1c @philjackson More frequent operations get 'double tap' keybindings.
philjackson authored
68 ("P" "Push" magit-push)
8152961 @philjackson Added the ability to push tags.
philjackson authored
69 ("t" "Push tags" magit-push-tags))
78a3d70 @philjackson Added -n to push menu. Added magit-custom-options to push command.
philjackson authored
70 (switches
bdaee3c @philjackson Added force to push switch list.
philjackson authored
71 ("-f" "Force" "--force")
8b6b90f @rubbish Adding option for set-upstream.
rubbish authored
72 ("-d" "Dry run" "-n")
73 ("-u" "Set upstream" "-u")))
c02fffb @philjackson Added push/pull menus.
philjackson authored
74
75 (pulling
3e91027 @philjackson Added more man-page declarations.
philjackson authored
76 (man-page "git-pull")
c02fffb @philjackson Added push/pull menus.
philjackson authored
77 (actions
3e7bd1c @philjackson More frequent operations get 'double tap' keybindings.
philjackson authored
78 ("F" "Pull" magit-pull))
c02fffb @philjackson Added push/pull menus.
philjackson authored
79 (switches
80 ("-r" "Rebase" "--rebase")))
81
ceb77d5 @philjackson Added a branch menu.
philjackson authored
82 (branching
3e91027 @philjackson Added more man-page declarations.
philjackson authored
83 (man-page "git-branch")
ceb77d5 @philjackson Added a branch menu.
philjackson authored
84 (actions
a5233ba @dudebout Renaming magit-show-branches to magit-branch-manager.
dudebout authored
85 ("v" "Branch manager" magit-branch-manager)
3e7bd1c @philjackson More frequent operations get 'double tap' keybindings.
philjackson authored
86 ("n" "New" magit-create-branch)
70ee1c5 @philjackson Added a branching menu.
philjackson authored
87 ("m" "Move" magit-move-branch)
88 ("d" "Delete" magit-delete-branch)
1e237f8 @praet add forced branch deletion ("git branch -D BRANCH")
praet authored
89 ("D" "Force Delete" magit-delete-branch-forced)
3e7bd1c @philjackson More frequent operations get 'double tap' keybindings.
philjackson authored
90 ("b" "Checkout" magit-checkout)))
ceb77d5 @philjackson Added a branch menu.
philjackson authored
91
e91decf @philjackson Added a tagging menu.
philjackson authored
92 (tagging
3e91027 @philjackson Added more man-page declarations.
philjackson authored
93 (man-page "git-tag")
e91decf @philjackson Added a tagging menu.
philjackson authored
94 (actions
95 ("t" "Lightweight" magit-tag)
db050cb @mbunkus Use "a" instead of "T" for annotated tags
mbunkus authored
96 ("a" "Annotated" magit-annotated-tag))
e91decf @philjackson Added a tagging menu.
philjackson authored
97 (switches
98 ("-f" "Force" "-f")))
99
2733adb @philjackson Added a stash menu.
philjackson authored
100 (stashing
3e91027 @philjackson Added more man-page declarations.
philjackson authored
101 (man-page "git-stash")
2733adb @philjackson Added a stash menu.
philjackson authored
102 (actions
3e7bd1c @philjackson More frequent operations get 'double tap' keybindings.
philjackson authored
103 ("z" "Save" magit-stash)
104 ("s" "Snapshot" magit-stash-snapshot))
2733adb @philjackson Added a stash menu.
philjackson authored
105 (switches
106 ("-k" "Keep index" "--keep-index")))
107
653cc89 @philjackson Added a merge menu.
philjackson authored
108 (merging
3e91027 @philjackson Added more man-page declarations.
philjackson authored
109 (man-page "git-merge")
653cc89 @philjackson Added a merge menu.
philjackson authored
110 (actions
bdebdfc @philjackson Merged the different type of... merges.
philjackson authored
111 ("m" "Merge" magit-merge))
653cc89 @philjackson Added a merge menu.
philjackson authored
112 (switches
3dacf2a Add switch for fast-forward only merge: --ff-only
Robert Boone authored
113 ("-ff" "Fast-forward only" "--ff-only")
bdebdfc @philjackson Merged the different type of... merges.
philjackson authored
114 ("-nf" "No fast-forward" "--no-ff")
115 ("-nc" "No commit" "--no-commit")
3dd1ef3 @greenrd Fix typo
greenrd authored
116 ("-sq" "Squash" "--squash"))
653cc89 @philjackson Added a merge menu.
philjackson authored
117 (arguments
c2e05fa @dabrahams Add missing `='.
dabrahams authored
118 ("-st" "Strategy" "--strategy=" read-from-minibuffer)))
653cc89 @philjackson Added a merge menu.
philjackson authored
119
e882f3c @philjackson Put rebasing commands in menu.
philjackson authored
120 (rewriting
121 (actions
122 ("b" "Begin" magit-rewrite-start)
123 ("s" "Stop" magit-rewrite-stop)
124 ("a" "Abort" magit-rewrite-abort)
125 ("f" "Finish" magit-rewrite-finish)
126 ("*" "Set unused" magit-rewrite-set-unused)
327f0af @vanicat Submodule support.
vanicat authored
127 ("." "Set used" magit-rewrite-set-used)))
128
129 (submodule
130 (man-page "git-submodule")
131 (actions
132 ("u" "Update" magit-submodule-update)
133 ("b" "Both update and init" magit-submodule-update-init)
134 ("i" "Init" magit-submodule-init)
c042f4b @mbunkus Support for "git bisect" with "B" from status and log buffers
mbunkus authored
135 ("s" "Sync" magit-submodule-sync)))
136
137 (bisecting
138 (man-page "git-bisect")
139 (actions
140 ("b" "Bad" magit-bisect-bad)
141 ("g" "Good" magit-bisect-good)
142 ("k" "Skip" magit-bisect-skip)
143 ("l" "Log" magit-bisect-log)
144 ("r" "Reset" magit-bisect-reset)
145 ("s" "Start" magit-bisect-start)
c7b0db0 @mbunkus Support for "git bisect run"
mbunkus authored
146 ("u" "Run" magit-bisect-run)
c042f4b @mbunkus Support for "git bisect" with "B" from status and log buffers
mbunkus authored
147 ("v" "Visualize" magit-bisect-visualize))))
955adde @philjackson Actions just about ready, keymap-wise.
philjackson authored
148 "Holds the key, help, function mapping for the log-mode. If you
149 modify this make sure you reset `magit-key-mode-key-maps' to
150 nil.")
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
151
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
152 (defun magit-key-mode-delete-group (group)
4d1c52b @mbunkus Fix docstring for magit-key-mode-delete-group
mbunkus authored
153 "Delete a group from `magit-key-mode-key-maps'."
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
154 (let ((items (assoc group magit-key-mode-groups)))
155 (when items
156 ;; reset the cache
157 (setq magit-key-mode-key-maps nil)
158 ;; delete the whole group
159 (setq magit-key-mode-groups
160 (delq items magit-key-mode-groups))
161 ;; unbind the defun
162 (magit-key-mode-de-generate group))
163 magit-key-mode-groups))
164
165 (defun magit-key-mode-add-group (group)
166 "Add a new group to `magit-key-mode-key-maps'. If there's
167 already a group of that name then this will completely remove it
168 and put in its place an empty one of the same name."
169 (when (assoc group magit-key-mode-groups)
170 (magit-key-mode-delete-group group))
171 (setq magit-key-mode-groups
172 (cons (list group '(actions)) magit-key-mode-groups)))
173
174 (defun magit-key-mode-key-defined-p (for-group key)
175 "If KEY is defined as any of switch, argument or action within
176 FOR-GROUP then return t"
177 (catch 'result
178 (let ((options (magit-key-mode-options-for-group for-group)))
179 (dolist (type '(actions switches arguments))
180 (when (assoc key (assoc type options))
181 (throw 'result t))))))
70c3b4d @philjackson Func to add a new key group.
philjackson authored
182
8448f8a @philjackson Dedupe the magit-key-mode-insert-* functions.
philjackson authored
183 (defun magit-key-mode-update-group (for-group thing &rest args)
184 "Abstraction for setting values in `magit-key-mode-key-maps'."
185 (let* ((options (magit-key-mode-options-for-group for-group))
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
186 (things (assoc thing options))
187 (key (car args)))
4b34f17 @philjackson Fix up the group helper functions to handle a case where there are no cu...
philjackson authored
188 (if (cdr things)
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
189 (if (magit-key-mode-key-defined-p for-group key)
190 (error "%s is already defined in the %s group." key for-group)
191 (setcdr (cdr things) (cons args (cddr things))))
4b34f17 @philjackson Fix up the group helper functions to handle a case where there are no cu...
philjackson authored
192 (setcdr things (list args)))
193 (setq magit-key-mode-key-maps nil)
194 things))
8448f8a @philjackson Dedupe the magit-key-mode-insert-* functions.
philjackson authored
195
1f36bfb @philjackson Functions for plugins to add to the key groups.
philjackson authored
196 (defun magit-key-mode-insert-argument (for-group key desc arg read-func)
197 "Add a new binding (KEY) in FOR-GROUP which will use READ-FUNC
198 to receive input to apply to argument ARG git is run. DESC should
199 be a brief description of the binding."
8448f8a @philjackson Dedupe the magit-key-mode-insert-* functions.
philjackson authored
200 (magit-key-mode-update-group for-group 'arguments key desc arg read-func))
1f36bfb @philjackson Functions for plugins to add to the key groups.
philjackson authored
201
202 (defun magit-key-mode-insert-switch (for-group key desc switch)
203 "Add a new binding (KEY) in FOR-GROUP which will add SWITCH to git's
1a4df17 @greenrd Spelling
greenrd authored
204 command line when it runs. DESC should be a brief description of
1f36bfb @philjackson Functions for plugins to add to the key groups.
philjackson authored
205 the binding."
8448f8a @philjackson Dedupe the magit-key-mode-insert-* functions.
philjackson authored
206 (magit-key-mode-update-group for-group 'switches key desc switch))
1f36bfb @philjackson Functions for plugins to add to the key groups.
philjackson authored
207
208 (defun magit-key-mode-insert-action (for-group key desc func)
209 "Add a new binding (KEY) in FOR-GROUP which will run command
210 FUNC. DESC should be a brief description of the binding."
8448f8a @philjackson Dedupe the magit-key-mode-insert-* functions.
philjackson authored
211 (magit-key-mode-update-group for-group 'actions key desc func))
1f36bfb @philjackson Functions for plugins to add to the key groups.
philjackson authored
212
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
213 (defun magit-key-mode-options-for-group (for-group)
c9a33c6 @philjackson Docs.
philjackson authored
214 "Retrieve the options (switches, commands and arguments) for
215 the group FOR-GROUP."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
216 (or (cdr (assoc for-group magit-key-mode-groups))
217 (error "Unknown group '%s'" for-group)))
218
82a7d90 @philjackson Added a help function.
philjackson authored
219 (defun magit-key-mode-help (for-group)
d1070e6 @philjackson Docs.
philjackson authored
220 "Provide help for a key (which the user is prompted for) within
221 FOR-GROUP."
82a7d90 @philjackson Added a help function.
philjackson authored
222 (let* ((opts (magit-key-mode-options-for-group for-group))
89db2aa @elibarzilay Improve the `??' man-page showing.
elibarzilay authored
223 (man-page (cadr (assoc 'man-page opts)))
224 (seq (read-key-sequence
225 (format "Enter command prefix%s: "
226 (if man-page
227 (format ", `?' for man `%s'" man-page)
228 ""))))
82a7d90 @philjackson Added a help function.
philjackson authored
229 (actions (cdr (assoc 'actions opts))))
89db2aa @elibarzilay Improve the `??' man-page showing.
elibarzilay authored
230 (cond
231 ;; if it is an action popup the help for the to-be-run function
232 ((assoc seq actions) (describe-function (nth 2 (assoc seq actions))))
233 ;; if there is "?" show a man page if there is one
234 ((equal seq "?")
235 (if man-page
236 (man man-page)
237 (error "No man page associated with `%s'" for-group)))
238 (t (error "No help associated with `%s'" seq)))))
82a7d90 @philjackson Added a help function.
philjackson authored
239
3ebcb08 @philjackson Hitting ret on args does same as using prefix key.
philjackson authored
240 (defun magit-key-mode-exec-at-point ()
241 "Run action/args/option at point."
242 (interactive)
243 (let* ((key (or (get-text-property (point) 'key-group-executor)
244 (error "Nothing at point to do.")))
245 (def (lookup-key (current-local-map) key)))
246 (call-interactively def)))
62518e3 @elibarzilay Make TAB jump between keys in `magit-key-mode'.
elibarzilay authored
247 (defun magit-key-mode-jump-to-next-exec ()
248 "Jump to the next action/args/option point."
249 (interactive)
250 (let* ((oldp (point))
251 (old (get-text-property oldp 'key-group-executor))
252 (p (if (= oldp (point-max)) (point-min) (1+ oldp))))
253 (while (let ((new (get-text-property p 'key-group-executor)))
254 (and (not (= p oldp)) (or (not new) (eq new old))))
255 (setq p (if (= p (point-max)) (point-min) (1+ p))))
256 (goto-char p)
257 (skip-chars-forward " ")))
3ebcb08 @philjackson Hitting ret on args does same as using prefix key.
philjackson authored
258
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
259 (defun magit-key-mode-build-keymap (for-group)
260 "Construct a normal looking keymap for the key mode to use and
261 put it in magit-key-mode-key-maps for fast lookup."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
262 (let* ((options (magit-key-mode-options-for-group for-group))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
263 (actions (cdr (assoc 'actions options)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
264 (switches (cdr (assoc 'switches options)))
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
265 (arguments (cdr (assoc 'arguments options)))
266 (map (make-sparse-keymap)))
1cd5b33 @pjweisberg magit-key-mode-build-keymap: Use a suppressed keymap
pjweisberg authored
267 (suppress-keymap map 'nodigits)
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
268 ;; ret dwim
269 (define-key map (kbd "RET") 'magit-key-mode-exec-at-point)
62518e3 @elibarzilay Make TAB jump between keys in `magit-key-mode'.
elibarzilay authored
270 ;; tab jumps to the next "button"
271 (define-key map (kbd "TAB") 'magit-key-mode-jump-to-next-exec)
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
272
2ed6653 @elibarzilay Make `q' quit magit-key-mode popups.
elibarzilay authored
273 ;; all maps should `quit' with `C-g' or `q'
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
274 (define-key map (kbd "C-g") `(lambda ()
275 (interactive)
276 (magit-key-mode-command nil)))
2ed6653 @elibarzilay Make `q' quit magit-key-mode popups.
elibarzilay authored
277 (define-key map (kbd "q") `(lambda ()
278 (interactive)
279 (magit-key-mode-command nil)))
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
280 ;; run help
281 (define-key map (kbd "?") `(lambda ()
282 (interactive)
283 (magit-key-mode-help ',for-group)))
284
2a53872 @elibarzilay Use a little utility function to do the key binding.
elibarzilay authored
285 (flet ((defkey (k action)
74e4024 @vanicat Correct a bug in 2a538725ee138c80408b611181a4faa779ebd5b8
vanicat authored
286 (when (and (lookup-key map (car k))
287 (not (numberp (lookup-key map (car k)))))
2a53872 @elibarzilay Use a little utility function to do the key binding.
elibarzilay authored
288 (message "Warning: overriding binding for `%s' in %S"
289 (car k) for-group)
290 (ding)
291 (sit-for 2))
292 (define-key map (car k)
293 `(lambda () (interactive) ,action))))
294 (when actions
295 (dolist (k actions)
296 (defkey k `(magit-key-mode-command ',(nth 2 k)))))
297 (when switches
298 (dolist (k switches)
299 (defkey k `(magit-key-mode-add-option ',for-group ,(nth 2 k)))))
300 (when arguments
301 (dolist (k arguments)
302 (defkey k `(magit-key-mode-add-argument
303 ',for-group ,(nth 2 k) ',(nth 3 k))))))
304
6183af2 @elibarzilay Merge redundant `let' into the surrounding `let*'.
elibarzilay authored
305 (aput 'magit-key-mode-key-maps for-group map)
306 map))
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
307
d459556 @pjweisberg Make magit-key-mode-popup-foo commands propagate their prefix arg
pjweisberg authored
308 (defvar magit-key-mode-prefix nil
309 "For internal use. Holds the prefix argument to the command
310 that brought up the key-mode window, so it can be used by the
311 command that's eventually invoked.")
312
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
313 (defun magit-key-mode-command (func)
314 (let ((args '()))
315 ;; why can't maphash return a list?!
316 (maphash (lambda (k v)
7058e07 @philjackson Added Pickaxe options.
philjackson authored
317 (push (concat k (shell-quote-argument v)) args))
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
318 magit-key-mode-current-args)
d459556 @pjweisberg Make magit-key-mode-popup-foo commands propagate their prefix arg
pjweisberg authored
319 (let ((magit-custom-options (append args magit-key-mode-current-options))
320 (current-prefix-arg (or current-prefix-arg magit-key-mode-prefix)))
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
321 (set-window-configuration magit-log-mode-window-conf)
c0324a5 @philjackson Fixed quit.
philjackson authored
322 (when func
e882f3c @philjackson Put rebasing commands in menu.
philjackson authored
323 (call-interactively func))
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
324 (magit-key-mode-kill-buffer))))
5be31a3 @philjackson Some font-locking.
philjackson authored
325
217febc @philjackson Args being remembered.
philjackson authored
326 (defvar magit-key-mode-current-args nil
327 "A hash-table of current argument set (which will eventually
328 make it to the git command-line).")
329
330 (defun magit-key-mode-add-argument (for-group arg-name input-func)
331 (let ((input (funcall input-func (concat arg-name ": "))))
332 (puthash arg-name input magit-key-mode-current-args)
fc2fe2b @philjackson Arguments now being passed through.
philjackson authored
333 (magit-key-mode-redraw for-group)))
217febc @philjackson Args being remembered.
philjackson authored
334
335 (defvar magit-key-mode-current-options '()
336 "Current option set (which will eventually make it to the git
337 command-line).")
0604574 @philjackson Basic argument display in place.
philjackson authored
338
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
339 (defun magit-key-mode-add-option (for-group option-name)
340 "Toggles the appearance of OPTION-NAME in
341 `magit-key-mode-current-options'."
342 (if (not (member option-name magit-key-mode-current-options))
343 (add-to-list 'magit-key-mode-current-options option-name)
344 (setq magit-key-mode-current-options
345 (delete option-name magit-key-mode-current-options)))
346 (magit-key-mode-redraw for-group))
5be31a3 @philjackson Some font-locking.
philjackson authored
347
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
348 (defun magit-key-mode-kill-buffer ()
c351215 @philjackson C-g kills buffer.
philjackson authored
349 (interactive)
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
350 (kill-buffer magit-key-mode-buf-name))
351
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
352 (defvar magit-log-mode-window-conf nil
353 "Pre-popup window configuration.")
354
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
355 (defun magit-key-mode (for-group &optional original-opts)
d1070e6 @philjackson Docs.
philjackson authored
356 "Mode for magit key selection. All commands, switches and
357 options can be toggled/actioned with the key combination
1a4df17 @greenrd Spelling
greenrd authored
358 highlighted before the description."
0a2965c @philjackson Experiment with a new style for the mappings.
philjackson authored
359 (interactive)
09ab17d @philjackson Doc.
philjackson authored
360 ;; save the window config to restore it as was (no need to make this
361 ;; buffer local)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
362 (setq magit-log-mode-window-conf
363 (current-window-configuration))
364 ;; setup the mode, draw the buffer
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
365 (let ((buf (get-buffer-create magit-key-mode-buf-name)))
c3971bb @philjackson Revert (again) to the split-window method of display.
philjackson authored
366 (delete-other-windows)
367 (split-window-vertically)
b03829c @philjackson Make sure the menu turns up at the bottom of the window.
philjackson authored
368 (other-window 1)
c3971bb @philjackson Revert (again) to the split-window method of display.
philjackson authored
369 (switch-to-buffer buf)
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
370 (kill-all-local-variables)
55f0a9c @philjackson make-variable-buffer-local -> make-local-variable.
philjackson authored
371 (set (make-local-variable
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
372 'magit-key-mode-current-options)
373 original-opts)
55f0a9c @philjackson make-variable-buffer-local -> make-local-variable.
philjackson authored
374 (set (make-local-variable
217febc @philjackson Args being remembered.
philjackson authored
375 'magit-key-mode-current-args)
376 (make-hash-table))
d459556 @pjweisberg Make magit-key-mode-popup-foo commands propagate their prefix arg
pjweisberg authored
377 (set (make-local-variable 'magit-key-mode-prefix) current-prefix-arg)
fe2cbfc @philjackson Message to hint at what to do when presented with key menu.
philjackson authored
378 (magit-key-mode-redraw for-group))
2b8d098 @philjackson Make the instructional help _even_ clearer when a key group buffer is sh...
philjackson authored
379 (message
380 (concat
27c9fe4 @jwiegley Shorten popup prompt text
authored
381 "Type a prefix key to toggle it. Run 'actions' with their prefixes. "
382 "'?' for more help.")))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
383
3ebcb08 @philjackson Hitting ret on args does same as using prefix key.
philjackson authored
384 (defun magit-key-mode-get-key-map (for-group)
385 "Get or build the keymap for FOR-GROUP."
386 (or (cdr (assoc for-group magit-key-mode-key-maps))
387 (magit-key-mode-build-keymap for-group)))
388
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
389 (defun magit-key-mode-redraw (for-group)
b335871 @philjackson Options var now buffer local.
philjackson authored
390 "(re)draw the magit key buffer."
6465329 @philjackson Keep cursor where it was after executing a command with RET.
philjackson authored
391 (let ((buffer-read-only nil)
392 (old-point (point)))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
393 (erase-buffer)
394 (make-local-variable 'font-lock-defaults)
3ebcb08 @philjackson Hitting ret on args does same as using prefix key.
philjackson authored
395 (use-local-map (magit-key-mode-get-key-map for-group))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
396 (magit-key-mode-draw for-group)
4211822 @philjackson Clear whitespace from key buffer.
philjackson authored
397 (delete-trailing-whitespace)
6465329 @philjackson Keep cursor where it was after executing a command with RET.
philjackson authored
398 (setq mode-name "magit-key-mode" major-mode 'magit-key-mode)
399 (goto-char old-point))
e04f27d @philjackson Window config stored and reapplied on quit.
philjackson authored
400 (setq buffer-read-only t)
401 (fit-window-to-buffer))
4e7c192 @philjackson Moved the menu/key definitions into another file.
philjackson authored
402
4ab9bab @philjackson Start of on-the-fly font-locking.
philjackson authored
403 (defun magit-key-mode-draw-header (header)
2cf4192 @philjackson Docs.
philjackson authored
404 "Draw a header with the correct face."
9108080 @elibarzilay Make `magit-key-mode-draw-header' get just the header, without a newline...
elibarzilay authored
405 (insert (propertize header 'face 'font-lock-keyword-face) "\n"))
4ab9bab @philjackson Start of on-the-fly font-locking.
philjackson authored
406
62baed8 @philjackson Optionally columnify options too.
philjackson authored
407 (defvar magit-key-mode-args-in-cols nil
408 "When true, draw arguments in columns as with switches and
409 options.")
410
ab566aa @philjackson draw-args function.
philjackson authored
411 (defun magit-key-mode-draw-args (args)
2cf4192 @philjackson Docs.
philjackson authored
412 "Draw the args part of the menu."
0aa86ef @elibarzilay New `magit-key-mode-draw-args' function that does most of the repetitive
elibarzilay authored
413 (magit-key-mode-draw-buttons
414 "Args"
415 args
416 (lambda (x)
417 (format "(%s) %s"
418 (nth 2 x)
419 (propertize (gethash (nth 2 x) magit-key-mode-current-args "")
420 'face 'widget-field)))
421 (not magit-key-mode-args-in-cols)))
ab566aa @philjackson draw-args function.
philjackson authored
422
b67b255 @philjackson draw-switches function.
philjackson authored
423 (defun magit-key-mode-draw-switches (switches)
2cf4192 @philjackson Docs.
philjackson authored
424 "Draw the switches part of the menu."
0aa86ef @elibarzilay New `magit-key-mode-draw-args' function that does most of the repetitive
elibarzilay authored
425 (magit-key-mode-draw-buttons
426 "Switches"
427 switches
428 (lambda (x)
429 (format "(%s)" (let ((s (nth 2 x)))
430 (if (member s magit-key-mode-current-options)
431 (propertize s 'face 'font-lock-warning-face)
432 s))))))
e19f302 @philjackson Columify switches too.
philjackson authored
433
02600a8 @philjackson Pretty layout of actions.
philjackson authored
434 (defun magit-key-mode-draw-actions (actions)
2cf4192 @philjackson Docs.
philjackson authored
435 "Draw the actions part of the menu."
0aa86ef @elibarzilay New `magit-key-mode-draw-args' function that does most of the repetitive
elibarzilay authored
436 (magit-key-mode-draw-buttons "Actions" actions nil))
437
438 (defun magit-key-mode-draw-buttons (section xs maker
439 &optional one-col-each)
440 (when xs
441 (magit-key-mode-draw-header section)
442 (magit-key-mode-draw-in-cols
443 (mapcar (lambda (x)
444 (let* ((head (propertize (car x) 'face 'font-lock-builtin-face))
445 (desc (nth 1 x))
446 (more (and maker (funcall maker x)))
447 (text (format " %s: %s%s%s"
448 head desc (if more " " "") (or more ""))))
449 (propertize text 'key-group-executor (car x))))
450 xs)
451 one-col-each)))
452
453 (defun magit-key-mode-draw-in-cols (strings one-col-each)
62baed8 @philjackson Optionally columnify options too.
philjackson authored
454 "Given a list of strings, print in columns (using `insert'). If
455 ONE-COL-EACH is true then don't columify, but rather, draw each
456 item on one line."
564726a @philjackson Use `window-width' to wrap menu items.
philjackson authored
457 (let ((longest-act (apply 'max (mapcar 'length strings))))
fd23002 @philjackson Don't add a newline if a menu item is the last.
philjackson authored
458 (while strings
459 (let ((str (car strings)))
70ee1c5 @philjackson Added a branching menu.
philjackson authored
460 (let ((padding (make-string (- (+ longest-act 3) (length str)) ? )))
fd23002 @philjackson Don't add a newline if a menu item is the last.
philjackson authored
461 (insert str)
62baed8 @philjackson Optionally columnify options too.
philjackson authored
462 (if (or one-col-each
463 (and (> (+ (length padding) ;
464 (current-column)
465 longest-act)
466 (window-width))
467 (cdr strings)))
fd23002 @philjackson Don't add a newline if a menu item is the last.
philjackson authored
468 (insert "\n")
469 (insert padding))))
470 (setq strings (cdr strings))))
471 (insert "\n"))
02600a8 @philjackson Pretty layout of actions.
philjackson authored
472
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
473 (defun magit-key-mode-draw (for-group)
5be31a3 @philjackson Some font-locking.
philjackson authored
474 "Function used to draw actions, switches and parameters."
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
475 (let* ((options (magit-key-mode-options-for-group for-group))
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
476 (switches (cdr (assoc 'switches options)))
0604574 @philjackson Basic argument display in place.
philjackson authored
477 (arguments (cdr (assoc 'arguments options)))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
478 (actions (cdr (assoc 'actions options))))
b67b255 @philjackson draw-switches function.
philjackson authored
479 (magit-key-mode-draw-switches switches)
bc47f3f @philjackson Put actions at the bottom of the group buffer to indicate flow.
philjackson authored
480 (magit-key-mode-draw-args arguments)
04a5e59 @philjackson Extra blank line at the bottom of the key buffer. Fixes #115.
philjackson authored
481 (magit-key-mode-draw-actions actions)
482 (insert "\n")))
f6e921d @philjackson Simple pass at drawing actions.
philjackson authored
483
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
484 (defun magit-key-mode-de-generate (group)
485 "Unbind the function for GROUP."
486 (fmakunbound
487 (intern (concat "magit-key-mode-popup-" (symbol-name group)))))
488
489 (defun magit-key-mode-generate (group)
490 "Generate the key-group menu for GROUP"
491 (let ((opts (magit-key-mode-options-for-group group)))
527cc7a @philjackson Generate interactive popup functions (thanks Rémi).
philjackson authored
492 (eval
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
493 `(defun ,(intern (concat "magit-key-mode-popup-" (symbol-name group))) nil
494 ,(concat "Key menu for " (symbol-name group))
527cc7a @philjackson Generate interactive popup functions (thanks Rémi).
philjackson authored
495 (interactive)
7447930 @philjackson Make the key-mode plugin interface a little nicer to use.
philjackson authored
496 (magit-key-mode (quote ,group))))))
527cc7a @philjackson Generate interactive popup functions (thanks Rémi).
philjackson authored
497
790dd88 @philjackson Remove debugging function, docs.
philjackson authored
498 ;; create the interactive functions for the key mode popups (which are
499 ;; applied in the top-level key maps)
527cc7a @philjackson Generate interactive popup functions (thanks Rémi).
philjackson authored
500 (mapc (lambda (g)
501 (magit-key-mode-generate (car g)))
502 magit-key-mode-groups)
503
5570e6a @philjackson Renamed key file, added kill-buffer.
philjackson authored
504 (provide 'magit-key-mode)
Something went wrong with that request. Please try again.