Klimi's new dotfiles with stow.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

47 righe
1.4 KiB

  1. ;;; nix-shebang.el --- Handle nix shebang header -*- lexical-binding: t -*-
  2. ;; Author: Matthew Bauer <mjbauer95@gmail.com>
  3. ;; Homepage: https://github.com/NixOS/nix-mode
  4. ;; Version: 1.2.1
  5. ;; Keywords: nix, languages, tools, unix
  6. ;; Package-Requires: ((emacs "24.3"))
  7. ;; This file is NOT part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; This detects file headers that look like:
  10. ;; #!/usr/bin/env nix-shell
  11. ;; #!nix-shell -i bash
  12. ;; and correctly detects their file modes.
  13. ;;; Code:
  14. (require 'files)
  15. (defvar nix-shebang-interpreter-regexp "#!\s*nix-shell -i \\([^ \t\n]+\\)"
  16. "Regexp for nix-shell -i header.")
  17. (defun nix-shebang-get-interpreter ()
  18. "Get interpreter string from nix-shell -i file."
  19. (save-excursion
  20. (goto-char (point-min))
  21. (forward-line 1)
  22. (when (looking-at nix-shebang-interpreter-regexp)
  23. (match-string 1))))
  24. (defun nix-shebang-mode ()
  25. "Detect and run file’s interpreter mode."
  26. (let ((mode (nix-shebang-get-interpreter)))
  27. (when mode
  28. (funcall (assoc-default mode
  29. (mapcar (lambda (e)
  30. (cons
  31. (format "\\`%s\\'" (car e))
  32. (cdr e)))
  33. interpreter-mode-alist)
  34. #'string-match-p)))))
  35. (provide 'nix-shebang)
  36. ;;; nix-shebang.el ends here