unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 3/4] emacs: Add "Build" button to Package Info.
Date: Sat, 28 May 2016 17:36:13 +0300	[thread overview]
Message-ID: <1464446174-1868-3-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1464446174-1868-1-git-send-email-alezost@gmail.com>

* emacs/guix-main.scm: Use (guix scripts) module for 'build-package'
  procedure.
* emacs/guix-base.el (guix-build-package): New procedure.
* emacs/guix-ui-package.el (guix-package-info-insert-build-button): New
  procedure.
(guix-package-info-button-functions): New variable.
(guix-package-info-insert-misc): Insert buttons using it.
---
 emacs/guix-base.el       | 14 ++++++++++++++
 emacs/guix-main.scm      |  1 +
 emacs/guix-ui-package.el | 28 +++++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index 9620100..658cfdb 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -231,6 +231,20 @@ Ask a user with PROMPT for continuing an operation."
       :dry-run? (or guix-dry-run 'f))
      nil 'source-download)))
 
+(defun guix-build-package (package-id &optional prompt)
+  "Build package with PACKAGE-ID.
+Ask a user with PROMPT for continuing the build operation."
+  (when (or (not guix-operation-confirm)
+            (guix-operation-prompt (or prompt "Build package?")))
+    (guix-eval-in-repl
+     (format (concat ",run-in-store "
+                     "(build-package (package-by-id %d)"
+                     " #:use-substitutes? %s"
+                     " #:dry-run? %s)")
+             package-id
+             (guix-guile-boolean guix-use-substitutes)
+             (guix-guile-boolean guix-dry-run)))))
+
 ;;;###autoload
 (defun guix-apply-manifest (profile file &optional operation-buffer)
   "Apply manifest from FILE to PROFILE.
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index c4f1b4a..8914933 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -51,6 +51,7 @@
  (guix licenses)
  (guix utils)
  (guix ui)
+ (guix scripts)
  (guix scripts package)
  (gnu packages)
  (gnu system))
diff --git a/emacs/guix-ui-package.el b/emacs/guix-ui-package.el
index eebecc7..4eb7083 100644
--- a/emacs/guix-ui-package.el
+++ b/emacs/guix-ui-package.el
@@ -332,6 +332,13 @@ prompt depending on `guix-operation-confirm' variable)."
   :type 'boolean
   :group 'guix-package-info)
 
+(defcustom guix-package-info-button-functions
+  '(guix-package-info-insert-build-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)
+  :group 'guix-package-info)
+
 (defvar guix-package-info-download-buffer nil
   "Buffer from which a current download operation was performed.")
 
@@ -558,6 +565,7 @@ PACKAGE-ID is an ID of the package which store path to show."
     (let* ((entry-id   (guix-entry-id entry))
            (package-id (or (guix-entry-value entry 'package-id)
                            entry-id))
+           (full-name  (guix-package-entry->name-specification entry))
            (store-path (guix-entry-value entry 'store-path)))
       (guix-info-insert-title-simple "Package")
       (if store-path
@@ -570,7 +578,25 @@ PACKAGE-ID is an ID of the package which store path to show."
             (button-get btn 'package-id)))
          "Show the store directory of the current package"
          'entry-id entry-id
-         'package-id package-id)))))
+         'package-id package-id))
+      (when guix-package-info-button-functions
+        (insert "\n")
+        (guix-mapinsert (lambda (fun)
+                          (funcall fun package-id full-name))
+                        guix-package-info-button-functions
+                        (guix-info-get-indent)
+                        :indent guix-info-indent
+                        :column (guix-info-fill-column))))))
+
+(defun guix-package-info-insert-build-button (id full-name)
+  "Insert button to build a package defined by ID."
+  (guix-info-insert-action-button
+   "Build"
+   (lambda (btn)
+     (guix-build-package (button-get btn 'id)
+                         (format "Build '%s' package?" full-name)))
+   (format "Build 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.
-- 
2.7.3

  parent reply	other threads:[~2016-05-28 14:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-28 14:36 [PATCH 1/4] emacs: Show built output directories in Package Info Alex Kost
2016-05-28 14:36 ` [PATCH 2/4] emacs: Extend 'guix-mapinsert' Alex Kost
2016-05-30 21:14   ` Ludovic Courtès
2016-05-28 14:36 ` Alex Kost [this message]
2016-05-30 21:15   ` [PATCH 3/4] emacs: Add "Build" button to Package Info Ludovic Courtès
2016-05-28 14:36 ` [PATCH 4/4] emacs: Add "Build Log" " Alex Kost
2016-05-30 21:17   ` Ludovic Courtès
2016-05-31 21:09     ` Alex Kost
2016-06-01 21:04       ` Ludovic Courtès
2016-05-30 21:13 ` [PATCH 1/4] emacs: Show built output directories in " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464446174-1868-3-git-send-email-alezost@gmail.com \
    --to=alezost@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).