guix-auto-mode.el 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;;; guix-auto-mode.el --- Settings for `auto-mode-alist'
  2. ;; Copyright © 2017 Alex Kost <alezost@gmail.com>
  3. ;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  4. ;; This file is part of Emacs-Guix.
  5. ;; Emacs-Guix is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;;
  10. ;; Emacs-Guix is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;;
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This file contains "autoloads" for `auto-mode-alist' and some
  19. ;; variables that are used by regexps.
  20. ;;; Code:
  21. ;;;###autoload
  22. (defvar guix-store-directory "/gnu/store"
  23. "Name of the Guix store directory.
  24. See Info node `(guix) The Store'.
  25. This string is used in various regular expressions and it
  26. shouldn't end with a trailing slash.")
  27. ;;;###autoload
  28. (defvar guix-hash-regexp
  29. ;; Hash-parts do not include "e", "o", "u" and "t". See base32Chars
  30. ;; at <https://github.com/NixOS/nix/blob/master/src/libutil/hash.cc>
  31. (rx (= 32 (any "0-9" "a-d" "f-n" "p-s" "v-z")))
  32. "Regexp matching hash part of a store file name.")
  33. ;;;###autoload
  34. (unless (rassq 'guix-build-log-mode auto-mode-alist)
  35. ;; The purpose of this ^^^ check is to avoid running this sexp twice:
  36. ;; if `auto-mode-alist' contains some guix mode, then most likely this
  37. ;; sexp has already been evaluated by "autoloads.el".
  38. (let ((chars-rx (rx (+ (any alnum "-_+.")))))
  39. (setq
  40. auto-mode-alist
  41. (append
  42. ;; Regexp for log files (usually placed in /var/log/guix/...)
  43. `((,(rx-to-string `(and "/guix/drvs/" (= 2 alnum) "/" (= 30 alnum)
  44. "-" (regexp ,chars-rx) ".drv" string-end)
  45. t)
  46. . guix-build-log-mode)
  47. (,(rx-to-string `(and ,guix-store-directory "/"
  48. (regexp ,chars-rx) ".drv" string-end)
  49. t)
  50. . guix-derivation-mode)
  51. (,(rx-to-string `(and "/etc/profile" string-end) t)
  52. . guix-env-var-mode)
  53. (,(rx-to-string
  54. `(and "/tmp/guix-build-" (regexp ,chars-rx)
  55. ".drv-" (one-or-more digit) "/environment-variables"
  56. string-end)
  57. t)
  58. . guix-env-var-mode)
  59. (,(rx-to-string
  60. `(and "/guix/profiles/system" (* (regexp ,chars-rx)) "/"
  61. (or "boot" "parameters")
  62. string-end)
  63. t)
  64. . guix-scheme-mode)
  65. (,(rx-to-string
  66. `(and ,guix-store-directory "/" (regexp ,guix-hash-regexp) "-"
  67. (or "activate" "activate-service" "boot" "parameters"
  68. "shepherd.conf"
  69. (and "shepherd" (regexp ,chars-rx) ".scm")
  70. (and (regexp ,chars-rx) "-guile-builder"))
  71. string-end)
  72. t)
  73. . guix-scheme-mode))
  74. auto-mode-alist))))
  75. (provide 'guix-auto-mode)
  76. ;;; guix-auto-mode.el ends here