branch: elpa/nix-mode commit c8f33e586917262359d32cbe1a6726b168a6010a Author: Daniel Nagy <danieln...@posteo.de> Commit: Daniel Nagy <danieln...@posteo.de>
Differentiate realised/unrealised store paths * propertize store-paths with their respective face --- nix-mode.el | 14 ++++++++++++++ nix-store.el | 34 ++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 12 deletions(-) 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))))))