guix-about.el 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ;;; guix-about.el --- Various info about Guix and Emacs-Guix -*- lexical-binding: t -*-
  2. ;; Copyright © 2016–2017, 2019 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://emacs-guix.gitlab.io/website/"
  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 the Guix logo image.
  69. Return nil if the image cannot be found."
  70. (when guix-image-directory
  71. (expand-file-name "guix-logo.svg" guix-image-directory)))
  72. ;; Guix builds Emacs-Guix with 'emacs-minimal' package which does not
  73. ;; support many things including image stuff. This leads to a
  74. ;; (harmless) warning about missing `image-size' function during ELC
  75. ;; compilation. The following line hides this useless warning.
  76. (declare-function image-size "image.c")
  77. (defun guix-insert-logo ()
  78. "Insert Guix(SD) logo into the current buffer."
  79. (when (display-images-p)
  80. (let* ((file (guix-logo-file))
  81. (image (and file (create-image file))))
  82. (when image
  83. (let ((width (car (image-size image))))
  84. (when (> (window-width) width)
  85. ;; Center the image in the window.
  86. (insert (propertize
  87. " " 'display
  88. `(space :align-to (+ center (-0.5 . ,image)))))
  89. (insert-image image)
  90. (bui-newline)))))))
  91. (defun guix-about-insert-content ()
  92. "Insert Emacs-Guix 'about' info into the current buffer."
  93. (guix-insert-logo)
  94. (apply #'fancy-splash-insert guix-about-specifications)
  95. (goto-char (point-min))
  96. (forward-line 3))
  97. (defun guix-about-show ()
  98. "Display 'About' buffer with fancy Guix logo if available.
  99. Unlike `guix-about', this command always recreates
  100. `guix-about-buffer-name' buffer."
  101. (interactive)
  102. (guix-help-display-buffer guix-about-buffer-name
  103. #'guix-about-insert-content))
  104. ;;;###autoload
  105. (defun guix-about ()
  106. "Display 'About' buffer with fancy Guix logo if available.
  107. Switch to `guix-about-buffer-name' buffer if it already exists."
  108. (interactive)
  109. (guix-switch-to-buffer-or-funcall
  110. guix-about-buffer-name #'guix-about-show))
  111. (provide 'guix-about)
  112. ;;; guix-about.el ends here