Hitting ret on args does same as using prefix key.

This commit is contained in:
Phil Jackson 2010-09-20 19:11:39 +01:00
parent d1070e67c7
commit 3ebcb08091

View file

@ -168,6 +168,14 @@ FOR-GROUP."
(man (or (cadr (assoc 'man-page opts)) (man (or (cadr (assoc 'man-page opts))
(error "No help associated with %s" seq)))))) (error "No help associated with %s" seq))))))
(defun magit-key-mode-exec-at-point ()
"Run action/args/option at point."
(interactive)
(let* ((key (or (get-text-property (point) 'key-group-executor)
(error "Nothing at point to do.")))
(def (lookup-key (current-local-map) key)))
(call-interactively def)))
(defun magit-key-mode-build-keymap (for-group) (defun magit-key-mode-build-keymap (for-group)
"Construct a normal looking keymap for the key mode to use and "Construct a normal looking keymap for the key mode to use and
put it in magit-key-mode-key-maps for fast lookup." put it in magit-key-mode-key-maps for fast lookup."
@ -176,10 +184,14 @@ put it in magit-key-mode-key-maps for fast lookup."
(switches (cdr (assoc 'switches options))) (switches (cdr (assoc 'switches options)))
(arguments (cdr (assoc 'arguments options)))) (arguments (cdr (assoc 'arguments options))))
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
;; ret dwim
(define-key map (kbd "RET") 'magit-key-mode-exec-at-point)
;; all maps should 'quit' with C-g ;; all maps should 'quit' with C-g
(define-key map (kbd "C-g") (lambda () (define-key map (kbd "C-g") (lambda ()
(interactive) (interactive)
(magit-key-mode-command nil))) (magit-key-mode-command nil)))
;; run help
(define-key map (kbd "?") `(lambda () (define-key map (kbd "?") `(lambda ()
(interactive) (interactive)
(magit-key-mode-help ',for-group))) (magit-key-mode-help ',for-group)))
@ -273,14 +285,17 @@ highlighed before the description."
(magit-key-mode-redraw for-group)) (magit-key-mode-redraw for-group))
(message "Bindings prefixing options action them. '?' for help")) (message "Bindings prefixing options action them. '?' for help"))
(defun magit-key-mode-get-key-map (for-group)
"Get or build the keymap for FOR-GROUP."
(or (cdr (assoc for-group magit-key-mode-key-maps))
(magit-key-mode-build-keymap for-group)))
(defun magit-key-mode-redraw (for-group) (defun magit-key-mode-redraw (for-group)
"(re)draw the magit key buffer." "(re)draw the magit key buffer."
(let ((buffer-read-only nil)) (let ((buffer-read-only nil))
(erase-buffer) (erase-buffer)
(make-local-variable 'font-lock-defaults) (make-local-variable 'font-lock-defaults)
(use-local-map (use-local-map (magit-key-mode-get-key-map for-group))
(or (cdr (assoc for-group magit-key-mode-key-maps))
(magit-key-mode-build-keymap for-group)))
(magit-key-mode-draw for-group) (magit-key-mode-draw for-group)
(delete-trailing-whitespace) (delete-trailing-whitespace)
(setq mode-name "magit-key-mode" major-mode 'magit-key-mode)) (setq mode-name "magit-key-mode" major-mode 'magit-key-mode))
@ -301,15 +316,19 @@ highlighed before the description."
(when args (when args
(let ((strs (mapcar (let ((strs (mapcar
(lambda (argument) (lambda (argument)
(format " %s: %s (%s) %s" (propertize
(propertize (format " %s: %s (%s) %s"
(car argument) (propertize
'face 'font-lock-builtin-face) (car argument)
(nth 1 argument) 'face 'font-lock-builtin-face)
(nth 2 argument) (nth 1 argument)
(propertize (nth 2 argument)
(gethash (nth 2 argument) magit-key-mode-current-args "") (propertize
'face 'widget-field))) (gethash (nth 2 argument)
magit-key-mode-current-args
"")
'face 'widget-field))
'key-group-executor (car argument)))
args))) args)))
(magit-key-mode-draw-header "Args\n") (magit-key-mode-draw-header "Args\n")
(magit-key-mode-draw-in-cols strs (not magit-key-mode-args-in-cols))))) (magit-key-mode-draw-in-cols strs (not magit-key-mode-args-in-cols)))))