all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Sorting in package.el
@ 2011-07-31 13:26 Deniz Dogan
  2011-08-01 15:56 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Deniz Dogan @ 2011-07-31 13:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

I found it confusing to sort by "Status" in list-packages so I figured 
why not make this modifiable?

Attached is a rather simple patch.  Maybe it should go into 
package-x.el, if at all.

What do you think?

Deniz

[-- Attachment #2: package-sort.diff --]
[-- Type: text/plain, Size: 1961 bytes --]

=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el	2011-04-24 20:32:23 +0000
+++ lisp/emacs-lisp/package.el	2011-07-31 13:24:22 +0000
@@ -1266,6 +1266,7 @@
     (define-key map "r" 'package-menu-refresh)
     (define-key map "~" 'package-menu-mark-obsolete-for-deletion)
     (define-key map "x" 'package-menu-execute)
+    (define-key map "s" 'package-menu-toggle-sorting)
     (define-key map "h" 'package-menu-quick-help)
     (define-key map "?" 'package-menu-describe-package)
     (define-key map [menu-bar package-menu] (cons "Package" menu-map))
@@ -1326,7 +1327,7 @@
 			       ("Status"  10 package-menu--status-predicate)
 			       ("Description" 0 nil)])
   (setq tabulated-list-padding 2)
-  (setq tabulated-list-sort-key (cons "Status" nil))
+  (setq tabulated-list-sort-key package-menu-default-sort-key)
   (tabulated-list-init-header))
 
 (defmacro package--push (package desc status listname)
@@ -1537,6 +1538,28 @@
 	(package-menu--generate t t)
       (message "No operations specified."))))
 
+(defconst package-menu-sort-keys '(("Status") ("Package"))
+  "List of possible keys to sort by.")
+
+(defcustom package-menu-default-sort-key '("Status")
+  "Default key to sort by."
+  :type `(choice (const :tag "Status" ("Status"))
+                 (const :tag "Package" ("Package"))))
+
+(defun package-menu-toggle-sorting ()
+  "Toggle between the different sorting methods.
+See the variable `package-menu-sort-keys'."
+  (interactive)
+  (let* ((curr-pos
+          (position tabulated-list-sort-key
+                    package-menu-sort-keys :test 'equal))
+         (next-pos
+          (mod (1+ curr-pos) (length package-menu-sort-keys)))
+         (next-key
+          (nth next-pos package-menu-sort-keys)))
+    (setq tabulated-list-sort-key next-key)
+    (revert-buffer)))
+
 (defun package-menu--version-predicate (A B)
   (let ((vA (or (aref (cadr A) 1)  '(0)))
 	(vB (or (aref (cadr B) 1) '(0))))


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Sorting in package.el
  2011-07-31 13:26 Sorting in package.el Deniz Dogan
@ 2011-08-01 15:56 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2011-08-01 15:56 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

Deniz Dogan <deniz@dogan.se> writes:

> I found it confusing to sort by "Status" in list-packages so I figured
> why not make this modifiable?
>
> Attached is a rather simple patch.  Maybe it should go into
> package-x.el, if at all.
>
> What do you think?

Good idea, but I think it should be a patch against tabulated-list-mode,
not something specific to package.el.

The variable `package-menu-sort-keys' doesn't look useful; just have the
command loop through all sortable keys in tabulated-list-sort-key.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-01 15:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-31 13:26 Sorting in package.el Deniz Dogan
2011-08-01 15:56 ` Chong Yidong

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.