From 40417cb37ad7b4d088d68773d21e8cc8d6f1a5d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:26 -0300 Subject: [PATCH] Enhancements on `python-shell-calculate-process-environment' and `python-shell-calculate-exec-path' Removed functions: + python-util-merge --- lisp/progmodes/python.el | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 05e999a6bef..28b5eeaa33f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1231,27 +1231,24 @@ uniqueness for different types of configurations." (defun python-shell-calculate-process-environment () "Calculate process environment given `python-shell-virtualenv-path'." - (let ((env (python-util-merge 'list python-shell-process-environment - process-environment 'string=)) + (let ((process-environment (append + python-shell-process-environment + process-environment nil)) (virtualenv (if python-shell-virtualenv-path (directory-file-name python-shell-virtualenv-path) nil))) (if (not virtualenv) - env - (dolist (envvar env) - (let* ((split (split-string envvar "=" t)) - (name (nth 0 split)) - (value (nth 1 split))) - (when (not (string= name "PYTHONHOME")) - (when (string= name "PATH") - (setq value (format "%s/bin:%s" virtualenv value))) - (setq env (cons (format "%s=%s" name value) env))))) - (cons (format "VIRTUAL_ENV=%s" virtualenv) env)))) + process-environment + (setenv "PYTHONHOME" nil) + (setenv "PATH" (format "%s/bin%s%s" + virtualenv path-separator (getenv "PATH"))) + (setenv "VIRTUAL_ENV" virtualenv)) + process-environment)) (defun python-shell-calculate-exec-path () "Calculate exec path given `python-shell-virtualenv-path'." - (let ((path (python-util-merge 'list python-shell-exec-path - exec-path 'string=))) + (let ((path (append python-shell-exec-path + exec-path nil))) (if (not python-shell-virtualenv-path) path (cons (format "%s/bin" @@ -2471,19 +2468,6 @@ The type returned can be 'comment, 'string or 'paren." ;;; Utility functions -;; Stolen from GNUS -(defun python-util-merge (type list1 list2 pred) - "Destructively merge lists to produce a new one. -Argument TYPE is for compatibility and ignored. LIST1 and LIST2 -are the list to be merged. Ordering of the elements is preserved -according to PRED, a `less-than' predicate on the elements." - (let ((res nil)) - (while (and list1 list2) - (if (funcall pred (car list2) (car list1)) - (push (pop list2) res) - (push (pop list1) res))) - (nconc (nreverse res) list1 list2))) - (defun python-util-position (item seq) "Find the first occurrence of ITEM in SEQ. Return the index of the matching item, or nil if not found." -- 2.39.2