Resolve major mode for (cached)-nix-shell scripts
This commit is contained in:
parent
014385a9f6
commit
49c7cf8172
2 changed files with 23 additions and 0 deletions
|
@ -39,3 +39,24 @@
|
|||
((user-error "No search engine is enabled. Enable helm or ivy!")))
|
||||
;; Tell lookup module to let us handle things from here
|
||||
'deferred)
|
||||
|
||||
;;;###autoload
|
||||
(defun +nix-shell-init-mode ()
|
||||
"Resolve a (cached-)?nix-shell shebang to the correct major mode."
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(save-match-data
|
||||
(when (re-search-forward "#! *\\(?:cached-\\)?nix-shell +-i +\\([^ \n]+\\)" 256 t)
|
||||
(let* ((interp (match-string 1))
|
||||
(mode
|
||||
(assoc-default
|
||||
interp
|
||||
(mapcar (lambda (e)
|
||||
(cons (format "\\`%s\\'" (car e))
|
||||
(cdr e)))
|
||||
interpreter-mode-alist)
|
||||
#'string-match-p)))
|
||||
(when mode
|
||||
(prog1 (set-auto-mode-0 mode)
|
||||
(when (eq major-mode 'sh-mode)
|
||||
(sh-set-shell interp)))))))))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
;;; lang/nix/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! nix-mode
|
||||
:interpreter ("cached-nix-shell" . +nix-shell-init-mode)
|
||||
:interpreter ("nix-shell" . +nix-shell-init-mode)
|
||||
:mode "\\.nix\\'"
|
||||
:config
|
||||
(set-company-backend! 'nix-mode 'company-nixos-options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue