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

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

[elpa] externals/buffer-env 033f04fd27 10/12: Command to display the pro


From: ELPA Syncer
Subject: [elpa] externals/buffer-env 033f04fd27 10/12: Command to display the process environment
Date: Mon, 28 Feb 2022 15:57:26 -0500 (EST)

branch: externals/buffer-env
commit 033f04fd27ae3207c851b23a797a2a718763b0a4
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>

    Command to display the process environment
---
 buffer-env.el | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/buffer-env.el b/buffer-env.el
index 808114d1bf..87299fe4ac 100644
--- a/buffer-env.el
+++ b/buffer-env.el
@@ -162,5 +162,47 @@ When called interactively, ask for a FILE."
   (kill-local-variable 'process-environment)
   (kill-local-variable 'exec-path))
 
+(defun buffer-env--sorted (vars)
+  "Sort and remove duplicates in the list of environment VARS."
+  (let ((testfn (lambda (x y)
+                  (string= (progn (string-match "[^=]*" x)
+                                  (match-string 0 x))
+                           (progn (string-match "[^=]*" y)
+                                  (match-string 0 y))))))
+    (sort (seq-uniq vars testfn) 'string<)))
+
+(defun buffer-env-inspect ()
+  "Compare buffer-local and global process environments."
+  (interactive)
+  (if (not (local-variable-p 'process-environment))
+      (message "Buffer has the default process environment")
+    (let ((name (buffer-name (current-buffer)))
+          (script buffer-env-active)
+          (local (buffer-env--sorted process-environment))
+          (global (buffer-env--sorted (default-toplevel-value 
'process-environment)))
+          (buffer (get-buffer-create "*buffer-env*"))
+          (inhibit-read-only t))
+      (with-current-buffer buffer
+        (special-mode)
+        (erase-buffer)
+        (insert "The process environment of buffer ‘" name
+                "’ was generated by the script ‘" (or script "??") "’.")
+        (fill-paragraph)
+        (insert "\n\nOnly in the local process environment:\n\n")
+        (add-face-text-property (line-beginning-position -2) (point) 'bold)
+        (if-let ((vars (seq-difference local global)))
+            (dolist (var vars) (insert var ?\n))
+          (insert "(None)"))
+        (insert "\nOnly in the global process environment:\n\n")
+        (add-face-text-property (line-beginning-position -2) (point) 'bold)
+        (if-let ((vars (seq-difference global local)))
+            (dolist (var vars) (insert var ?\n))
+          (insert "(None)"))
+        (insert "\nComplete process environment of the buffer:\n\n")
+        (add-face-text-property (line-beginning-position -2) (point) 'bold)
+        (dolist (var local) (insert var ?\n))
+        (goto-char (point-min)))
+      (display-buffer buffer))))
+
 (provide 'buffer-env)
 ;;; buffer-env.el ends here



reply via email to

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