aboutsummaryrefslogtreecommitdiff
path: root/emacs/guix-list.el
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2015-11-20 12:38:31 +0300
committerAlex Kost <alezost@gmail.com>2016-01-02 17:25:35 +0300
commit7735c503b5b8dfe7d8963207f4f2cf0b7dfd3894 (patch)
treeabff13562165160b51938a84a7f93ab32c39f329 /emacs/guix-list.el
parent2c7ed388cf403120c17b5e222ac5dda093f5ad94 (diff)
downloadgnu-guix-7735c503b5b8dfe7d8963207f4f2cf0b7dfd3894.tar
gnu-guix-7735c503b5b8dfe7d8963207f4f2cf0b7dfd3894.tar.gz
emacs: Factorize macros for defining interfaces.
Make a root 'guix-buffer-define-interface' macro. It should generate a common code for any type of interface. Inherit 'guix-info-define-interface' and 'guix-list-define-interface' from it. They should provide a general 'info'/'list' interface for any data. Finally, make 'guix-ui-define-interface' for the common code for interfaces to Guix packages and generations, and inherit 'guix-ui-info-define-interface' and 'guix-ui-list-define-interface' from it. * emacs/guix-base.el (guix-define-buffer-type): Rename to... (guix-buffer-define-interface): ... this. Rename internal variables ('buf-' -> 'buffer-'). Move ':required' keyword to 'guix-ui-define-interface'. * emacs/guix-info.el (guix-info-define-interface): New macro. (guix-info-font-lock-keywords): New variable. * emacs/guix-list.el (guix-list-define-entry-type): Rename to... (guix-list-define-interface): ... this. (guix-list-font-lock-keywords): New variable. (guix-list-describe-ids): Move and rename to... * emacs/guix-ui.el: New file. (guix-ui-list-describe): ... this. (guix-ui-define-interface, guix-ui-info-define-interface) (guix-ui-list-define-interface): New macros. (guix-ui-font-lock-keywords): New variable. * emacs.am (ELFILES): Add "emacs/guix-ui.el"
Diffstat (limited to 'emacs/guix-list.el')
-rw-r--r--emacs/guix-list.el47
1 files changed, 24 insertions, 23 deletions
diff --git a/emacs/guix-list.el b/emacs/guix-list.el
index e1fc199639..8943e8f589 100644
--- a/emacs/guix-list.el
+++ b/emacs/guix-list.el
@@ -30,6 +30,7 @@
(require 'guix-base)
(require 'guix-entry)
(require 'guix-utils)
+(require 'guix-ui)
(defgroup guix-list nil
"General settings for list buffers."
@@ -73,17 +74,12 @@ With prefix argument, describe entries marked with any mark."
count)))
(guix-list-describe-entries entry-type ids))))
-(defun guix-list-describe-ids (ids)
- "Describe entries with IDS (list of identifiers)."
- (apply #'guix-get-show-entries
- guix-profile 'info guix-entry-type 'id ids))
-
;;; Wrappers for 'list' variables
(defvar guix-list-data nil
"Alist with 'list' data.
-This alist is filled by `guix-list-define-entry-type' macro.")
+This alist is filled by `guix-list-define-interface' macro.")
(defun guix-list-value (entry-type symbol)
"Return SYMBOL's value for ENTRY-TYPE from `guix-list-data'."
@@ -416,8 +412,8 @@ Same as `tabulated-list-sort', but also restore marks after sorting."
(setq-local guix-list-marks (guix-list-marks entry-type))
(tabulated-list-init-header))
-(defmacro guix-list-define-entry-type (entry-type &rest args)
- "Define common stuff for displaying ENTRY-TYPE entries in list buffers.
+(defmacro guix-list-define-interface (entry-type &rest args)
+ "Define 'list' interface for displaying ENTRY-TYPE entries.
Remaining arguments (ARGS) should have a form [KEYWORD VALUE] ...
Required keywords:
@@ -435,7 +431,10 @@ Optional keywords:
- `:marks' - default value of the generated
`guix-ENTRY-TYPE-list-marks' variable.
-"
+
+The rest keyword arguments are passed to
+`guix-buffer-define-interface' macro."
+ (declare (indent 1))
(let* ((entry-type-str (symbol-name entry-type))
(prefix (concat "guix-" entry-type-str "-list"))
(group (intern prefix))
@@ -518,17 +517,15 @@ See also `guix-list-describe'."
(format . ,format-var)
(sort-key . ,sort-key-var)
(marks . ,marks-var))
- 'guix-list-data ',entry-type)))))
+ 'guix-list-data ',entry-type)
-(put 'guix-list-define-entry-type 'lisp-indent-function 'defun)
+ (guix-buffer-define-interface list ,entry-type
+ ,@%foreign-args)))))
;;; Displaying packages
-(guix-define-buffer-type list package)
-
-(guix-list-define-entry-type package
- :describe-function 'guix-list-describe-ids
+(guix-ui-list-define-interface package
:format '((name guix-package-list-get-name 20 t)
(version nil 10 nil)
(outputs nil 13 t)
@@ -717,17 +714,15 @@ The specification is suitable for `guix-process-package-actions'."
;;; Displaying outputs
-(guix-define-buffer-type list output
+(guix-ui-list-define-interface output
:buffer-name "*Guix Package List*"
- :required (package-id))
-
-(guix-list-define-entry-type output
:describe-function 'guix-output-list-describe
:format '((name guix-package-list-get-name 20 t)
(version nil 10 nil)
(output nil 9 t)
(installed nil 12 t)
(synopsis guix-list-get-one-line 30 nil))
+ :required '(package-id)
:sort-key '(name)
:marks '((install . ?I)
(upgrade . ?U)
@@ -816,10 +811,7 @@ See `guix-package-info-type'."
;;; Displaying generations
-(guix-define-buffer-type list generation)
-
-(guix-list-define-entry-type generation
- :describe-function 'guix-list-describe-ids
+(guix-ui-list-define-interface generation
:format '((number nil 5 guix-list-sort-numerically-0 :right-align t)
(current guix-generation-list-get-current 10 t)
(time guix-list-get-time 20 t)
@@ -954,6 +946,15 @@ With ARG, mark all generations for deletion."
(user-error "No generations marked for deletion"))
(guix-delete-generations guix-profile marked (current-buffer))))
+
+(defvar guix-list-font-lock-keywords
+ (eval-when-compile
+ `((,(rx "(" (group "guix-list-define-interface")
+ symbol-end)
+ . 1))))
+
+(font-lock-add-keywords 'emacs-lisp-mode guix-list-font-lock-keywords)
+
(provide 'guix-list)
;;; guix-list.el ends here