emacs: Add hierarchy of customization groups.

* emacs/guix-buffer.el (guix-define-groups, guix-define-entry-type)
  (guix-define-buffer-type): New macros.
  (guix-buffer-define-interface): Add parent groups for the generated
  custom groups.
* emacs/guix-info.el: Use 'guix-define-buffer-type' to generate custom
  groups.
* emacs/guix-list.el: Likewise.
* emacs/guix-ui.el: Use 'guix-define-groups' to generate custom groups.
  (guix-ui-define-entry-type): New macro.
* emacs/guix-ui-package.el: Use it.
* emacs/guix-ui-generation.el: Use it.
This commit is contained in:
Alex Kost 2015-12-18 11:19:12 +03:00
parent dc690c445e
commit 8ed2c92eb1
6 changed files with 83 additions and 33 deletions

View file

@ -331,7 +331,58 @@ This function does not update the buffer data, use
(guix-buffer-redisplay)))
;;; Interface definer
;;; Interface definers
(defmacro guix-define-groups (type &rest args)
"Define `guix-TYPE' and `guix-TYPE-faces' custom groups.
Remaining arguments (ARGS) should have a form [KEYWORD VALUE] ...
Optional keywords:
- `:parent-group' - name of a parent custom group.
- `:parent-faces-group' - name of a parent custom faces group.
- `:group-doc' - docstring of a `guix-TYPE' group.
- `:faces-group-doc' - docstring of a `guix-TYPE-faces' group."
(declare (indent 1))
(let* ((type-str (symbol-name type))
(prefix (concat "guix-" type-str))
(group (intern prefix))
(faces-group (intern (concat prefix "-faces"))))
(guix-keyword-args-let args
((parent-group :parent-group 'guix)
(parent-faces-group :parent-faces-group 'guix-faces)
(group-doc :group-doc
(format "Settings for '%s' buffers."
type-str))
(faces-group-doc :faces-group-doc
(format "Faces for '%s' buffers."
type-str)))
`(progn
(defgroup ,group nil
,group-doc
:group ',parent-group)
(defgroup ,faces-group nil
,faces-group-doc
:group ',group
:group ',parent-faces-group)))))
(defmacro guix-define-entry-type (entry-type &rest args)
"Define general code for ENTRY-TYPE.
See `guix-define-groups'."
(declare (indent 1))
`(guix-define-groups ,entry-type
,@args))
(defmacro guix-define-buffer-type (buffer-type &rest args)
"Define general code for BUFFER-TYPE.
See `guix-define-groups'."
(declare (indent 1))
`(guix-define-groups ,buffer-type
,@args))
(defmacro guix-buffer-define-interface (buffer-type entry-type &rest args)
"Define BUFFER-TYPE interface for displaying ENTRY-TYPE entries.
@ -408,14 +459,16 @@ Optional keywords:
(reduced? :reduced?))
`(progn
(defgroup ,group nil
,(format "Display '%s' entries in '%s' buffer."
,(format "Displaying '%s' entries in '%s' buffer."
entry-type-str buffer-type-str)
:prefix ,(concat prefix "-")
:group ',(intern (concat "guix-" entry-type-str))
:group ',(intern (concat "guix-" buffer-type-str)))
(defgroup ,faces-group nil
,(format "Faces for displaying '%s' entries in '%s' buffer."
entry-type-str buffer-type-str)
:group ',group
:group ',(intern (concat "guix-" entry-type-str "-faces"))
:group ',(intern (concat "guix-" buffer-type-str "-faces")))
(defcustom ,titles-var ,titles-val
@ -555,7 +608,10 @@ Major mode for displaying '%s' entries in '%s' buffer.
(eval-when-compile
`((,(rx "(" (group (or "guix-buffer-with-item"
"guix-buffer-with-current-item"
"guix-buffer-define-interface"))
"guix-buffer-define-interface"
"guix-define-groups"
"guix-define-entry-type"
"guix-define-buffer-type"))
symbol-end)
. 1))))

View file

@ -29,15 +29,7 @@
(require 'guix-entry)
(require 'guix-utils)
(defgroup guix-info nil
"General settings for info buffers."
:prefix "guix-info-"
:group 'guix)
(defgroup guix-info-faces nil
"Faces for info buffers."
:group 'guix-info
:group 'guix-faces)
(guix-define-buffer-type info)
(defface guix-info-heading
'((((type tty pc) (class color)) :weight bold)

View file

@ -31,15 +31,7 @@
(require 'guix-entry)
(require 'guix-utils)
(defgroup guix-list nil
"General settings for list buffers."
:prefix "guix-list-"
:group 'guix)
(defgroup guix-list-faces nil
"Faces for list buffers."
:group 'guix-list
:group 'guix-faces)
(guix-define-buffer-type list)
(defface guix-list-file-path
'((t :inherit guix-info-file-path))

View file

@ -36,9 +36,7 @@
(require 'guix-entry)
(require 'guix-utils)
(defgroup guix-generation nil
"Interface for displaying generations."
:group 'guix-ui)
(guix-ui-define-entry-type generation)
(defun guix-generation-get-display (profile search-type &rest search-values)
"Search for generations and show results.

View file

@ -35,9 +35,8 @@
(require 'guix-entry)
(require 'guix-utils)
(defgroup guix-package nil
"Interface for displaying packages and outputs."
:group 'guix-ui)
(guix-ui-define-entry-type package)
(guix-ui-define-entry-type output)
(defcustom guix-package-list-type 'output
"Define how to display packages in 'list' buffer.

View file

@ -31,11 +31,11 @@
(require 'guix-utils)
(require 'guix-messages)
(defgroup guix-ui nil
"Settings for Guix package management.
(guix-define-groups ui
:group-doc "\
Settings for 'ui' (Guix package management) buffers.
This group includes settings for displaying packages, outputs and
generations in 'list' and 'info' buffers."
:group 'guix)
generations in 'list' and 'info' buffers.")
(defvar guix-ui-map
(let ((map (make-sparse-keymap)))
@ -175,6 +175,18 @@ See `guix-ui-update-after-operation' for details."
;;; Interface definers
(defmacro guix-ui-define-entry-type (entry-type &rest args)
"Define general code for ENTRY-TYPE.
Remaining arguments (ARGS) should have a form [KEYWORD VALUE] ...
The rest keyword arguments are passed to
`guix-define-entry-type' macro."
(declare (indent 1))
`(guix-define-entry-type ,entry-type
:parent-group guix-ui
:parent-faces-group guix-ui-faces
,@args))
(defmacro guix-ui-define-interface (buffer-type entry-type &rest args)
"Define BUFFER-TYPE interface for displaying ENTRY-TYPE entries.
Remaining arguments (ARGS) should have a form [KEYWORD VALUE] ...
@ -300,7 +312,8 @@ The rest keyword arguments are passed to
(defvar guix-ui-font-lock-keywords
(eval-when-compile
`((,(rx "(" (group (or "guix-ui-define-interface"
`((,(rx "(" (group (or "guix-ui-define-entry-type"
"guix-ui-define-interface"
"guix-ui-info-define-interface"
"guix-ui-list-define-interface"))
symbol-end)