tests: Add 'openssh-service-type' test.
[jackhill/guix/guix.git] / emacs / guix-external.el
1 ;;; guix-external.el --- External programs -*- lexical-binding: t -*-
2
3 ;; Copyright © 2015 Alex Kost <alezost@gmail.com>
4
5 ;; This file is part of GNU Guix.
6
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; This file provides auxiliary code for running external programs.
23
24 ;;; Code:
25
26 (require 'cl-lib)
27 (require 'guix-config)
28
29 (defgroup guix-external nil
30 "Settings for external programs."
31 :group 'guix)
32
33 (defcustom guix-guile-program guix-config-guile-program
34 "Name of the 'guile' executable used for Guix REPL.
35 May be either a string (the name of the executable) or a list of
36 strings of the form:
37
38 (NAME . ARGS)
39
40 Where ARGS is a list of arguments to the guile program."
41 :type 'string
42 :group 'guix-external)
43
44 (defcustom guix-dot-program
45 (if (file-name-absolute-p guix-config-dot-program)
46 guix-config-dot-program
47 (executable-find "dot"))
48 "Name of the 'dot' executable."
49 :type 'string
50 :group 'guix-external)
51
52 (defcustom guix-dot-default-arguments
53 '("-Tpng")
54 "Default arguments for 'dot' program."
55 :type '(repeat string)
56 :group 'guix-external)
57
58 (defcustom guix-dot-file-name-function #'guix-png-file-name
59 "Function used to define a file name of a temporary 'dot' file.
60 The function is called without arguments."
61 :type '(choice (function-item guix-png-file-name)
62 (function :tag "Other function"))
63 :group 'guix-external)
64
65 (defun guix-dot-arguments (output-file &rest args)
66 "Return a list of dot arguments for writing a graph into OUTPUT-FILE.
67 If ARGS is nil, use `guix-dot-default-arguments'."
68 (or guix-dot-program
69 (error (concat "Couldn't find 'dot'.\n"
70 "Set guix-dot-program to a proper value")))
71 (cl-list* guix-dot-program
72 (concat "-o" output-file)
73 (or args guix-dot-default-arguments)))
74
75 (defun guix-dot-file-name ()
76 "Call `guix-dot-file-name-function'."
77 (funcall guix-dot-file-name-function))
78
79 (defun guix-png-file-name ()
80 "Return '.png' file name in the `temporary-file-directory'."
81 (concat (make-temp-name
82 (concat (file-name-as-directory temporary-file-directory)
83 "guix-emacs-graph-"))
84 ".png"))
85
86 (provide 'guix-external)
87
88 ;;; guix-external.el ends here