branch: elpa/nix-mode commit 34d51e2731408b5b615f785a83faa3d6dc2a92a1 Merge: b3f71c75f7 e1f3af50bc Author: Matthew Bauer <mjbaue...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #165 from nagy/store-realization Differentiate between realised and unrealised store paths --- nix-flake.el | 6 ++++-- nix-mode.el | 14 ++++++++++++++ nix-store.el | 34 ++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/nix-flake.el b/nix-flake.el index b0c11397fa..d40d96e07e 100644 --- a/nix-flake.el +++ b/nix-flake.el @@ -2,6 +2,8 @@ ;; Keywords: nix, languages, tools, unix ;; Package-Requires: ((emacs "27.1") (transient "0.3")) +;; Homepage: https://github.com/NixOS/nix-mode +;; Version: 1.4.4 ;;; Commentary: @@ -15,7 +17,7 @@ (require 'transient) (defgroup nix-flake nil - "Nix flake commands" + "Nix flake commands." :group 'nix) ;;;; Custom variables @@ -23,7 +25,7 @@ (defcustom nix-flake-init-post-action 'open-flake-nix "Action to run after successfully initializing a flake. -This action is run after a flake is successlly initialized by +This action is run after a flake is successfully initialized by `nix-flake-init` (or generally `nix-flake-dispatch`). You can also specify a function, which should take no arguments. diff --git a/nix-mode.el b/nix-mode.el index 59ca5a2101..9a67544ed2 100644 --- a/nix-mode.el +++ b/nix-mode.el @@ -81,6 +81,20 @@ very large Nix files (all-packages.nix)." "Face used to highlight Nix antiquotes." :group 'nix-faces) +(defface nix-store-path-face nil + "Face used to highlight Nix store paths." + :group 'nix-faces) + +(defface nix-store-path-realised-face + '((t :inherit 'nix-store-path-face)) + "Face used to highlight realised Nix store paths." + :group 'nix-faces) + +(defface nix-store-path-unrealised-face + '((t :inherit 'nix-store-path-face)) + "Face used to highlight unrealised Nix store paths." + :group 'nix-faces) + ;;; Constants (defconst nix-system-types diff --git a/nix-store.el b/nix-store.el index a05f1d34ec..d633031393 100644 --- a/nix-store.el +++ b/nix-store.el @@ -34,15 +34,15 @@ PATH the path within /nix/store to realise" (defvar-local nix-buffer-store-path nil "Buffer-local object holding an `nix-store-path` object.") (defclass nix-store-path () - ((path :initarg :path :accessor nix-store-path-path) - (status :initarg :status :initform 'realised :accessor nix-store-path-status) - (hash :initarg :hash :accessor nix-store-path-hash) - (size :initarg :size :accessor nix-store-path-size) - (derivers :initarg :derivers :accessor nix-store-path-derivers) - (outputs :initarg :outputs :accessor nix-store-path-outputs) - (references :initarg :references :accessor nix-store-path-references) - (referrers :initarg :referrers :accessor nix-store-path-referrers) - (requisites :initarg :requisites :accessor nix-store-path-requisites)) + ((path :initarg :path :accessor nix-store-path-path) + (status :initarg :status :accessor nix-store-path-status) + (hash :initarg :hash :accessor nix-store-path-hash) + (size :initarg :size :accessor nix-store-path-size) + (derivers :initarg :derivers :accessor nix-store-path-derivers) + (outputs :initarg :outputs :accessor nix-store-path-outputs) + (references :initarg :references :accessor nix-store-path-references) + (referrers :initarg :referrers :accessor nix-store-path-referrers) + (requisites :initarg :requisites :accessor nix-store-path-requisites)) "Nix-Store-Path Class holds all information of the path that is displayed") @@ -55,6 +55,7 @@ is displayed") (oset object :referrers (nix-store--query 'referrers (nix-store-path-path object))) (oset object :requisites (nix-store--query 'requisites (nix-store-path-path object))) (oset object :references (nix-store--query 'references (nix-store-path-path object))) + (oset object :status (file-exists-p (car (nix-store-path-outputs object)))) object) (cl-defun nix-store--query (argument &optional (path (nix-store-path-path nix-buffer-store-path))) @@ -85,7 +86,10 @@ information." "Insert a section showing the path of STORE-PATH." (magit-insert-section (path (nix-store-path-path store-path)) (magit-insert-heading (propertize (format "%-11s" "Path:") 'face 'magit-section-heading) - (format "%s" (oref store-path path))))) + (propertize (oref store-path path) + 'face (if (file-exists-p (nix-store-path-path store-path)) + 'nix-store-path-realised-face + 'nix-store-path-unrealised-face) )))) (cl-defun nix-store-path-insert-size (&optional (store-path nix-buffer-store-path)) "Insert a section showing the size of STORE-PATH." @@ -103,7 +107,7 @@ information." "Insert a section showing the status of STORE-PATH." (magit-insert-section (status (nix-store-path-status store-path)) (magit-insert-heading (propertize (format "%-11s" "Status:") 'face 'magit-section-heading) - (format "%s" (oref store-path status))))) + (if (nix-store-path-status store-path) "realised" "unrealised")))) (defmacro nix-store--magit-insert-section-list (type value label) "Helper macro for inserting a list as a magit-section. @@ -113,7 +117,13 @@ respectively. The LABEL is the text displayed." (when (and (listp value) (> (length value) 0)) (magit-insert-section (,type value) (magit-insert-heading ,label) - (cl-loop for x in value do (magit-insert-section (store-path x) (insert x) (newline))) + (cl-loop for x in value + for exists = (file-exists-p x) + do + (magit-insert-section (store-path x) + (insert + (propertize x 'face (if exists 'nix-store-path-realised-face 'nix-store-path-unrealised-face)) + ?\n))) (insert ?\n) (magit-insert-child-count (magit-current-section))))))