[4/4] emacs: Add "Build Log" button to Package Info.

Message ID 1464446174-1868-4-git-send-email-alezost@gmail.com
State New
Headers

Commit Message

Alex Kost May 28, 2016, 2:36 p.m. UTC
  * emacs/guix-main.scm (package-build-log-file): New procedure.
* emacs/guix-ui-package.el (guix-package-build-log-file)
(guix-package-find-build-log)
(guix-package-info-insert-build-log-button): New procedures.
(guix-package-info-button-functions): Add
'guix-package-info-insert-build-log-button'.
---
 emacs/guix-main.scm      | 10 ++++++++++
 emacs/guix-ui-package.el | 25 ++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
  

Comments

Ludovic Courtès May 30, 2016, 9:17 p.m. UTC | #1
Alex Kost <alezost@gmail.com> skribis:

> * emacs/guix-main.scm (package-build-log-file): New procedure.
> * emacs/guix-ui-package.el (guix-package-build-log-file)
> (guix-package-find-build-log)
> (guix-package-info-insert-build-log-button): New procedures.
> (guix-package-info-button-functions): Add
> 'guix-package-info-insert-build-log-button'.

OK!

I think having this extra info and extra buttons is nice.  I wonder
though if in the future we should have a way to hide non-essential info
and buttons, so that someone who just wants to search and install/remove
software isn’t overwhelmed.

What are your thoughts?

Thank you!

Ludo’.
  
Alex Kost May 31, 2016, 9:09 p.m. UTC | #2
Ludovic Courtès (2016-05-31 00:17 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> * emacs/guix-main.scm (package-build-log-file): New procedure.
>> * emacs/guix-ui-package.el (guix-package-build-log-file)
>> (guix-package-find-build-log)
>> (guix-package-info-insert-build-log-button): New procedures.
>> (guix-package-info-button-functions): Add
>> 'guix-package-info-insert-build-log-button'.
>
> OK!

Thanks, I've pushed this patchset.

> I think having this extra info and extra buttons is nice.  I wonder
> though if in the future we should have a way to hide non-essential info
> and buttons, so that someone who just wants to search and install/remove
> software isn’t overwhelmed.
>
> What are your thoughts?

I agree that there may be too much buttons for a new user, but I
wouldn't like to hide features by default.  For users, there is
'guix-package-info-format' variable.  It is a bit complicated but it
allows to control any aspect of *Guix Package Info* buffer.  For
example, one could hide all non-essential info like this:

(setq guix-package-info-format
      '(guix-package-info-insert-heading
        (outputs ignore guix-package-info-insert-outputs)))
  
Ludovic Courtès June 1, 2016, 9:04 p.m. UTC | #3
Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2016-05-31 00:17 +0300) wrote:

[...]

>> I think having this extra info and extra buttons is nice.  I wonder
>> though if in the future we should have a way to hide non-essential info
>> and buttons, so that someone who just wants to search and install/remove
>> software isn’t overwhelmed.
>>
>> What are your thoughts?
>
> I agree that there may be too much buttons for a new user, but I
> wouldn't like to hide features by default.  For users, there is
> 'guix-package-info-format' variable.  It is a bit complicated but it
> allows to control any aspect of *Guix Package Info* buffer.  For
> example, one could hide all non-essential info like this:
>
> (setq guix-package-info-format
>       '(guix-package-info-insert-heading
>         (outputs ignore guix-package-info-insert-outputs)))

OK, makes sense.  Let’s keep it this way for now.

Thanks,
Ludo’.
  

Patch

diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 8914933..cbf7cdc 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -1000,6 +1000,16 @@  GENERATIONS is a list of generation numbers."
         (format #t "The source store path: ~a~%"
                 (package-source-derivation->store-path derivation))))))
 
+(define (package-build-log-file package-id)
+  "Return the build log file of a package PACKAGE-ID.
+Return #f if the build log is not found."
+  (and-let* ((package (package-by-id package-id)))
+    (with-store store
+      (let* ((derivation (package-derivation store package))
+             (file       (derivation-file-name derivation)))
+        (or (log-file store file)
+            ((@@ (guix scripts build) log-url) store file))))))
+
 
 ;;; Executing guix commands
 
diff --git a/emacs/guix-ui-package.el b/emacs/guix-ui-package.el
index 4eb7083..4280246 100644
--- a/emacs/guix-ui-package.el
+++ b/emacs/guix-ui-package.el
@@ -111,6 +111,19 @@  is found and `guix-package-list-single' is nil."
       (list (if (= 0 package-id) package-id-str package-id)
             output))))
 
+(defun guix-package-build-log-file (id)
+  "Return build log file name of a package defined by ID."
+  (guix-eval-read
+   (guix-make-guile-expression 'package-build-log-file id)))
+
+(defun guix-package-find-build-log (id)
+  "Show build log of a package defined by ID."
+  (require 'guix-build-log)
+  (let ((file (guix-package-build-log-file id)))
+    (if file
+        (guix-build-log-find-file file)
+      (message "Couldn't find the package build log."))))
+
 
 ;;; Processing package actions
 
@@ -333,7 +346,8 @@  prompt depending on `guix-operation-confirm' variable)."
   :group 'guix-package-info)
 
 (defcustom guix-package-info-button-functions
-  '(guix-package-info-insert-build-button)
+  '(guix-package-info-insert-build-button
+    guix-package-info-insert-build-log-button)
   "List of functions used to insert package buttons in Info buffer.
 Each function is called with 2 arguments: package ID and full name."
   :type '(repeat function)
@@ -598,6 +612,15 @@  PACKAGE-ID is an ID of the package which store path to show."
    (format "Build the current package")
    'id id))
 
+(defun guix-package-info-insert-build-log-button (id _name)
+  "Insert button to show build log of a package defined by ID."
+  (guix-info-insert-action-button
+   "Build Log"
+   (lambda (btn)
+     (guix-package-find-build-log (button-get btn 'id)))
+   "View build log of the current package"
+   'id id))
+
 (defun guix-package-info-show-source (entry-id package-id)
   "Show file name of a package source in the current info buffer.
 Find the file if needed (see `guix-package-info-auto-find-source').