aboutsummaryrefslogtreecommitdiff
path: root/emacs/guix-base.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-base.el
parent2c7ed388cf403120c17b5e222ac5dda093f5ad94 (diff)
downloadpatches-7735c503b5b8dfe7d8963207f4f2cf0b7dfd3894.tar
patches-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-base.el')
-rw-r--r--emacs/guix-base.el122
1 files changed, 56 insertions, 66 deletions
diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index f55e1c67e0..67b83cfbe3 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -23,7 +23,7 @@
;; package.
;; List and info buffers have many common patterns that are defined
-;; using `guix-define-buffer-type' macro from this file.
+;; using `guix-buffer-define-interface' macro from this file.
;;; Code:
@@ -337,103 +337,93 @@ VAL is a value of this parameter.")
(concat (symbol-name entry-type) "-"))
(symbol-name buffer-type) "-" postfix)))
-(defmacro guix-define-buffer-type (buf-type entry-type &rest args)
- "Define common for BUF-TYPE buffers for displaying ENTRY-TYPE entries.
-
-In the text below TYPE means ENTRY-TYPE-BUF-TYPE.
-
-This macro defines `guix-TYPE-mode', a custom group and several
-user variables.
+(defmacro guix-buffer-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.
The following stuff should be defined outside this macro:
- - `guix-BUF-TYPE-mode' - parent mode for the defined mode.
+ - `guix-BUFFER-TYPE-mode' - parent mode of the generated mode.
- `guix-TYPE-mode-initialize' (optional) - function for
additional mode settings; it is called without arguments.
-Remaining argument (ARGS) should have a form [KEYWORD VALUE] ... The
-following keywords are available:
+Optional keywords:
- - `:buffer-name' - default value for the defined
+ - `:buffer-name' - default value of the generated
`guix-TYPE-buffer-name' variable.
- - `:required' - default value for the defined
- `guix-TYPE-required-params' variable.
-
- - `:history-size' - default value for the defined
+ - `:history-size' - default value of the generated
`guix-TYPE-history-size' variable.
- - `:revert' - default value for the defined
- `guix-TYPE-revert-no-confirm' variable."
- (let* ((entry-type-str (symbol-name entry-type))
- (buf-type-str (symbol-name buf-type))
- (Entry-type-str (capitalize entry-type-str))
- (Buf-type-str (capitalize buf-type-str))
- (entry-str (concat entry-type-str " entries"))
- (buf-str (concat buf-type-str " buffer"))
- (prefix (concat "guix-" entry-type-str "-" buf-type-str))
- (group (intern prefix))
- (faces-group (intern (concat prefix "-faces")))
- (mode-map-str (concat prefix "-mode-map"))
- (parent-mode (intern (concat "guix-" buf-type-str "-mode")))
- (mode (intern (concat prefix "-mode")))
- (mode-init-fun (intern (concat prefix "-mode-initialize")))
- (buf-name-var (intern (concat prefix "-buffer-name")))
- (revert-var (intern (concat prefix "-revert-no-confirm")))
- (history-var (intern (concat prefix "-history-size")))
- (params-var (intern (concat prefix "-required-params"))))
+ - `:revert-confirm?' - default value of the generated
+ `guix-TYPE-revert-confirm' variable."
+ (declare (indent 2))
+ (let* ((entry-type-str (symbol-name entry-type))
+ (buffer-type-str (symbol-name buffer-type))
+ (Entry-type-str (capitalize entry-type-str))
+ (Buffer-type-str (capitalize buffer-type-str))
+ (entry-str (concat entry-type-str " entries"))
+ (buffer-str (concat buffer-type-str " buffer"))
+ (prefix (concat "guix-" entry-type-str "-"
+ buffer-type-str))
+ (group (intern prefix))
+ (faces-group (intern (concat prefix "-faces")))
+ (mode-map-str (concat prefix "-mode-map"))
+ (parent-mode (intern (concat "guix-" buffer-type-str "-mode")))
+ (mode (intern (concat prefix "-mode")))
+ (mode-init-fun (intern (concat prefix "-mode-initialize")))
+ (buffer-name-var (intern (concat prefix "-buffer-name")))
+ (history-size-var (intern (concat prefix "-history-size")))
+ (revert-confirm-var (intern (concat prefix "-revert-confirm"))))
(guix-keyword-args-let args
- ((params-val :required '(id))
- (history-val :history-size 20)
- (revert-val :revert)
- (buf-name-val :buffer-name
- (format "*Guix %s %s*" Entry-type-str Buf-type-str)))
+ ((buffer-name-val :buffer-name
+ (format "*Guix %s %s*"
+ Entry-type-str Buffer-type-str))
+ (history-size-val :history-size 20)
+ (revert-confirm-val :revert-confirm? t))
`(progn
(defgroup ,group nil
- ,(concat Buf-type-str " buffer with " entry-str ".")
+ ,(format "Display '%s' entries in '%s' buffer."
+ entry-type-str buffer-type-str)
:prefix ,(concat prefix "-")
- :group ',(intern (concat "guix-" buf-type-str)))
+ :group ',(intern (concat "guix-" buffer-type-str)))
(defgroup ,faces-group nil
- ,(concat "Faces for " buf-type-str " buffer with " entry-str ".")
- :group ',(intern (concat "guix-" buf-type-str "-faces")))
-
- (defcustom ,buf-name-var ,buf-name-val
- ,(concat "Default name of the " buf-str " for displaying " entry-str ".")
+ ,(format "Faces for displaying '%s' entries in '%s' buffer."
+ entry-type-str buffer-type-str)
+ :group ',(intern (concat "guix-" buffer-type-str "-faces")))
+
+ (defcustom ,buffer-name-var ,buffer-name-val
+ ,(format "\
+Default name of '%s' buffer for displaying '%s' entries."
+ buffer-type-str entry-type-str)
:type 'string
:group ',group)
- (defcustom ,history-var ,history-val
- ,(concat "Maximum number of items saved in the history of the " buf-str ".\n"
- "If 0, the history is disabled.")
+ (defcustom ,history-size-var ,history-size-val
+ ,(format "\
+Maximum number of items saved in history of `%S' buffer.
+If 0, the history is disabled."
+ buffer-name-var)
:type 'integer
:group ',group)
- (defcustom ,revert-var ,revert-val
- ,(concat "If non-nil, do not ask to confirm for reverting the " buf-str ".")
+ (defcustom ,revert-confirm-var ,revert-confirm-val
+ ,(format "\
+If non-nil, ask to confirm for reverting `%S' buffer."
+ buffer-name-var)
:type 'boolean
:group ',group)
- (defvar ,params-var ',params-val
- ,(concat "List of required " entry-type-str " parameters.\n\n"
- "Displayed parameters and parameters from this list are received\n"
- "for each " entry-type-str ".\n\n"
- "May be a special value `all', in which case all supported\n"
- "parameters are received (this may be very slow for a big number\n"
- "of entries).\n\n"
- "Do not remove `id' from this list as it is required for\n"
- "identifying an entry."))
-
- (define-derived-mode ,mode ,parent-mode ,(concat "Guix-" Buf-type-str)
+ (define-derived-mode ,mode ,parent-mode ,(concat "Guix-" Buffer-type-str)
,(concat "Major mode for displaying information about " entry-str ".\n\n"
"\\{" mode-map-str "}")
(setq-local revert-buffer-function 'guix-revert-buffer)
- (setq-local guix-history-size ,history-var)
+ (setq-local guix-history-size ,history-size-var)
(and (fboundp ',mode-init-fun) (,mode-init-fun)))))))
-(put 'guix-define-buffer-type 'lisp-indent-function 'defun)
-
;;; Getting and displaying info about packages and generations