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

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

[elpa] externals/buffer-env e2802e1c20 2/5: Refactoring


From: ELPA Syncer
Subject: [elpa] externals/buffer-env e2802e1c20 2/5: Refactoring
Date: Mon, 6 Jun 2022 09:57:18 -0400 (EDT)

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

    Refactoring
---
 buffer-env.el | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/buffer-env.el b/buffer-env.el
index 46dbce6aa3..93555b4630 100644
--- a/buffer-env.el
+++ b/buffer-env.el
@@ -125,7 +125,7 @@ mouse-2: Reset to default process environment"
                                       (mouse-1 . buffer-env-describe)
                                       (mouse-2 . buffer-env-reset))))))
 
-(defvar buffer-env-cache-alist nil
+(defvar buffer-env--cache nil
   "List of cache entries, to accelerate `buffer-env-update'.
 Each entry has the form (FILENAME TIMESTAMP PROCESS-ENVIRONMENT
 EXEC-PATH).")
@@ -178,20 +178,20 @@ When called interactively, ask for a FILE."
            (read-file-name (format-prompt "Environment script"
                                           (when file (file-relative-name 
file)))
                            nil file t))))
-  (when-let* ((file (if file
-                        (expand-file-name file)
-                      (buffer-env--locate-script)))
-              ((buffer-env--authorize file))
-              (attr (file-attributes file))
-              (modtime (file-attribute-modification-time attr)))
-    (if-let ((cache (assoc file buffer-env-cache-alist #'file-equal-p))
+  (when-let ((file (if file
+                       (expand-file-name file)
+                     (buffer-env--locate-script)))
+             ((buffer-env--authorize file))
+             (modtime (file-attribute-modification-time (file-attributes 
file))))
+    (if-let ((cache (assoc file buffer-env--cache #'file-equal-p))
             ((time-equal-p (nth 1 cache) modtime)))
         (progn
-          (setq-local process-environment (nth 2 cache)
-                      exec-path (nth 3 cache))
           (when buffer-env-verbose
-            (message "[buffer-env] Cached environment of `%s' set from `%s'"
-                     (current-buffer) file)))
+            (message "[buffer-env] Environment of `%s' set from `%s' using 
cache"
+                     (current-buffer) file))
+          (setq-local process-environment (nth 2 cache)
+                      exec-path (nth 3 cache)
+                      buffer-env-active file))
       (when-let ((command (seq-some (pcase-lambda (`(,patt . ,command))
                                       (when (string-match-p 
(wildcard-to-regexp patt)
                                                             
(file-name-nondirectory file))
@@ -204,7 +204,7 @@ When called interactively, ask for a FILE."
                          (let* ((default-directory (file-name-directory file))
                                 (message-log-max nil)
                                 (proc (make-process
-                                       :name " *buffer-env*"
+                                       :name "buffer-env"
                                        :command (list shell-file-name
                                                       shell-command-switch
                                                       command file)
@@ -220,11 +220,11 @@ When called interactively, ask for a FILE."
                                  (progress-reporter-update reporter))
                                (progress-reporter-done reporter)))
                            (if (= (process-exit-status proc) 0)
-                               (split-string (buffer-substring (point-min) 
(point-max))
-                                             "\0" t)
+                               (split-string (buffer-substring (point-min) 
(point-max)) "\0" t)
                              (message "[buffer-env] Error in `%s', exit status 
%s.\
  See \" *buffer-env*\" for details."
                                       file (process-exit-status proc))
+                             (buffer-env-reset)
                              nil)))))
         (setq-local process-environment
                     (nconc (seq-remove (lambda (var)
@@ -236,11 +236,11 @@ When called interactively, ask for a FILE."
           (setq-local exec-path (nconc (split-string path path-separator)
                                        (list exec-directory))))
         (push (list file modtime process-environment exec-path)
-              buffer-env-cache-alist)
+              buffer-env--cache)
         (when buffer-env-verbose
           (message "[buffer-env] Environment of `%s' set from `%s'"
-                   (current-buffer) file))))
-    (setq buffer-env-active file)))
+                   (current-buffer) file))
+        (setq buffer-env-active file)))))
 
 ;;;###autoload
 (defun buffer-env-reset ()



reply via email to

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