Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect cursor location in magit-key-mode #514

Merged
merged 1 commit into from
Feb 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion magit-key-mode.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ FOR-GROUP."
(error "Nothing at point to do."))) (error "Nothing at point to do.")))
(def (lookup-key (current-local-map) key))) (def (lookup-key (current-local-map) key)))
(call-interactively def))) (call-interactively def)))

(defun magit-key-mode-build-exec-point-alist ()
(save-excursion
(goto-char (point-min))
(let* ((exec (get-text-property (point) 'key-group-executor))
(exec-alist (if exec `((,exec . ,(point))) nil)))
(do nil ((eobp) (nreverse exec-alist))
(when (not (eq exec (get-text-property (point) 'key-group-executor)))
(setq exec (get-text-property (point) 'key-group-executor))
(when exec (push (cons exec (point)) exec-alist)))
(forward-char)))))

(defun magit-key-mode-jump-to-next-exec () (defun magit-key-mode-jump-to-next-exec ()
"Jump to the next action/args/option point." "Jump to the next action/args/option point."
(interactive) (interactive)
Expand Down Expand Up @@ -396,6 +408,8 @@ highlighted before the description."
(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)
(current-exec (get-text-property (point) 'key-group-executor))
(new-exec-pos)
(old-point (point)) (old-point (point))
(is-first (zerop (buffer-size))) (is-first (zerop (buffer-size)))
(actions-p nil)) (actions-p nil))
Expand All @@ -405,10 +419,15 @@ highlighted before the description."
(setq actions-p (magit-key-mode-draw for-group)) (setq actions-p (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)
(when current-exec
(setq new-exec-pos (cdr (assoc current-exec (magit-key-mode-build-exec-point-alist)))))
(if (and is-first actions-p) (if (and is-first actions-p)
(progn (goto-char actions-p) (progn (goto-char actions-p)
(magit-key-mode-jump-to-next-exec)) (magit-key-mode-jump-to-next-exec))
(goto-char old-point))) (if new-exec-pos
(progn (goto-char new-exec-pos)
(skip-chars-forward " "))
(goto-char old-point))))
(setq buffer-read-only t) (setq buffer-read-only t)
(fit-window-to-buffer)) (fit-window-to-buffer))


Expand Down