[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/buffer-env 4ed60c9fee 03/12: Add a separate buffer-env-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/buffer-env 4ed60c9fee 03/12: Add a separate buffer-env--locate-script function |
Date: |
Mon, 28 Feb 2022 15:57:26 -0500 (EST) |
branch: externals/buffer-env
commit 4ed60c9feeaeec712f4c0fbc323a67efd45f673a
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>
Add a separate buffer-env--locate-script function
---
buffer-env.el | 66 ++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 43 insertions(+), 23 deletions(-)
diff --git a/buffer-env.el b/buffer-env.el
index 0db5d82cd5..1e2228f82c 100644
--- a/buffer-env.el
+++ b/buffer-env.el
@@ -95,7 +95,7 @@ content."
"List of additional `exec-path' entries."
:type '(string))
-(defun buffer-env-authorize (file)
+(defun buffer-env--authorize (file)
"Check if FILE is safe to execute, or ask for permission.
Files marked as safe to execute are permanently stored in
`buffer-env-safe-files' via the Custom mechanism."
@@ -109,29 +109,46 @@ Files marked as safe to execute are permanently stored in
(push (cons file hash)
buffer-env-safe-files))))))
-;;;###autoload
-(defun buffer-env-update ()
- "Update the environment variables buffer locally.
-This function searches for a file named `buffer-env-file' in the
-current directory and its parents, executes it in a shell, and
-then sets `process-environment' and `exec-path' buffer-locally to
-match the shell environment."
- (interactive)
- (when-let* ((dir (and (stringp buffer-env-file)
+(defun buffer-env--locate-script ()
+ (when-let* ((dir (and (stringp buffer-env-script-name)
(not (file-remote-p default-directory))
(locate-dominating-file default-directory
- buffer-env-file)))
- (file (expand-file-name buffer-env-file dir))
- ((file-readable-p file))
- ((buffer-env-authorize file))
- (out (with-temp-buffer
- (setq default-directory dir)
- (call-process shell-file-name nil t nil
- shell-command-switch
- buffer-env-command
- file)
- (buffer-substring (point-min) (point-max))))
- (vars (split-string out (string 0) t)))
+ buffer-env-script-name))))
+ (expand-file-name buffer-env-script-name dir)))
+
+;;;###autoload
+(defun buffer-env-update (&optional file)
+ "Update the process environment buffer locally.
+This function executes FILE in a shell, collects the exported
+variables (see `buffer-env-command' for details), and then sets
+the buffer-local values of `process-environment' and `exec-path'
+accordingly.
+
+If FILE omitted, a file with base name `buffer-env-script-name'
+is looked up in the current directory and its parents; nothing
+happens if no such file is found. This makes this function
+suitable for use in a normal hook.
+
+When called interactively, ask for a FILE."
+ (interactive (list (let ((file (buffer-env--locate-script)))
+ (read-file-name "Environment script: "
+ file file t))))
+ (when-let* ((file (if file
+ (expand-file-name file)
+ (buffer-env--locate-script)))
+ ((buffer-env--authorize file))
+ (vars (with-temp-buffer
+ (let* ((default-directory (file-name-directory file))
+ (status (call-process shell-file-name nil t nil
+ shell-command-switch
+ buffer-env-command
+ file)))
+ (if (eq 0 status)
+ (split-string (buffer-substring (point-min)
(point-max))
+ (string 0) t)
+ (prog1 nil
+ (message "[buffer-env] Error in `%s', exit status
%s"
+ file status)))))))
(setq-local process-environment buffer-env-extra-variables)
(dolist (var vars)
(unless (seq-contains-p buffer-env-ignored-variables
@@ -140,7 +157,10 @@ match the shell environment."
(setq process-environment (cons var process-environment))))
(when-let* ((path (getenv "PATH")))
(setq-local exec-path (append (split-string path path-separator)
- buffer-env-extra-exec-path)))))
+ buffer-env-extra-exec-path)))
+ (message "[buffer-env] Environment of buffer `%s' set from `%s'"
+ (buffer-name)
+ file)))
(provide 'buffer-env)
;;; buffer-env.el ends here
- [elpa] branch externals/buffer-env created (now dc7342277f), ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env a12a914cd5 05/12: No message for hidden buffers, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 32c1cfdf06 08/12: Add a Readme, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 564c3679c8 11/12: Add mode line indicator and make messages optional, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 4ed60c9fee 03/12: Add a separate buffer-env--locate-script function,
ELPA Syncer <=
- [elpa] externals/buffer-env eb4cf91f7b 02/12: Refinements in defcustoms, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 3568a9f426 01/12: Initial commit, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 5f4e2258ff 04/12: Add buffer-env-reset, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env f05d5bd1e7 07/12: Fix checkdoc and package-lint issues, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env 033f04fd27 10/12: Command to display the process environment, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env ed0a4b31ce 06/12: Some simplifications, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env f3781a628a 09/12: Update README, ELPA Syncer, 2022/02/28
- [elpa] externals/buffer-env dc7342277f 12/12: Release on ELPA, ELPA Syncer, 2022/02/28