From 6c40b7b703424f757ff2e1fbb7503a525f9acfd8 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 2 Dec 2015 15:24:07 +0300 Subject: emacs: Generalize buffer interface. Extract the code for defining buffer interface from "guix-base.el", generalize it and move to "guix-buffer.el". * emacs.am (ELFILES): Add "emacs/guix-buffer.el". * emacs/guix-base.el (guix-profile, guix-entries, guix-buffer-type) (guix-entry-type, guix-search-type, guix-search-vals, guix-set-vars) (guix-get-symbol, guix-show-entries, guix-get-show-entries) (guix-set-buffer, guix-history-call, guix-make-history-item) (guix-get-params-for-receiving): Remove. (guix-switch-to-buffer): Rename to 'guix-buffer-display' and move to "guix-buffer.el". (guix-get-entries): Rename to 'guix-ui-get-entries' and move to "guix-ui.el". (guix-buffer-data, guix-buffer-value, guix-buffer-param-title) (guix-buffer-name, guix-buffer-history-size) (guix-buffer-revert-confirm?, guix-buffer-map, guix-buffer-revert) (guix-buffer-after-redisplay-hook, guix-buffer-redisplay) (guix-buffer-redisplay-goto-button): Move to... * emacs/guix-buffer.el: ... here. New file. (guix-buffer-item): New variable. (guix-buffer-with-item, guix-buffer-with-current-item) (guix-buffer-define-current-item-accessor) (guix-buffer-define-current-item-accessors) (guix-buffer-define-current-args-accessor) (guix-buffer-define-current-args-accessors): New macros. (guix-buffer-get-entries, guix-buffer-mode-enable) (guix-buffer-mode-initialize, guix-buffer-insert-entries) (guix-buffer-show-entries-default, guix-buffer-show-entries) (guix-buffer-message, guix-buffer-history-item, guix-buffer-set) (guix-buffer-display-entries-current) (guix-buffer-get-display-entries-current) (guix-buffer-display-entries, guix-buffer-get-display-entries): New procedures. * emacs/guix-info.el: Adjust for the procedures renaming. (guix-info-define-interface): Add ':show-entries-function' keyword. * emacs/guix-list.el: Likewise. * emacs/guix-ui.el (guix-ui-define-interface): Generate 'guix-ENTRY-TYPE-BUFFER-TYPE-get-entries' procedure based on 'guix-ui-get-entries'. * emacs/guix.el (guix-get-show-packages, guix-get-show-generations): Adjust for the procedures renaming. --- emacs/guix-info.el | 58 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'emacs/guix-info.el') diff --git a/emacs/guix-info.el b/emacs/guix-info.el index 871c4b085f..9c63892d06 100644 --- a/emacs/guix-info.el +++ b/emacs/guix-info.el @@ -202,8 +202,7 @@ LEVEL is 1 by default." (insert (guix-info-get-indent level))) (defun guix-info-insert-entries (entries entry-type) - "Display ENTRIES of ENTRY-TYPE in the current info buffer. -ENTRIES should have a form of `guix-entries'." + "Display ENTRY-TYPE ENTRIES in the current info buffer." (guix-mapinsert (lambda (entry) (guix-info-insert-entry entry entry-type)) entries @@ -371,8 +370,11 @@ BUTTON-OR-FACE is a button type)." 'face 'guix-package-info-name-button 'help-echo "Describe this package" 'action (lambda (btn) - (guix-get-show-entries guix-profile 'info guix-package-info-type - 'name (button-label btn)))) + (guix-buffer-get-display-entries-current + 'info guix-package-info-type + (list (guix-ui-current-profile) + 'name (button-label btn)) + 'add))) (defun guix-info-button-copy-label (&optional pos) "Copy a label of the button at POS into kill ring. @@ -407,7 +409,8 @@ See `insert-text-button' for the meaning of PROPERTIES." "Keymap for `guix-info-mode' buffers.") (define-derived-mode guix-info-mode special-mode "Guix-Info" - "Parent mode for displaying information in info buffers.") + "Parent mode for displaying data in 'info' form." + (setq-local revert-buffer-function 'guix-buffer-revert)) (defun guix-info-mode-initialize () "Set up the current 'info' buffer." @@ -435,7 +438,8 @@ The rest keyword arguments are passed to (group (intern prefix)) (format-var (intern (concat prefix "-format")))) (guix-keyword-args-let args - ((format-val :format)) + ((show-entries-val :show-entries-function) + (format-val :format)) `(progn (defcustom ,format-var ,format-val ,(format "\ @@ -473,9 +477,23 @@ After calling each METHOD, a new line is inserted." '((format . ,format-var)) 'guix-info-data ',entry-type) - (guix-buffer-define-interface info ,entry-type - :mode-init-function 'guix-info-mode-initialize - ,@%foreign-args))))) + ,(if show-entries-val + `(guix-buffer-define-interface info ,entry-type + :show-entries-function ,show-entries-val + ,@%foreign-args) + + (let ((insert-fun (intern (concat prefix "-insert-entries")))) + `(progn + (defun ,insert-fun (entries) + ,(format "\ +Print '%s' ENTRIES in the current 'info' buffer." + entry-type-str) + (guix-info-insert-entries entries ',entry-type)) + + (guix-buffer-define-interface info ,entry-type + :insert-entries-function ',insert-fun + :mode-init-function 'guix-info-mode-initialize + ,@%foreign-args)))))))) ;;; Displaying packages @@ -675,7 +693,7 @@ ENTRY is an alist with package info." type-str (lambda (btn) (guix-process-package-actions - guix-profile + (guix-ui-current-profile) `((,(button-get btn 'action-type) (,(button-get btn 'id) ,(button-get btn 'output)))) (current-buffer))) @@ -726,15 +744,16 @@ prompt depending on `guix-operation-confirm' variable)." Find the file if needed (see `guix-package-info-auto-find-source'). ENTRY-ID is an ID of the current entry (package or output). PACKAGE-ID is an ID of the package which source to show." - (let* ((entries guix-entries) - (entry (guix-entry-by-id entry-id guix-entries)) + (let* ((entries (guix-buffer-current-entries)) + (entry (guix-entry-by-id entry-id entries)) (file (guix-package-source-path package-id))) (or file (error "Couldn't define file name of the package source")) (let* ((new-entry (cons (cons 'source-file file) entry)) (new-entries (guix-replace-entry entry-id new-entry entries))) - (setq guix-entries new-entries) + (setf (guix-buffer-item-entries guix-buffer-item) + new-entries) (guix-buffer-redisplay-goto-button) (if (file-exists-p file) (if guix-package-info-auto-find-source @@ -872,15 +891,19 @@ This function is used to hide a \"Download\" button if needed." (guix-info-insert-action-button "Packages" (lambda (btn) - (guix-get-show-entries guix-profile 'list guix-package-list-type - 'generation (button-get btn 'number))) + (guix-buffer-get-display-entries + 'list guix-package-list-type + (list (guix-ui-current-profile) + 'generation (button-get btn 'number)) + 'add)) "Show installed packages for this generation" 'number number) (guix-info-insert-indent) (guix-info-insert-action-button "Delete" (lambda (btn) - (guix-delete-generations guix-profile (list (button-get btn 'number)) + (guix-delete-generations (guix-ui-current-profile) + (list (button-get btn 'number)) (current-buffer))) "Delete this generation" 'number number)) @@ -894,7 +917,8 @@ This function is used to hide a \"Download\" button if needed." (guix-info-insert-action-button "Switch" (lambda (btn) - (guix-switch-to-generation guix-profile (button-get btn 'number) + (guix-switch-to-generation (guix-ui-current-profile) + (button-get btn 'number) (current-buffer))) "Switch to this generation (make it the current one)" 'number (guix-entry-value entry 'number)))) -- cgit v1.2.3