Subject: bug#27134: 25.2; Add imenu support to package-menu-mode

From: Damien Cassou <[email-masked]>
Date: Mon, 29 May 2017 20:39:36 +0200

This commit adds Imenu support to package-menu-mode to rapidly go 
to any package through the standard Imenu interface. 

-- 
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
>From c86ded55ec0e97cd464a47299ec8130b8a04f038 Mon Sep 17 00:00:00 2001
From: Damien Cassou <[email-masked]>
Date: Mon, 29 May 2017 20:36:02 +0200
Subject: [PATCH] Add imenu support to package-menu-mode

* lisp/emacs-list/package.el (package--imenu-prev-index-position-function
  package--imenu-extract-index-name-function): Imenu functions in
  package-menu-mode.
---
 lisp/emacs-lisp/package.el | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index cb8e2d6..40595ff 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2551,7 +2551,11 @@ (define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
   (setq tabulated-list-padding 2)
   (setq tabulated-list-sort-key (cons "Status" nil))
   (add-hook 'tabulated-list-revert-hook 'package-menu--refresh nil t)
-  (tabulated-list-init-header))
+  (tabulated-list-init-header)
+  (setf imenu-prev-index-position-function
+        #'package--imenu-prev-index-position-function)
+  (setf imenu-extract-index-name-function
+        #'package--imenu-extract-index-name-function))
 
 (defmacro package--push (pkg-desc status listname)
   "Convenience macro for `package-menu--generate'.
@@ -3461,6 +3465,24 @@ (defun package-list-packages-no-fetch ()
   (interactive)
   (list-packages t))
 
+(defun package--imenu-prev-index-position-function ()
+  "Move point to previous line in package-menu buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+  (unless (bobp)
+    (forward-line -1)))
+
+(defun package--imenu-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."
+  (let ((package-desc (tabulated-list-get-id)))
+    (format "%s (%s): %s"
+            (package-desc-name package-desc)
+            (package-version-join (package-desc-version package-desc))
+            (package-desc-summary package-desc))))
+
 (provide 'package)
 
 ;;; package.el ends here
-- 
2.9.4