guix-about.el 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ;;; guix-about.el --- Various info about Guix and Emacs-Guix -*- lexical-binding: t -*-
  2. ;; Copyright © 2016–2017 Alex Kost <alezost@gmail.com>
  3. ;; This file is part of Emacs-Guix.
  4. ;; Emacs-Guix is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; Emacs-Guix is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This file provides the code to display various info about Guix (e.g., its
  18. ;; version) and Emacs-Guix.
  19. ;;; Code:
  20. (require 'bui)
  21. (require 'guix nil t)
  22. (require 'guix-help)
  23. (require 'guix-utils)
  24. (require 'guix-config)
  25. (declare-function guix-eval-read "guix-repl" (str))
  26. ;;;###autoload
  27. (defun guix-version ()
  28. "Display Emacs-Guix and Guix versions in the echo area."
  29. (interactive)
  30. (require 'guix-repl)
  31. (message "%s %s\n%s %s"
  32. (guix-eval-read "(@ (guix config) %guix-package-name)")
  33. (guix-eval-read "(@ (guix config) %guix-version)")
  34. guix-config-name
  35. guix-config-version))
  36. ;;; "About" buffer
  37. (defcustom guix-about-buffer-name "*Guix About*"
  38. "Buffer name for '\\[guix-about]'."
  39. :type 'string
  40. :group 'guix)
  41. (defvar guix-about-specifications
  42. `("GNU Guix: "
  43. :link ("https://www.gnu.org/software/guix/"
  44. ,(lambda (button)
  45. (browse-url (button-label button))))
  46. "\nEmacs-Guix: "
  47. :link ("https://github.com/alezost/guix.el"
  48. ,(lambda (button)
  49. (browse-url (button-label button))))
  50. "\n\n"
  51. :link ("GNU Guix Manual"
  52. ,(lambda (_button) (info "(guix)")))
  53. "\n"
  54. :link ("Emacs Guix Manual"
  55. ,(lambda (_button) (info "(emacs-guix)")))
  56. "\n"
  57. "\nAvailable commands: "
  58. :link ("M-x guix-help"
  59. ,(lambda (_button) (guix-help)))
  60. "\nGuix and Emacs-Guix versions: "
  61. :link ("M-x guix-version"
  62. ,(lambda (_button) (guix-version)))
  63. "\n")
  64. "Text to show with '\\[guix-about]' command.
  65. This is not really a text, it is a list of arguments passed to
  66. `fancy-splash-insert'.")
  67. (defun guix-logo-file ()
  68. "Return the file name of Guix(SD) logo image.
  69. Return nil, if the image cannot be found."
  70. (when guix-image-directory
  71. (expand-file-name (if (guix-guixsd?)
  72. "guixsd-logo.svg"
  73. "guix-logo.svg")
  74. guix-image-directory)))
  75. (defun guix-insert-logo ()
  76. "Insert Guix(SD) logo into the current buffer."
  77. (when (display-images-p)
  78. (let* ((file (guix-logo-file))
  79. (image (and file (create-image file))))
  80. (when image
  81. (let ((width (car (image-size image))))
  82. (when (> (window-width) width)
  83. ;; Center the image in the window.
  84. (insert (propertize
  85. " " 'display
  86. `(space :align-to (+ center (-0.5 . ,image)))))
  87. (insert-image image)
  88. (bui-newline)))))))
  89. (defun guix-about-insert-content ()
  90. "Insert Emacs-Guix 'about' info into the current buffer."
  91. (guix-insert-logo)
  92. (apply #'fancy-splash-insert guix-about-specifications)
  93. (goto-char (point-min))
  94. (forward-line 3))
  95. (defun guix-about-show ()
  96. "Display 'About' buffer with fancy Guix logo if available.
  97. Unlike `guix-about', this command always recreates
  98. `guix-about-buffer-name' buffer."
  99. (interactive)
  100. (guix-help-display-buffer guix-about-buffer-name
  101. #'guix-about-insert-content))
  102. ;;;###autoload
  103. (defun guix-about ()
  104. "Display 'About' buffer with fancy Guix logo if available.
  105. Switch to `guix-about-buffer-name' buffer if it already exists."
  106. (interactive)
  107. (guix-switch-to-buffer-or-funcall
  108. guix-about-buffer-name #'guix-about-show))
  109. (provide 'guix-about)
  110. ;;; guix-about.el ends here