Skip to content

Commit

Permalink
Add support for imenu in git-rebase [#3022]
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed May 29, 2017
1 parent 400e994 commit 94988f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lisp/Makefile
Expand Up @@ -47,7 +47,7 @@ magit-subtree.elc: magit.elc
magit-ediff.elc: magit.elc
magit-extras.elc: magit.elc
git-rebase.elc: magit.elc
magit-imenu.elc: magit.elc
magit-imenu.elc: magit.elc git-rebase.elc

## Build #############################################################

Expand Down
4 changes: 4 additions & 0 deletions lisp/git-rebase.el
Expand Up @@ -482,6 +482,10 @@ running 'man git-rebase' at the command line) for details."
(setq-local redisplay-unhighlight-region-function 'git-rebase-unhighlight-region)
(add-hook 'with-editor-pre-cancel-hook 'git-rebase-autostash-save nil t)
(add-hook 'with-editor-post-cancel-hook 'git-rebase-autostash-apply nil t)
(setq imenu-prev-index-position-function
#'magit-imenu--rebase-prev-index-position-function)
(setq imenu-extract-index-name-function
#'magit-imenu--rebase-extract-index-name-function)
(when (boundp 'save-place)
(setq save-place nil)))

Expand Down
23 changes: 23 additions & 0 deletions lisp/magit-imenu.el
Expand Up @@ -36,6 +36,7 @@
(require 'subr-x)

(require 'magit)
(require 'git-rebase)

(defun magit-imenu--index-function (entry-types menu-types)
"Return an alist of imenu entries in current buffer.
Expand Down Expand Up @@ -133,5 +134,27 @@ This function is used as a value for
'(file commit stash)
'(unpushed unstaged unpulled untracked staged stashes)))

;;;; Rebase mode

;;;###autoload
(defun magit-imenu--rebase-prev-index-position-function ()
"Move point to previous commit in git-rebase buffer.
This function is used as a value for
`imenu-prev-index-position-function'."
(catch 'found
(while (not (bobp))
(git-rebase-backward-line)
(when (git-rebase-line-p)
(throw 'found t)))))

;;;###autoload
(defun magit-imenu--rebase-extract-index-name-function ()
"Return imenu name for line at point.
This function is used as a value for
`imenu-extract-index-name-function'. Point should be at the
beginning of the line."
(buffer-substring-no-properties (line-beginning-position)
(line-end-position)))

(provide 'magit-imenu)
;;; magit-imenu.el ends here

0 comments on commit 94988f3

Please sign in to comment.