emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/nix-mode 420cbbf94c 215/500: Reorganization


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 420cbbf94c 215/500: Reorganization
Date: Sat, 29 Jan 2022 08:27:08 -0500 (EST)

branch: elpa/nix-mode
commit 420cbbf94c9abac9f8277e4cb3c04cb7f171d101
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>

    Reorganization
    
    Move around some files. Add ‘nix.el’ that is now the main entry point
    to configurations. If you want the full experience of Nix integration
    into Emacs, try running this (if you are already using use-package):
    
      (use-package 'nix
        :ensure 'nix-mode
        :demand
        :config (global-nix-mode))
    
    Otherwise you can still do something like this:
    
      (use-package 'nix-mode
        :mode "\\.nix\\'"))
---
 nix-company.el  |   4 ---
 nix-drv-mode.el |  45 ++++++++++++++++++++++++
 nix-mode.el     |  34 ++++--------------
 nix-repl.el     |   7 ++--
 nix-shebang.el  |   4 ---
 nix-shell.el    |  59 -------------------------------
 nix.el          | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 161 insertions(+), 99 deletions(-)

diff --git a/nix-company.el b/nix-company.el
index 9cc0648cf1..3c6abf0ab6 100644
--- a/nix-company.el
+++ b/nix-company.el
@@ -69,9 +69,5 @@ BUFFER check for Nix-REPL in current buffer"
                (setq nix--company-last-buffer (buffer-name))))
       backend-buf)))
 
-;; install nix-company
-(add-hook 'nix-mode-hook (lambda ()
-                           (setq-local company-backends '(company-nix))))
-
 (provide 'nix-company)
 ;;; nix-company.el ends here
diff --git a/nix-drv-mode.el b/nix-drv-mode.el
new file mode 100644
index 0000000000..a0eb60c0f4
--- /dev/null
+++ b/nix-drv-mode.el
@@ -0,0 +1,45 @@
+;;; nix-drv-mode.el --- Major mode for viewing .drv files
+
+;; Maintainer: Matthew Bauer <mjbauer95@gmail.com>
+;; Homepage: https://github.com/NixOS/nix-mode
+;; Version: 1.2.1
+;; Keywords: nix, languages, tools, unix
+;; Package-Requires: ((emacs "24.3"))
+
+;; This file is NOT part of GNU Emacs.
+
+;;; Commentary:
+
+;; A major mode for viewing Nix derivations (.drv files). See the Nix
+;; manual for more information available at
+;; https://nixos.org/nix/manual/.
+
+;;; Code:
+
+(require 'json-mode)
+(require 'nix)
+
+(defvar-local nix-drv-mode nil)
+
+;;;###autoload
+(defun nix-drv-mode ()
+  "Pretty print Nix’s .drv files."
+  (interactive)
+  (let ((inhibit-read-only t))
+    (if nix-drv-mode
+        (progn
+          (erase-buffer)
+          (insert-file-contents (buffer-file-name))
+          (setq nix-drv-mode nil))
+      (setq nix-drv-mode t)
+      (erase-buffer)
+      (insert (shell-command-to-string
+               (format "%s show-derivation \"%s\""
+                      nix-executable
+                      (buffer-file-name))))
+      (json-mode))
+    (set-buffer-modified-p nil)
+    (read-only-mode 1)))
+
+(provide 'nix-drv-mode)
+;;; nix-drv-mode.el ends here
diff --git a/nix-mode.el b/nix-mode.el
index 21429fa5a9..1b25d091ad 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -15,12 +15,12 @@
 
 ;;; Code:
 
+(require 'nix)
 (require 'nix-format)
-(require 'nix-shebang)
 
-(defgroup nix nil
-  "Nix-related customizations"
-  :group 'languages)
+(defgroup nix-mode nil
+  "Nix mode customizations"
+  :group 'nix)
 
 (defcustom nix-indent-function 'indent-relative
   "The function to use to indent.
@@ -29,16 +29,12 @@ Valid functions for this are:
 
 - indent-relative
 - nix-indent-line (buggy)"
-  :group 'nix
+  :group 'nix-mode
   :type 'function)
 
-(defgroup nix-mode nil
-  "Nix mode customizations"
-  :group 'nix)
-
 (defgroup nix-faces nil
   "Nix faces."
-  :group 'nix
+  :group 'nix-mode
   :group 'faces)
 
 (defface nix-keyword-face
@@ -438,7 +434,7 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
 
 (defun nix-create-keymap ()
   "Create the keymap associated with the Nix mode."
-  (define-key nix-mode-map "\C-c\C-r" 'nix-format-buffer))
+  )
 
 (defun nix-create-menu ()
   "Create the Nix menu as shown in the menu bar."
@@ -450,17 +446,6 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
 (nix-create-keymap)
 (nix-create-menu)
 
-;;;###autoload
-(defun nix-build (&optional attr dir)
-  "Run nix-build.
-ATTR is the attribute to build.
-DIR is the directory containing the Nix default.nix expression."
-  (interactive)
-  (unless dir (setq dir default-directory))
-  (if attr
-      (async-shell-command (format "nix-build %s -A %s" dir attr))
-    (async-shell-command (format "nix-build %s" dir))))
-
 ;;;###autoload
 (define-derived-mode nix-mode prog-mode "Nix"
   "Major mode for editing Nix expressions.
@@ -518,10 +503,5 @@ The hook `nix-mode-hook' is run when Nix mode is started.
 
   (easy-menu-add nix-mode-menu nix-mode-map))
 
-;;;###autoload
-(progn
-  (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
-  (add-to-list 'auto-mode-alist '("\\.nix.in\\'" . nix-mode)))
-
 (provide 'nix-mode)
 ;;; nix-mode.el ends here
diff --git a/nix-repl.el b/nix-repl.el
index e8962806cd..036b697e9f 100644
--- a/nix-repl.el
+++ b/nix-repl.el
@@ -9,15 +9,12 @@
 (defvar nix-prompt-regexp "nix-repl> ")
 
 (require 'comint)
+(require 'nix)
 
 (defgroup nix-repl nil
   "nix-repl customizations"
   :group 'nix)
 
-(defcustom nix-repl-executable "nix"
-  "Location of nix-repl command."
-  :type 'string)
-
 (defcustom nix-repl-executable-args '("repl")
   "Arguments to provide to nix-repl."
   :type 'list)
@@ -53,7 +50,7 @@
   "Make Nix Repl in BUFFER."
   (apply
    'make-comint-in-buffer
-   (append `("Nix-REPL" ,buffer ,nix-repl-executable nil)
+   (append `("Nix-REPL" ,buffer ,nix-executable nil)
            nix-repl-executable-args)))
 
 (defun nix-get-completions (proc prefix)
diff --git a/nix-shebang.el b/nix-shebang.el
index 0edf939a5b..08cc1629dd 100644
--- a/nix-shebang.el
+++ b/nix-shebang.el
@@ -43,9 +43,5 @@
                                       interpreter-mode-alist)
                               #'string-match-p)))))
 
-;; WARNING: this will automatically modify interpreter-mode-alist
-;; ideally we could make this opt-in
-(add-to-list 'interpreter-mode-alist '("nix-shell" . nix-shebang-mode))
-
 (provide 'nix-shebang)
 ;;; nix-shebang.el ends here
diff --git a/nix-shell.el b/nix-shell.el
deleted file mode 100644
index ca3dec72d2..0000000000
--- a/nix-shell.el
+++ /dev/null
@@ -1,59 +0,0 @@
-;;; nix-shell.el -- run nix-shell in Emacs -*- lexical-binding: t -*-
-
-;; Author: Matthew Bauer <mjbauer95@gmail.com>
-;; Homepage: https://github.com/NixOS/nix-mode
-;; Keywords: nix
-
-;; This file is NOT part of GNU Emacs.
-
-;;; Commentary:
-
-;; To use this just run:
-
-;; M-x RET nix-shell RET
-
-;; This will give you some
-
-;;; Code:
-
-;; (require 'nix-mode)
-(require 'term)
-
-(defgroup nix-shell nil
-  "Customizations for nix-shell"
-  :group 'nix)
-
-(defcustom nix-shell-executable "nix-shell"
-  "Location of ‘nix-shell’ executable."
-  :group 'nix-shell
-  :type 'string)
-
-;;;###autoload
-(defun nix-shell (path attribute)
-  "Run ‘nix-shell’ in a terminal.
-
-PATH path containing Nix expressions.
-ATTRIBUTE attribute name in nixpkgs to use."
-  (interactive
-   (list (read-from-minibuffer "Nix path: " "<nixpkgs>")
-         (read-from-minibuffer "Nix attribute name: ")))
-  (set-buffer (make-term "nix-shell" nix-shell-executable nil
-                         path "-A" attribute))
-  (term-mode)
-  (term-char-mode)
-  (switch-to-buffer "*nix-shell*"))
-
-;;;###autoload
-(defun nix-unpack (path attribute)
-  "Get source from a Nix derivation.
-
-PATH used for base of Nix expresions.
-
-ATTRIBUTE from PATH to get Nix expressions from."
-  (interactive (list (read-string "Nix path: " "<nixpkgs>")
-                                        (read-string "Nix attribute name: ")))
-  (async-shell-command (format "%s '%s' -A '%s' --run unpackPhase"
-                                                          nix-shell-executable 
path attribute)))
-
-(provide 'nix-shell)
-;;; nix-shell.el ends here
diff --git a/nix.el b/nix.el
new file mode 100644
index 0000000000..f6215b5be2
--- /dev/null
+++ b/nix.el
@@ -0,0 +1,107 @@
+;;; nix.el -- run nix commands in Emacs -*- lexical-binding: t -*-
+
+;; Author: Matthew Bauer <mjbauer95@gmail.com>
+;; Homepage: https://github.com/NixOS/nix-mode
+;; Keywords: nix
+
+;; This file is NOT part of GNU Emacs.
+
+;;; Commentary:
+
+;; To use this just run:
+
+;; M-x RET nix-shell RET
+
+;; This will give you some
+
+;;; Code:
+
+(require 'term)
+
+(require 'nix-mode)
+(require 'nix-shebang)
+(require 'nix-company)
+
+(defgroup nix nil
+  "Nix-related customizations"
+  :group 'languages)
+
+(defcustom nix-executable "nix"
+  "Nix executable location."
+  :group 'nix)
+
+(defcustom nix-build-executable "nix-build"
+  "Nix-build executable location."
+  :group 'nix)
+
+(defcustom nix-instantiate-executable "nix-instantiate"
+  "Nix executable location."
+  :group 'nix)
+
+(defcustom nix-store-executable "nix-store"
+  "Nix executable location."
+  :group 'nix)
+
+(defcustom nix-shell-executable "nix-shell"
+  "Location of ‘nix-shell’ executable."
+  :group 'nix
+  :type 'string)
+
+;;;###autoload
+(defun nix-build (&optional attr dir)
+  "Run nix-build.
+ATTR is the attribute to build.
+DIR is the directory containing the Nix default.nix expression."
+  (interactive)
+  (unless dir (setq dir default-directory))
+  (if attr
+      (async-shell-command (format "%s %s -A %s" nix-build-executable dir 
attr))
+    (async-shell-command (format "%s %s" nix-build-executable dir))))
+
+
+;;;###autoload
+(defun nix-shell (path attribute)
+  "Run ‘nix-shell’ in a terminal.
+
+PATH path containing Nix expressions.
+ATTRIBUTE attribute name in nixpkgs to use."
+  (interactive
+   (list (read-from-minibuffer "Nix path: " "<nixpkgs>")
+         (read-from-minibuffer "Nix attribute name: ")))
+  (set-buffer (make-term "nix-shell" nix-shell-executable nil
+                         path "-A" attribute))
+  (term-mode)
+  (term-char-mode)
+  (switch-to-buffer "*nix-shell*"))
+
+;;;###autoload
+(defun nix-unpack (path attribute)
+  "Get source from a Nix derivation.
+
+PATH used for base of Nix expresions.
+
+ATTRIBUTE from PATH to get Nix expressions from."
+  (interactive (list (read-string "Nix path: " "<nixpkgs>")
+                    (read-string "Nix attribute name: ")))
+  (async-shell-command (format "%s '%s' -A '%s' --run unpackPhase"
+                              nix-shell-executable
+                              path attribute)))
+
+
+;;;###autoload
+(define-minor-mode global-nix-mode
+  "Minor mode to enable Nix enhancements."
+  :require 'nix
+  :global t
+  (cond
+   (global-nix-mode
+    (add-to-list 'interpreter-mode-alist '("nix-shell" . nix-shebang-mode))
+    (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
+    (add-to-list 'auto-mode-alist '("\\.drv\\'" . nix-drv-mode))
+    (add-hook 'nix-mode-hook (lambda () (setq-local company-backends 
'(company-nix))))
+    )
+   (t
+    ())))
+
+(provide 'nix)
+;;; nix.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]