unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH 0/4] emacs: Add "View graph" action to graph popup.
@ 2015-08-30 21:04 Alex Kost
  2015-08-30 21:04 ` [PATCH 1/4] emacs: Add code to pipe guix output to external program Alex Kost
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Alex Kost @ 2015-08-30 21:04 UTC (permalink / raw)
  To: guix-devel

This patchset adds "View graph" action to 'guix graph' popup (i.e., to
"M-x guix RET G").  By default the graph (png) will be opened in Emacs,
but this can be changed by setting 'guix-find-file-function' variable.
For example, I prefer to open png-files in sxiv, so I use:

(setq guix-find-file-function 'org-open-file)

and I have ("\\.png\\'" . "sxiv %s") element in my 'org-file-apps' var.

If you don't like png, you can set 'guix-dot-default-arguments' and
'guix-dot-file-name-function'.

[PATCH 1/4] emacs: Add code to pipe guix output to external program.
[PATCH 2/4] emacs: Add code to run 'dot' program.
[PATCH 3/4] emacs: Allow to choose 'find-file' function.
[PATCH 4/4] emacs: Add "View graph" action to graph popup.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/4] emacs: Add code to pipe guix output to external program.
  2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
@ 2015-08-30 21:04 ` Alex Kost
  2015-08-31 21:29   ` Ludovic Courtès
  2015-08-30 21:04 ` [PATCH 2/4] emacs: Add code to run 'dot' program Alex Kost
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Alex Kost @ 2015-08-30 21:04 UTC (permalink / raw)
  To: guix-devel

* emacs/guix-main.scm: Use (ice-9 popen) module.
  (pipe-guix-output): New procedure.
---
 emacs/guix-main.scm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index fe224fb..8d3a881 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -45,6 +45,7 @@
 (use-modules
  (ice-9 vlist)
  (ice-9 match)
+ (ice-9 popen)
  (srfi srfi-1)
  (srfi srfi-2)
  (srfi srfi-11)
@@ -949,6 +950,15 @@ GENERATIONS is a list of generation numbers."
   "Return string with 'guix COMMANDS ... --help' output."
   (apply guix-command-output `(,@commands "--help")))
 
+(define (pipe-guix-output guix-args command-args)
+  "Run 'guix GUIX-ARGS ...' command and pipe its output to a shell command
+defined by COMMAND-ARGS.
+Return #t if the shell command was executed successfully."
+  (let ((pipe (apply open-pipe* OPEN_WRITE command-args)))
+    (with-output-to-port pipe
+      (lambda () (apply guix-command guix-args)))
+    (zero? (status:exit-val (close-pipe pipe)))))
+
 \f
 ;;; Lists of packages, lint checkers, etc.
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/4] emacs: Add code to run 'dot' program.
  2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
  2015-08-30 21:04 ` [PATCH 1/4] emacs: Add code to pipe guix output to external program Alex Kost
@ 2015-08-30 21:04 ` Alex Kost
  2015-08-31 21:29   ` Ludovic Courtès
  2015-08-30 21:04 ` [PATCH 3/4] emacs: Allow to choose 'find-file' function Alex Kost
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Alex Kost @ 2015-08-30 21:04 UTC (permalink / raw)
  To: guix-devel

* emacs/guix-external.el: New file.
* emacs.am (ELFILES): Add it.
---
 emacs.am               |  1 +
 emacs/guix-external.el | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 emacs/guix-external.el

diff --git a/emacs.am b/emacs.am
index 0f1ac94..5d3cb81 100644
--- a/emacs.am
+++ b/emacs.am
@@ -23,6 +23,7 @@ ELFILES =					\
   emacs/guix-base.el				\
   emacs/guix-command.el				\
   emacs/guix-emacs.el				\
+  emacs/guix-external.el			\
   emacs/guix-help-vars.el			\
   emacs/guix-history.el				\
   emacs/guix-info.el				\
diff --git a/emacs/guix-external.el b/emacs/guix-external.el
new file mode 100644
index 0000000..d233473
--- /dev/null
+++ b/emacs/guix-external.el
@@ -0,0 +1,72 @@
+;;; guix-external.el --- External programs  -*- lexical-binding: t -*-
+
+;; Copyright © 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 auxiliary code for running external programs.
+
+;;; Code:
+
+(defgroup guix-external nil
+  "Settings for external programs."
+  :group 'guix)
+
+(defcustom guix-dot-program (executable-find "dot")
+  "Name of the 'dot' executable."
+  :type 'string
+  :group 'guix-external)
+
+(defcustom guix-dot-default-arguments
+  '("-Tpng")
+  "Default arguments for 'dot' program."
+  :type '(repeat string)
+  :group 'guix-external)
+
+(defcustom guix-dot-file-name-function #'guix-png-file-name
+  "Function used to define a file name of a temporary 'dot' file.
+The function is called without arguments."
+  :type '(choice (function-item guix-png-file-name)
+                 (function :tag "Other function"))
+  :group 'guix-external)
+
+(defun guix-dot-arguments (output-file &rest args)
+  "Return a list of dot arguments for writing a graph into OUTPUT-FILE.
+If ARGS is nil, use `guix-dot-default-arguments'."
+  (or guix-dot-program
+      (error (concat "Couldn't find 'dot'.\n"
+                     "Set guix-dot-program to a proper value")))
+  (apply #'list
+         guix-dot-program
+         (concat "-o" output-file)
+         (or args guix-dot-default-arguments)))
+
+(defun guix-dot-file-name ()
+  "Call `guix-dot-file-name-function'."
+  (funcall guix-dot-file-name-function))
+
+(defun guix-png-file-name ()
+  "Return '.png' file name in the `temporary-file-directory'."
+  (concat (make-temp-name
+           (concat (file-name-as-directory temporary-file-directory)
+                   "graph-"))
+          ".png"))
+
+(provide 'guix-external)
+
+;;; guix-external.el ends here
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/4] emacs: Allow to choose 'find-file' function.
  2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
  2015-08-30 21:04 ` [PATCH 1/4] emacs: Add code to pipe guix output to external program Alex Kost
  2015-08-30 21:04 ` [PATCH 2/4] emacs: Add code to run 'dot' program Alex Kost
@ 2015-08-30 21:04 ` Alex Kost
  2015-08-31 21:31   ` Ludovic Courtès
  2015-08-30 21:04 ` [PATCH 4/4] emacs: Add "View graph" action to graph popup Alex Kost
  2015-08-31 21:28 ` [PATCH 0/4] " Ludovic Courtès
  4 siblings, 1 reply; 11+ messages in thread
From: Alex Kost @ 2015-08-30 21:04 UTC (permalink / raw)
  To: guix-devel

* emacs/guix-utils.el (guix-find-file-function): New variable.
  (guix-find-file): Use it.
---
 emacs/guix-utils.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index 78ea354..c1ce954 100644
--- a/emacs/guix-utils.el
+++ b/emacs/guix-utils.el
@@ -193,10 +193,19 @@ Return time value."
   (require 'org)
   (org-read-date nil t nil prompt))
 
+(defcustom guix-find-file-function #'find-file
+  "Function used to find a file.
+The function is called by `guix-find-file' with a file name as a
+single argument."
+  :type '(choice (function-item find-file)
+                 (function-item org-open-file)
+                 (function :tag "Other function"))
+  :group 'guix)
+
 (defun guix-find-file (file)
   "Find FILE if it exists."
   (if (file-exists-p file)
-      (find-file file)
+      (funcall guix-find-file-function file)
     (message "File '%s' does not exist." file)))
 
 (defmacro guix-while-search (regexp &rest body)
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4] emacs: Add "View graph" action to graph popup.
  2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
                   ` (2 preceding siblings ...)
  2015-08-30 21:04 ` [PATCH 3/4] emacs: Allow to choose 'find-file' function Alex Kost
@ 2015-08-30 21:04 ` Alex Kost
  2015-08-31 21:32   ` Ludovic Courtès
  2015-08-31 21:28 ` [PATCH 0/4] " Ludovic Courtès
  4 siblings, 1 reply; 11+ messages in thread
From: Alex Kost @ 2015-08-30 21:04 UTC (permalink / raw)
  To: guix-devel

* emacs/guix-command.el: Require 'guix-external'.
  (guix-run-view-graph): New function.
  (guix-command-additional-execute-arguments,
  guix-command-special-executors): Add entries for "View graph" action.
---
 emacs/guix-command.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/emacs/guix-command.el b/emacs/guix-command.el
index 139724d..3513300 100644
--- a/emacs/guix-command.el
+++ b/emacs/guix-command.el
@@ -65,6 +65,7 @@
 (require 'guix-help-vars)
 (require 'guix-read)
 (require 'guix-base)
+(require 'guix-external)
 
 (defgroup guix-commands nil
   "Settings for guix popup windows."
@@ -490,7 +491,9 @@ to be modified."
   "List of default 'execute' action arguments.")
 
 (defvar guix-command-additional-execute-arguments
-  nil
+  `((("graph")
+     ,(guix-command-make-argument
+       :name "view" :char ?v :doc "View graph")))
   "Alist of guix commands and additional 'execute' action arguments.")
 
 (defun guix-command-execute-arguments (commands)
@@ -508,7 +511,9 @@ to be modified."
   '((("environment")
      ("repl" . guix-run-environment-command-in-repl))
     (("pull")
-     ("repl" . guix-run-pull-command-in-repl)))
+     ("repl" . guix-run-pull-command-in-repl))
+    (("graph")
+     ("view" . guix-run-view-graph)))
   "Alist of guix commands and alists of special executers for them.
 See also `guix-command-default-executors'.")
 
@@ -545,6 +550,15 @@ Perform pull-specific actions after operation, see
    (apply #'guix-make-guile-expression 'guix-command args)
    nil 'pull))
 
+(defun guix-run-view-graph (args)
+  "Run 'guix ARGS ...' graph command, make the image and open it."
+  (let* ((graph-file (guix-dot-file-name))
+         (dot-args   (guix-dot-arguments graph-file)))
+    (if (guix-eval-read (guix-make-guile-expression
+                         'pipe-guix-output args dot-args))
+        (guix-find-file graph-file)
+      (error "Couldn't create a graph"))))
+
 \f
 ;;; Generating popups, actions, etc.
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/4] emacs: Add "View graph" action to graph popup.
  2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
                   ` (3 preceding siblings ...)
  2015-08-30 21:04 ` [PATCH 4/4] emacs: Add "View graph" action to graph popup Alex Kost
@ 2015-08-31 21:28 ` Ludovic Courtès
  4 siblings, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:28 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> This patchset adds "View graph" action to 'guix graph' popup (i.e., to
> "M-x guix RET G").  By default the graph (png) will be opened in Emacs,
> but this can be changed by setting 'guix-find-file-function' variable.
> For example, I prefer to open png-files in sxiv, so I use:
>
> (setq guix-find-file-function 'org-open-file)
>
> and I have ("\\.png\\'" . "sxiv %s") element in my 'org-file-apps' var.
>
> If you don't like png, you can set 'guix-dot-default-arguments' and
> 'guix-dot-file-name-function'.

Heheh, excellent.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] emacs: Add code to pipe guix output to external program.
  2015-08-30 21:04 ` [PATCH 1/4] emacs: Add code to pipe guix output to external program Alex Kost
@ 2015-08-31 21:29   ` Ludovic Courtès
  0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:29 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> * emacs/guix-main.scm: Use (ice-9 popen) module.
>   (pipe-guix-output): New procedure.

OK.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/4] emacs: Add code to run 'dot' program.
  2015-08-30 21:04 ` [PATCH 2/4] emacs: Add code to run 'dot' program Alex Kost
@ 2015-08-31 21:29   ` Ludovic Courtès
  0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:29 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> * emacs/guix-external.el: New file.
> * emacs.am (ELFILES): Add it.

LGTM.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] emacs: Allow to choose 'find-file' function.
  2015-08-30 21:04 ` [PATCH 3/4] emacs: Allow to choose 'find-file' function Alex Kost
@ 2015-08-31 21:31   ` Ludovic Courtès
  2015-09-01 10:05     ` Alex Kost
  0 siblings, 1 reply; 11+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:31 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> * emacs/guix-utils.el (guix-find-file-function): New variable.
>   (guix-find-file): Use it.

OK.

Nitpick: “Allow users to choose a ‘find-file’ function.”
                ^^^^^           ^
Ludo’.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] emacs: Add "View graph" action to graph popup.
  2015-08-30 21:04 ` [PATCH 4/4] emacs: Add "View graph" action to graph popup Alex Kost
@ 2015-08-31 21:32   ` Ludovic Courtès
  0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:32 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> * emacs/guix-command.el: Require 'guix-external'.
>   (guix-run-view-graph): New function.
>   (guix-command-additional-execute-arguments,
>   guix-command-special-executors): Add entries for "View graph" action.

OK!

This is really cool, thanks a lot!

Ludo’.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] emacs: Allow to choose 'find-file' function.
  2015-08-31 21:31   ` Ludovic Courtès
@ 2015-09-01 10:05     ` Alex Kost
  0 siblings, 0 replies; 11+ messages in thread
From: Alex Kost @ 2015-09-01 10:05 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès (2015-09-01 00:31 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> * emacs/guix-utils.el (guix-find-file-function): New variable.
>>   (guix-find-file): Use it.
>
> OK.
>
> Nitpick: “Allow users to choose a ‘find-file’ function.”
>                 ^^^^^           ^

Fixed.  Thank you for the review, I have pushed these patches.

-- 
Alex

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-09-01 10:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-30 21:04 [PATCH 0/4] emacs: Add "View graph" action to graph popup Alex Kost
2015-08-30 21:04 ` [PATCH 1/4] emacs: Add code to pipe guix output to external program Alex Kost
2015-08-31 21:29   ` Ludovic Courtès
2015-08-30 21:04 ` [PATCH 2/4] emacs: Add code to run 'dot' program Alex Kost
2015-08-31 21:29   ` Ludovic Courtès
2015-08-30 21:04 ` [PATCH 3/4] emacs: Allow to choose 'find-file' function Alex Kost
2015-08-31 21:31   ` Ludovic Courtès
2015-09-01 10:05     ` Alex Kost
2015-08-30 21:04 ` [PATCH 4/4] emacs: Add "View graph" action to graph popup Alex Kost
2015-08-31 21:32   ` Ludovic Courtès
2015-08-31 21:28 ` [PATCH 0/4] " Ludovic Courtès

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).