[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
12/38: emacs: list: Generalize 'sort-key' code.
From: |
Alex Kost |
Subject: |
12/38: emacs: list: Generalize 'sort-key' code. |
Date: |
Sat, 02 Jan 2016 14:27:19 +0000 |
alezost pushed a commit to branch master
in repository guix.
commit 649df66705cdd6c842af22f1ed4ef6cfeec79874
Author: Alex Kost <address@hidden>
Date: Thu Nov 19 16:19:47 2015 +0300
emacs: list: Generalize 'sort-key' code.
* emacs/guix-list.el (guix-list-sort-key): New procedure.
(guix-list-tabulated-sort-key): Use it.
(guix-list-define-entry-type): Generate
'guix-ENTRY-TYPE-list-sort-key' variables.
---
emacs/guix-list.el | 57 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/emacs/guix-list.el b/emacs/guix-list.el
index c4c85a8..aab3ef8 100644
--- a/emacs/guix-list.el
+++ b/emacs/guix-list.el
@@ -136,6 +136,10 @@ This alist is filled by `guix-list-define-entry-type'
macro.")
"Return a list of ENTRY-TYPE parameters that should be displayed."
(mapcar #'car (guix-list-format entry-type)))
+(defun guix-list-sort-key (entry-type)
+ "Return sort key for ENTRY-TYPE."
+ (guix-list-value entry-type 'sort-key))
+
(defun guix-list-additional-marks (entry-type)
"Return alist of additional marks for ENTRY-TYPE."
(guix-list-value entry-type 'marks))
@@ -182,12 +186,12 @@ See `guix-list-define-numerical-sorter' for details."
(guix-list-define-numerical-sorters 9)
-(defun guix-list-tabulated-sort-key (entry-type param &optional invert)
- "Return suitable sort key for `tabulated-list-sort-key'.
-Define column title by ENTRY-TYPE and PARAM. If INVERT is
-non-nil, invert the sort."
- (when (memq param (guix-list-displayed-params entry-type))
- (cons (guix-list-param-title entry-type param) invert)))
+(defun guix-list-tabulated-sort-key (entry-type)
+ "Return ENTRY-TYPE sort key for `tabulated-list-sort-key'."
+ (let ((sort-key (guix-list-sort-key entry-type)))
+ (and sort-key
+ (cons (guix-list-param-title entry-type (car sort-key))
+ (cdr sort-key)))))
(defun guix-list-tabulated-vector (entry-type fun)
"Call FUN on each column specification for ENTRY-TYPE.
@@ -450,9 +454,8 @@ Same as `tabulated-list-sort', but also restore marks after
sorting."
Remaining argument (ARGS) should have a form [KEYWORD VALUE] ... The
following keywords are available:
- - `:sort-key' - default sort key for the tabulated list buffer.
-
- - `:invert-sort' - if non-nil, invert initial sort.
+ - `:sort-key' - default value of the generated
+ `guix-ENTRY-TYPE-list-sort-key' variable.
- `:describe-function' - default value of the generated
`guix-ENTRY-TYPE-describe-function' variable.
@@ -468,14 +471,28 @@ following keywords are available:
(describe-var (intern (concat prefix "-describe-function")))
(describe-count-var (intern (concat prefix
"-describe-warning-count")))
+ (sort-key-var (intern (concat prefix "-sort-key")))
(marks-var (intern (concat prefix "-marks"))))
(guix-keyword-args-let args
((describe-val :describe-function)
(describe-count-val :describe-count 10)
- (sort-key :sort-key)
- (invert-sort :invert-sort)
+ (sort-key-val :sort-key)
(marks-val :marks))
`(progn
+ (defcustom ,sort-key-var ,sort-key-val
+ ,(format "\
+Default sort key for 'list' buffer with '%s' entries.
+Should be nil (no sort) or have a form:
+
+ (PARAM . FLIP)
+
+PARAM is the name of '%s' entry parameter. For the meaning of
+FLIP, see `tabulated-list-sort-key'."
+ entry-type-str entry-type-str)
+ :type '(choice (const :tag "No sort" nil)
+ (cons symbol boolean))
+ :group ',group)
+
(defvar ,marks-var ,marks-val
,(format "\
Alist of additional marks for 'list' buffer with '%s' entries.
@@ -498,18 +515,17 @@ See also `guix-list-describe'."
(defun ,init-fun ()
,(concat "Initial settings for `" mode-str "'.")
- ,(when sort-key
- `(setq tabulated-list-sort-key
- (guix-list-tabulated-sort-key
- ',entry-type ',sort-key ,invert-sort)))
- (setq tabulated-list-format
- (guix-list-tabulated-format ',entry-type))
+ (setq tabulated-list-sort-key (guix-list-tabulated-sort-key
+ ',entry-type)
+ tabulated-list-format (guix-list-tabulated-format
+ ',entry-type))
(setq-local guix-list-marks (guix-list-marks ',entry-type))
(tabulated-list-init-header))
(guix-alist-put!
'((describe . ,describe-var)
(describe-count . ,describe-count-var)
+ (sort-key . ,sort-key-var)
(marks . ,marks-var))
'guix-list-data ',entry-type)))))
@@ -527,7 +543,7 @@ See also `guix-list-describe'."
(guix-list-define-entry-type package
:describe-function 'guix-list-describe-ids
- :sort-key name
+ :sort-key '(name)
:marks '((install . ?I)
(upgrade . ?U)
(delete . ?D)))
@@ -711,7 +727,7 @@ The specification is suitable for
`guix-process-package-actions'."
(guix-list-define-entry-type output
:describe-function 'guix-output-list-describe
- :sort-key name
+ :sort-key '(name)
:marks '((install . ?I)
(upgrade . ?U)
(delete . ?D)))
@@ -797,8 +813,7 @@ See `guix-package-info-type'."
(guix-list-define-entry-type generation
:describe-function 'guix-list-describe-ids
- :sort-key number
- :invert-sort t
+ :sort-key '(number . t)
:marks '((delete . ?D)))
(let ((map guix-generation-list-mode-map))
- branch master updated (b989390 -> 1ae858f), Alex Kost, 2016/01/02
- 02/38: emacs: Add 'guix-with-indent'., Alex Kost, 2016/01/02
- 05/38: emacs: list: Generate numerical sort predicates., Alex Kost, 2016/01/02
- 01/38: emacs: Use "cl-list*" instead of "apply #'list"., Alex Kost, 2016/01/02
- 04/38: emacs: Simplify defining parameter titles., Alex Kost, 2016/01/02
- 09/38: emacs: Add 'guix-alist-put'., Alex Kost, 2016/01/02
- 07/38: emacs: list: Configure format in one place., Alex Kost, 2016/01/02
- 12/38: emacs: list: Generalize 'sort-key' code.,
Alex Kost <=
- 15/38: emacs: list: Factorize "edit package" commands., Alex Kost, 2016/01/02
- 08/38: emacs: Add 'guix-keyword-args-let'., Alex Kost, 2016/01/02
- 10/38: emacs: list: Generalize 'marks' code., Alex Kost, 2016/01/02
- 13/38: emacs: list: Add 'guix-list-mode-initialize'., Alex Kost, 2016/01/02
- 03/38: emacs: Add API for 'guix-entry'., Alex Kost, 2016/01/02
- 06/38: emacs: Rename internal procedures., Alex Kost, 2016/01/02
- 11/38: emacs: list: Generalize 'describe' code., Alex Kost, 2016/01/02
- 14/38: emacs: list: Split 'guix-list-format' variable., Alex Kost, 2016/01/02
- 20/38: emacs: Add wrappers for 'history-size' and 'revert-confirm'., Alex Kost, 2016/01/02
- 23/38: emacs: Generalize buffer reverting., Alex Kost, 2016/01/02