diff options
author | Alex Kost <alezost@gmail.com> | 2015-11-20 12:38:31 +0300 |
---|---|---|
committer | Alex Kost <alezost@gmail.com> | 2016-01-02 17:25:35 +0300 |
commit | 7735c503b5b8dfe7d8963207f4f2cf0b7dfd3894 (patch) | |
tree | abff13562165160b51938a84a7f93ab32c39f329 /emacs/guix-ui.el | |
parent | 2c7ed388cf403120c17b5e222ac5dda093f5ad94 (diff) | |
download | gnu-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-ui.el')
-rw-r--r-- | emacs/guix-ui.el | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/emacs/guix-ui.el b/emacs/guix-ui.el new file mode 100644 index 0000000000..4f4688250b --- /dev/null +++ b/emacs/guix-ui.el @@ -0,0 +1,109 @@ +;;; guix-ui.el --- Common code for Guix package management interface -*- lexical-binding: t -*- + +;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com> + +;; This file is part of GNU Guix. + +;; GNU Guix is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Guix is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; This file provides some general code for 'list'/'info' interfaces for +;; packages and generations. + +;;; Code: + +(require 'cl-lib) +(require 'guix-utils) + +(defun guix-ui-list-describe (ids) + "Describe 'ui' entries with IDS (list of identifiers)." + (apply #'guix-get-show-entries + guix-profile 'info guix-entry-type 'id ids)) + + +;;; Interface definers + +(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] ... +In the following description TYPE means ENTRY-TYPE-BUFFER-TYPE. + +Optional keywords: + + - `:required' - default value of the generated + `guix-TYPE-required-params' variable. + +The rest keyword arguments are passed to +`guix-BUFFER-TYPE-define-interface' macro." + (declare (indent 2)) + (let* ((entry-type-str (symbol-name entry-type)) + (buffer-type-str (symbol-name buffer-type)) + (prefix (concat "guix-" entry-type-str "-" + buffer-type-str)) + (required-var (intern (concat prefix "-required-params"))) + (definer (intern (format "guix-%s-define-interface" + buffer-type-str)))) + (guix-keyword-args-let args + ((required-val :required ''(id))) + `(progn + (defvar ,required-var ,required-val + ,(format "\ +List of the required '%s' parameters for '%s' buffer. +These parameters are received along with the displayed parameters." + entry-type-str buffer-type-str)) + + (,definer ,entry-type + ,@%foreign-args))))) + +(defmacro guix-ui-info-define-interface (entry-type &rest args) + "Define 'info' interface for displaying ENTRY-TYPE entries. +See `guix-ui-define-interface'." + (declare (indent 1)) + `(guix-ui-define-interface info ,entry-type + ,@args)) + +(defmacro guix-ui-list-define-interface (entry-type &rest args) + "Define 'list' interface for displaying ENTRY-TYPE entries. +Remaining arguments (ARGS) should have a form [KEYWORD VALUE] ... + +Optional keywords: + + - `:describe-function' - default value of the generated + `guix-ENTRY-TYPE-list-describe-function' variable (if not + specified, use `guix-ui-list-describe'). + +The rest keyword arguments are passed to +`guix-ui-define-interface' macro." + (declare (indent 1)) + (guix-keyword-args-let args + ((describe-val :describe-function)) + `(guix-ui-define-interface list ,entry-type + :describe-function ,(or describe-val ''guix-ui-list-describe) + ,@args))) + + +(defvar guix-ui-font-lock-keywords + (eval-when-compile + `((,(rx "(" (group (or "guix-ui-define-interface" + "guix-ui-info-define-interface" + "guix-ui-list-define-interface")) + symbol-end) + . 1)))) + +(font-lock-add-keywords 'emacs-lisp-mode guix-ui-font-lock-keywords) + +(provide 'guix-ui) + +;;; guix-ui.el ends here |