guix-auto-mode.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; guix-auto-mode.el --- Settings for `auto-mode-alist'
  2. ;; Copyright © 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 contains "autoloads" for `auto-mode-alist' and some
  18. ;; variables that are used by regexps.
  19. ;;; Code:
  20. ;;;###autoload
  21. (defvar guix-store-directory "/gnu/store"
  22. "Name of the Guix store directory.
  23. See Info node `(guix) The Store'.
  24. This string is used in various regular expressions and it
  25. shouldn't end with a trailing slash.")
  26. ;;;###autoload
  27. (defvar guix-hash-regexp
  28. ;; Hash-parts do not include "e", "o", "u" and "t". See base32Chars
  29. ;; at <https://github.com/NixOS/nix/blob/master/src/libutil/hash.cc>
  30. (rx (= 32 (any "0-9" "a-d" "f-n" "p-s" "v-z")))
  31. "Regexp matching hash part of a store file name.")
  32. ;;;###autoload
  33. (unless (rassq 'guix-build-log-mode auto-mode-alist)
  34. ;; The purpose of this ^^^ check is to avoid running this sexp twice:
  35. ;; if `auto-mode-alist' contains some guix mode, then most likely this
  36. ;; sexp has already been evaluated by "autoloads.el".
  37. (let ((chars-rx (rx (+ (any alnum "-_+.")))))
  38. (setq
  39. auto-mode-alist
  40. (append
  41. ;; Regexp for log files (usually placed in /var/log/guix/...)
  42. `((,(rx-to-string `(and "/guix/drvs/" (= 2 alnum) "/" (= 30 alnum)
  43. "-" (regexp ,chars-rx) ".drv" string-end)
  44. t)
  45. . guix-build-log-mode)
  46. (,(rx-to-string `(and ,guix-store-directory "/"
  47. (regexp ,chars-rx) ".drv" string-end)
  48. t)
  49. . guix-derivation-mode)
  50. (,(rx-to-string
  51. `(and "/guix/profiles/system" (* (regexp ,chars-rx)) "/"
  52. (or "boot" "parameters")
  53. string-end)
  54. t)
  55. . guix-scheme-mode)
  56. (,(rx-to-string
  57. `(and ,guix-store-directory "/" (regexp ,guix-hash-regexp) "-"
  58. (or "activate" "activate-service" "boot" "parameters"
  59. "shepherd.conf"
  60. (and "shepherd" (regexp ,chars-rx) ".scm")
  61. (and (regexp ,chars-rx) "-guile-builder"))
  62. string-end)
  63. t)
  64. . guix-scheme-mode))
  65. auto-mode-alist))))
  66. (provide 'guix-auto-mode)
  67. ;;; guix-auto-mode.el ends here