2010-08-30 22:23:59 +02:00
|
|
|
(defvar magit-mode-map
|
|
|
|
(let ((map (make-keymap)))
|
|
|
|
(suppress-keymap map t)
|
|
|
|
(define-key map (kbd "n") 'magit-goto-next-section)
|
|
|
|
(define-key map (kbd "p") 'magit-goto-previous-section)
|
|
|
|
(define-key map (kbd "TAB") 'magit-toggle-section)
|
|
|
|
(define-key map (kbd "<backtab>") 'magit-expand-collapse-section)
|
|
|
|
(define-key map (kbd "1") 'magit-show-level-1)
|
|
|
|
(define-key map (kbd "2") 'magit-show-level-2)
|
|
|
|
(define-key map (kbd "3") 'magit-show-level-3)
|
|
|
|
(define-key map (kbd "4") 'magit-show-level-4)
|
|
|
|
(define-key map (kbd "M-1") 'magit-show-level-1-all)
|
|
|
|
(define-key map (kbd "M-2") 'magit-show-level-2-all)
|
|
|
|
(define-key map (kbd "M-3") 'magit-show-level-3-all)
|
|
|
|
(define-key map (kbd "M-4") 'magit-show-level-4-all)
|
|
|
|
(define-key map (kbd "M-h") 'magit-show-only-files)
|
|
|
|
(define-key map (kbd "M-H") 'magit-show-only-files-all)
|
|
|
|
(define-key map (kbd "M-s") 'magit-show-level-4)
|
|
|
|
(define-key map (kbd "M-S") 'magit-show-level-4-all)
|
|
|
|
(define-key map (kbd "<M-left>") 'magit-goto-parent-section)
|
|
|
|
(define-key map (kbd "g") 'magit-refresh)
|
|
|
|
(define-key map (kbd "G") 'magit-refresh-all)
|
|
|
|
(define-key map (kbd "?") 'magit-describe-item)
|
|
|
|
(define-key map (kbd "!") 'magit-shell-command)
|
|
|
|
(define-key map (kbd ":") 'magit-git-command)
|
|
|
|
(define-key map (kbd "RET") 'magit-visit-item)
|
|
|
|
(define-key map (kbd "SPC") 'magit-show-item-or-scroll-up)
|
|
|
|
(define-key map (kbd "DEL") 'magit-show-item-or-scroll-down)
|
|
|
|
(define-key map (kbd "C-w") 'magit-copy-item-as-kill)
|
|
|
|
(define-key map (kbd "R") 'magit-rebase-step)
|
2010-09-01 11:45:09 +02:00
|
|
|
(define-key map (kbd "t") (lambda () (interactive) (magit-key-mode 'tagging)))
|
2010-09-01 11:17:21 +02:00
|
|
|
(define-key map (kbd "r") (lambda () (interactive) (magit-key-mode 'rewriting)))
|
2010-09-01 23:28:33 +02:00
|
|
|
(define-key map (kbd "P") (lambda () (interactive) (magit-key-mode 'pushing)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "f") 'magit-remote-update)
|
2010-09-01 22:49:58 +02:00
|
|
|
(define-key map (kbd "b") (lambda () (interactive) (magit-key-mode 'branching)))
|
2010-09-01 23:28:33 +02:00
|
|
|
(define-key map (kbd "F") (lambda () (interactive) (magit-key-mode 'pulling)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "c") 'magit-log-edit)
|
2010-08-31 19:14:42 +02:00
|
|
|
(define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "$") 'magit-display-process)
|
|
|
|
(define-key map (kbd "E") 'magit-interactive-rebase)
|
|
|
|
(define-key map (kbd "q") 'quit-window)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-commit-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-status-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "-") 'magit-diff-smaller-hunks)
|
|
|
|
(define-key map (kbd "+") 'magit-diff-larger-hunks)
|
|
|
|
(define-key map (kbd "0") 'magit-diff-default-hunks)
|
|
|
|
(define-key map (kbd "s") 'magit-stage-item)
|
|
|
|
(define-key map (kbd "S") 'magit-stage-all)
|
|
|
|
(define-key map (kbd "u") 'magit-unstage-item)
|
|
|
|
(define-key map (kbd "U") 'magit-unstage-all)
|
|
|
|
(define-key map (kbd "i") 'magit-ignore-item)
|
|
|
|
(define-key map (kbd "I") 'magit-ignore-item-locally)
|
|
|
|
(define-key map (kbd ".") 'magit-mark-item)
|
|
|
|
(define-key map (kbd "=") 'magit-diff-with-mark)
|
|
|
|
(define-key map (kbd "d") 'magit-diff-working-tree)
|
|
|
|
(define-key map (kbd "D") 'magit-diff)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
2010-09-01 22:49:58 +02:00
|
|
|
(define-key map (kbd "b") (lambda () (interactive) (magit-key-mode 'branching)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "m") 'magit-manual-merge)
|
|
|
|
(define-key map (kbd "M") 'magit-automatic-merge)
|
|
|
|
(define-key map (kbd "k") 'magit-discard-item)
|
|
|
|
(define-key map (kbd "e") 'magit-interactive-resolve-item)
|
|
|
|
(define-key map (kbd "C") 'magit-add-log)
|
|
|
|
(define-key map (kbd "x") 'magit-reset-head)
|
|
|
|
(define-key map (kbd "X") 'magit-reset-working-tree)
|
|
|
|
(define-key map (kbd "z") 'magit-stash)
|
|
|
|
(define-key map (kbd "Z") 'magit-stash-snapshot)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-stash-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "-") 'magit-diff-smaller-hunks)
|
|
|
|
(define-key map (kbd "+") 'magit-diff-larger-hunks)
|
|
|
|
(define-key map (kbd "0") 'magit-diff-default-hunks)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-log-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd ".") 'magit-mark-item)
|
|
|
|
(define-key map (kbd "=") 'magit-diff-with-mark)
|
|
|
|
(define-key map (kbd "d") 'magit-diff-working-tree)
|
|
|
|
(define-key map (kbd "D") 'magit-diff)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "s") 'magit-log-grep)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
2010-09-01 22:49:58 +02:00
|
|
|
(define-key map (kbd "b") (lambda () (interactive) (magit-key-mode 'branching)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "m") 'magit-manual-merge)
|
|
|
|
(define-key map (kbd "M") 'magit-automatic-merge)
|
|
|
|
(define-key map (kbd "x") 'magit-reset-head)
|
|
|
|
(define-key map (kbd "e") 'magit-log-show-more-entries)
|
2010-08-31 19:14:42 +02:00
|
|
|
(define-key map (kbd "l") (lambda () (interactive) (magit-key-mode 'logging)))
|
2010-08-30 22:23:59 +02:00
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-reflog-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd ".") 'magit-mark-item)
|
|
|
|
(define-key map (kbd "=") 'magit-diff-with-mark)
|
|
|
|
(define-key map (kbd "d") 'magit-diff-working-tree)
|
|
|
|
(define-key map (kbd "D") 'magit-diff)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
|
|
|
(define-key map (kbd "x") 'magit-reset-head)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-diff-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "-") 'magit-diff-smaller-hunks)
|
|
|
|
(define-key map (kbd "+") 'magit-diff-larger-hunks)
|
|
|
|
(define-key map (kbd "0") 'magit-diff-default-hunks)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
|
|
|
map))
|
|
|
|
|
|
|
|
(defvar magit-wazzup-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd ".") 'magit-mark-item)
|
|
|
|
(define-key map (kbd "=") 'magit-diff-with-mark)
|
|
|
|
(define-key map (kbd "d") 'magit-diff-working-tree)
|
|
|
|
(define-key map (kbd "D") 'magit-diff)
|
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick-item)
|
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
2010-09-01 22:49:58 +02:00
|
|
|
(define-key map (kbd "b") (lambda () (interactive) (magit-key-mode 'branching)))
|
2010-08-30 22:23:59 +02:00
|
|
|
(define-key map (kbd "m") 'magit-manual-merge)
|
|
|
|
(define-key map (kbd "M") 'magit-automatic-merge)
|
|
|
|
(define-key map (kbd "x") 'magit-reset-head)
|
|
|
|
(define-key map (kbd "i") 'magit-ignore-item)
|
|
|
|
map))
|
|
|
|
|
2010-08-30 23:11:40 +02:00
|
|
|
(defvar magit-key-mode-key-maps '()
|
|
|
|
"This will be filled lazily with proper `define-key' built
|
|
|
|
keymaps as they're reqeusted.")
|
2010-08-30 22:23:59 +02:00
|
|
|
|
2010-08-31 09:42:21 +02:00
|
|
|
(defvar magit-key-mode-buf-name "*magit-key*"
|
|
|
|
"Name of the buffer.")
|
|
|
|
|
2010-08-30 23:11:40 +02:00
|
|
|
(defvar magit-key-mode-groups
|
|
|
|
'((logging
|
|
|
|
(actions
|
|
|
|
("l" "One line log" magit-log)
|
|
|
|
("L" "Long log" magit-log-long)
|
|
|
|
("h" "Reflog" magit-reflog)
|
2010-08-31 09:42:21 +02:00
|
|
|
("H" "Reflog on head" magit-reflog-head))
|
|
|
|
(switches
|
2010-09-01 00:51:58 +02:00
|
|
|
("-m" "Only merge commits" "--merges")
|
2010-08-31 13:16:23 +02:00
|
|
|
("-f" "First parent" "--first-parent")
|
2010-09-01 11:46:54 +02:00
|
|
|
("-i" "Case insesnitive patterns" "-i")
|
2010-08-31 19:53:37 +02:00
|
|
|
("-a" "All" "--all"))
|
|
|
|
(arguments
|
2010-09-01 01:03:35 +02:00
|
|
|
("=b" "Branches" "--branches" read-from-minibuffer)
|
2010-09-01 00:46:50 +02:00
|
|
|
("=a" "Author" "--author" read-from-minibuffer)
|
2010-09-01 11:17:21 +02:00
|
|
|
("=g" "Grep" "--grep" read-from-minibuffer)))
|
|
|
|
|
2010-09-01 23:28:33 +02:00
|
|
|
(pushing
|
|
|
|
(actions
|
2010-09-02 00:50:25 +02:00
|
|
|
("p" "Push" magit-push))
|
|
|
|
(switches
|
|
|
|
("-d" "Dry run" "-n")))
|
2010-09-01 23:28:33 +02:00
|
|
|
|
|
|
|
(pulling
|
|
|
|
(actions
|
|
|
|
("p" "Pull" magit-pull))
|
|
|
|
(switches
|
|
|
|
("-r" "Rebase" "--rebase")))
|
|
|
|
|
2010-09-01 22:49:58 +02:00
|
|
|
(branching
|
|
|
|
(actions
|
2010-09-01 23:13:08 +02:00
|
|
|
("V" "Branch manager" magit-show-branches)
|
|
|
|
("B" "Create" magit-create-branch)
|
|
|
|
("m" "Move" magit-move-branch)
|
|
|
|
("d" "Delete" magit-delete-branch)
|
2010-09-01 22:49:58 +02:00
|
|
|
("c" "Checkout" magit-checkout)))
|
|
|
|
|
2010-09-01 11:45:09 +02:00
|
|
|
(tagging
|
|
|
|
(actions
|
|
|
|
("t" "Lightweight" magit-tag)
|
|
|
|
("T" "Annotated" magit-annotated-tag))
|
|
|
|
(switches
|
|
|
|
("-f" "Force" "-f")))
|
|
|
|
|
2010-09-01 11:17:21 +02:00
|
|
|
(rewriting
|
|
|
|
(actions
|
|
|
|
("b" "Begin" magit-rewrite-start)
|
|
|
|
("s" "Stop" magit-rewrite-stop)
|
|
|
|
("a" "Abort" magit-rewrite-abort)
|
|
|
|
("f" "Finish" magit-rewrite-finish)
|
|
|
|
("*" "Set unused" magit-rewrite-set-unused)
|
|
|
|
("." "Set used" magit-rewrite-set-used))))
|
2010-08-31 00:06:29 +02:00
|
|
|
"Holds the key, help, function mapping for the log-mode. If you
|
|
|
|
modify this make sure you reset `magit-key-mode-key-maps' to
|
|
|
|
nil.")
|
2010-08-30 23:11:40 +02:00
|
|
|
|
2010-08-31 00:28:52 +02:00
|
|
|
(defun magit-key-mode-options-for-group (for-group)
|
|
|
|
(or (cdr (assoc for-group magit-key-mode-groups))
|
|
|
|
(error "Unknown group '%s'" for-group)))
|
|
|
|
|
2010-08-30 23:11:40 +02:00
|
|
|
(defun magit-key-mode-build-keymap (for-group)
|
|
|
|
"Construct a normal looking keymap for the key mode to use and
|
|
|
|
put it in magit-key-mode-key-maps for fast lookup."
|
2010-08-31 00:28:52 +02:00
|
|
|
(let* ((options (magit-key-mode-options-for-group for-group))
|
2010-08-30 23:11:40 +02:00
|
|
|
(actions (cdr (assoc 'actions options)))
|
2010-08-31 09:42:21 +02:00
|
|
|
(switches (cdr (assoc 'switches options)))
|
2010-08-31 19:53:37 +02:00
|
|
|
(arguments (cdr (assoc 'arguments options))))
|
2010-08-30 23:50:57 +02:00
|
|
|
(let ((map (make-sparse-keymap)))
|
2010-08-31 00:28:52 +02:00
|
|
|
;; all maps should 'quit' with C-g
|
2010-08-31 22:39:52 +02:00
|
|
|
(define-key map (kbd "C-g") (lambda ()
|
|
|
|
(interactive)
|
2010-09-01 00:41:03 +02:00
|
|
|
(magit-key-mode-command nil)))
|
2010-08-30 23:50:57 +02:00
|
|
|
(when actions
|
2010-08-30 23:11:40 +02:00
|
|
|
(dolist (k actions)
|
2010-08-31 09:42:21 +02:00
|
|
|
(define-key map (car k) `(lambda ()
|
|
|
|
(interactive)
|
2010-09-01 00:34:46 +02:00
|
|
|
(magit-key-mode-command ',(nth 2 k))))))
|
2010-08-31 09:42:21 +02:00
|
|
|
(when switches
|
|
|
|
(dolist (k switches)
|
|
|
|
(define-key map (car k) `(lambda ()
|
2010-08-31 13:16:23 +02:00
|
|
|
(interactive)
|
|
|
|
(magit-key-mode-add-option
|
|
|
|
',for-group
|
|
|
|
,(nth 2 k))))))
|
2010-08-31 19:53:37 +02:00
|
|
|
(when arguments
|
|
|
|
(dolist (k arguments)
|
|
|
|
(define-key map (car k) `(lambda ()
|
|
|
|
(interactive)
|
|
|
|
(magit-key-mode-add-argument
|
|
|
|
',for-group
|
2010-08-31 23:04:36 +02:00
|
|
|
,(nth 2 k)
|
|
|
|
',(nth 3 k))))))
|
2010-08-31 09:42:21 +02:00
|
|
|
(aput 'magit-key-mode-key-maps for-group map)
|
2010-08-30 23:50:57 +02:00
|
|
|
map)))
|
2010-08-30 23:11:40 +02:00
|
|
|
|
2010-09-01 00:34:46 +02:00
|
|
|
(defun magit-key-mode-command (func)
|
|
|
|
(let ((args '()))
|
|
|
|
;; why can't maphash return a list?!
|
|
|
|
(maphash (lambda (k v)
|
|
|
|
(push (concat k "=" (shell-quote-argument v)) args))
|
|
|
|
magit-key-mode-current-args)
|
|
|
|
(let ((magit-custom-options (append args magit-key-mode-current-options)))
|
|
|
|
(set-window-configuration magit-log-mode-window-conf)
|
2010-09-01 00:41:03 +02:00
|
|
|
(when func
|
2010-09-01 11:17:21 +02:00
|
|
|
(call-interactively func))
|
2010-09-01 00:34:46 +02:00
|
|
|
(magit-key-mode-kill-buffer))))
|
2010-08-31 00:45:51 +02:00
|
|
|
|
2010-08-31 23:04:36 +02:00
|
|
|
(defvar magit-key-mode-current-args nil
|
|
|
|
"A hash-table of current argument set (which will eventually
|
|
|
|
make it to the git command-line).")
|
|
|
|
|
|
|
|
(defun debug-args ()
|
|
|
|
(interactive)
|
|
|
|
(maphash (lambda (k v) (print (format "%s: %s" k v))) magit-key-mode-current-args))
|
|
|
|
|
|
|
|
(defun magit-key-mode-add-argument (for-group arg-name input-func)
|
|
|
|
(let ((input (funcall input-func (concat arg-name ": "))))
|
|
|
|
(puthash arg-name input magit-key-mode-current-args)
|
2010-09-01 00:34:46 +02:00
|
|
|
(magit-key-mode-redraw for-group)))
|
2010-08-31 23:04:36 +02:00
|
|
|
|
|
|
|
(defvar magit-key-mode-current-options '()
|
|
|
|
"Current option set (which will eventually make it to the git
|
|
|
|
command-line).")
|
2010-08-31 19:53:37 +02:00
|
|
|
|
2010-08-31 09:42:21 +02:00
|
|
|
(defun magit-key-mode-add-option (for-group option-name)
|
|
|
|
"Toggles the appearance of OPTION-NAME in
|
|
|
|
`magit-key-mode-current-options'."
|
|
|
|
(if (not (member option-name magit-key-mode-current-options))
|
|
|
|
(add-to-list 'magit-key-mode-current-options option-name)
|
|
|
|
(setq magit-key-mode-current-options
|
|
|
|
(delete option-name magit-key-mode-current-options)))
|
|
|
|
(magit-key-mode-redraw for-group))
|
2010-08-31 00:45:51 +02:00
|
|
|
|
2010-08-31 09:42:21 +02:00
|
|
|
(defun magit-key-mode-kill-buffer ()
|
2010-08-31 19:15:05 +02:00
|
|
|
(interactive)
|
2010-08-31 09:42:21 +02:00
|
|
|
(kill-buffer magit-key-mode-buf-name))
|
|
|
|
|
2010-08-31 22:39:52 +02:00
|
|
|
(defvar magit-log-mode-window-conf nil
|
|
|
|
"Pre-popup window configuration.")
|
|
|
|
|
2010-08-31 09:42:21 +02:00
|
|
|
(defun magit-key-mode (for-group &optional original-opts)
|
2010-08-31 19:38:44 +02:00
|
|
|
"Mode for magit key selection."
|
2010-08-30 23:11:40 +02:00
|
|
|
(interactive)
|
2010-08-31 22:48:06 +02:00
|
|
|
;; save the window config to restore it as was (no need to make this
|
|
|
|
;; buffer local)
|
2010-08-31 22:39:52 +02:00
|
|
|
(setq magit-log-mode-window-conf
|
|
|
|
(current-window-configuration))
|
|
|
|
;; setup the mode, draw the buffer
|
2010-08-31 09:42:21 +02:00
|
|
|
(let ((buf (get-buffer-create magit-key-mode-buf-name)))
|
2010-09-01 11:24:17 +02:00
|
|
|
(delete-other-windows)
|
|
|
|
(split-window-vertically)
|
2010-09-01 21:36:02 +02:00
|
|
|
(other-window 1)
|
2010-09-01 11:24:17 +02:00
|
|
|
(switch-to-buffer buf)
|
2010-08-31 22:39:52 +02:00
|
|
|
(kill-all-local-variables)
|
|
|
|
(set (make-variable-buffer-local
|
|
|
|
'magit-key-mode-current-options)
|
|
|
|
original-opts)
|
2010-08-31 23:04:36 +02:00
|
|
|
(set (make-variable-buffer-local
|
|
|
|
'magit-key-mode-current-args)
|
|
|
|
(make-hash-table))
|
2010-08-31 22:39:52 +02:00
|
|
|
(magit-key-mode-redraw for-group)))
|
2010-08-31 09:42:21 +02:00
|
|
|
|
|
|
|
(defun magit-key-mode-redraw (for-group)
|
2010-08-31 19:38:44 +02:00
|
|
|
"(re)draw the magit key buffer."
|
2010-08-31 09:42:21 +02:00
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(erase-buffer)
|
|
|
|
(make-local-variable 'font-lock-defaults)
|
|
|
|
(use-local-map
|
|
|
|
(or (cdr (assoc for-group magit-key-mode-key-maps))
|
|
|
|
(magit-key-mode-build-keymap for-group)))
|
|
|
|
(magit-key-mode-draw for-group)
|
2010-08-31 19:38:08 +02:00
|
|
|
(setq mode-name "magit-key-mode" major-mode 'magit-key-mode))
|
2010-08-31 22:39:52 +02:00
|
|
|
(setq buffer-read-only t)
|
|
|
|
(fit-window-to-buffer))
|
2010-08-30 22:23:59 +02:00
|
|
|
|
2010-09-01 20:32:10 +02:00
|
|
|
(defun magit-key-mode-draw-header (header)
|
2010-09-01 22:35:09 +02:00
|
|
|
"Draw a header with the correct face."
|
2010-09-01 20:32:10 +02:00
|
|
|
(insert (propertize header 'face 'font-lock-keyword-face)))
|
|
|
|
|
2010-09-01 20:37:08 +02:00
|
|
|
(defun magit-key-mode-draw-args (args)
|
2010-09-01 22:35:09 +02:00
|
|
|
"Draw the args part of the menu."
|
2010-09-01 20:37:08 +02:00
|
|
|
(when args
|
|
|
|
(magit-key-mode-draw-header "Args\n")
|
|
|
|
(dolist (argument args)
|
|
|
|
(insert
|
|
|
|
(format " %s: (%s) %s %s\n"
|
2010-09-01 20:38:39 +02:00
|
|
|
(propertize
|
2010-09-01 20:37:08 +02:00
|
|
|
(car argument)
|
2010-09-01 20:38:39 +02:00
|
|
|
'face 'font-lock-builtin-face)
|
2010-09-01 20:37:08 +02:00
|
|
|
(nth 1 argument)
|
|
|
|
(nth 2 argument)
|
|
|
|
(propertize
|
|
|
|
(gethash (nth 2 argument) magit-key-mode-current-args "")
|
2010-09-01 20:38:39 +02:00
|
|
|
'face 'widget-field))))))
|
2010-09-01 20:37:08 +02:00
|
|
|
|
2010-09-01 20:39:58 +02:00
|
|
|
(defun magit-key-mode-draw-switches (switches)
|
2010-09-01 22:35:09 +02:00
|
|
|
"Draw the switches part of the menu."
|
2010-09-01 20:39:58 +02:00
|
|
|
(when switches
|
2010-09-01 22:14:46 +02:00
|
|
|
(let ((switch-strs (mapcar
|
|
|
|
(lambda (s)
|
|
|
|
(let ((option (nth 2 s)))
|
|
|
|
(format " %s: %s (%s)"
|
|
|
|
(propertize (car s)
|
|
|
|
'face 'font-lock-builtin-face)
|
|
|
|
(nth 1 s)
|
|
|
|
(if (member option magit-key-mode-current-options)
|
|
|
|
(propertize
|
|
|
|
option
|
|
|
|
'face 'font-lock-warning-face)
|
|
|
|
option))))
|
|
|
|
switches)))
|
|
|
|
(magit-key-mode-draw-header "Switches\n")
|
|
|
|
(magit-key-mode-draw-in-cols switch-strs))))
|
|
|
|
|
2010-09-01 20:27:49 +02:00
|
|
|
(defun magit-key-mode-draw-actions (actions)
|
2010-09-01 22:35:09 +02:00
|
|
|
"Draw the actions part of the menu."
|
2010-09-01 20:27:49 +02:00
|
|
|
(when actions
|
2010-09-01 22:14:46 +02:00
|
|
|
(let ((action-strs (mapcar
|
|
|
|
(lambda (a)
|
|
|
|
(format
|
|
|
|
" %s: %s"
|
|
|
|
(propertize (car a)
|
|
|
|
'face 'font-lock-builtin-face)
|
|
|
|
(nth 1 a)))
|
|
|
|
actions)))
|
2010-09-01 20:32:10 +02:00
|
|
|
(magit-key-mode-draw-header "Actions\n")
|
2010-09-01 22:14:46 +02:00
|
|
|
(magit-key-mode-draw-in-cols action-strs))))
|
|
|
|
|
2010-09-01 22:33:57 +02:00
|
|
|
(defun magit-key-mode-draw-in-cols (strings)
|
|
|
|
"Given a list of strings, print in columns (using `insert')."
|
2010-09-02 00:43:57 +02:00
|
|
|
(let ((longest-act (apply 'max (mapcar 'length strings))))
|
2010-09-01 22:33:57 +02:00
|
|
|
(while strings
|
|
|
|
(let ((str (car strings)))
|
2010-09-01 23:13:08 +02:00
|
|
|
(let ((padding (make-string (- (+ longest-act 3) (length str)) ? )))
|
2010-09-01 22:33:57 +02:00
|
|
|
(insert str)
|
2010-09-02 00:43:57 +02:00
|
|
|
(if (and (> (+ (current-column) longest-act) (window-width))
|
2010-09-01 22:33:57 +02:00
|
|
|
(cdr strings))
|
|
|
|
(insert "\n")
|
|
|
|
(insert padding))))
|
|
|
|
(setq strings (cdr strings))))
|
|
|
|
(insert "\n"))
|
2010-09-01 20:27:49 +02:00
|
|
|
|
2010-08-31 00:28:52 +02:00
|
|
|
(defun magit-key-mode-draw (for-group)
|
2010-08-31 00:45:51 +02:00
|
|
|
"Function used to draw actions, switches and parameters."
|
2010-08-31 00:28:52 +02:00
|
|
|
(let* ((options (magit-key-mode-options-for-group for-group))
|
2010-08-31 09:42:21 +02:00
|
|
|
(switches (cdr (assoc 'switches options)))
|
2010-08-31 19:53:37 +02:00
|
|
|
(arguments (cdr (assoc 'arguments options)))
|
2010-08-31 00:28:52 +02:00
|
|
|
(actions (cdr (assoc 'actions options))))
|
2010-09-01 20:27:49 +02:00
|
|
|
(magit-key-mode-draw-actions actions)
|
2010-09-01 20:39:58 +02:00
|
|
|
(magit-key-mode-draw-switches switches)
|
2010-09-01 20:37:08 +02:00
|
|
|
(magit-key-mode-draw-args arguments)))
|
2010-08-31 00:28:52 +02:00
|
|
|
|
2010-08-31 09:42:21 +02:00
|
|
|
(provide 'magit-key-mode)
|