Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial check-in

  • Loading branch information...
commit 39aca32dda87b843ec9deb53c7c6c5bb0f2458ef 0 parents
@purcell authored
Showing with 87 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +86 −0 exec-path-from-shell.el
1  .gitignore
@@ -0,0 +1 @@
+/exec-path-from-shell.elc
86 exec-path-from-shell.el
@@ -0,0 +1,86 @@
+;;; exec-path-from-shell.el --- Make Emacs use the $PATH set up by the user's shell
+
+;; Copyright (C) 2012 Steve Purcell
+
+;; Author: Steve Purcell <steve@sanityinc.com>
+;; Keywords: environment
+;; URL: https://github.com/purcell/exec-path-from-shell
+;; Version: DEV
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; On OS X (and perhaps elsewhere) the $PATH environment variable and
+;; `exec-path' used by a windowed Emacs instance will usually be the
+;; system-wide default path, rather than that seen in a terminal
+;; window.
+
+;; This library allows the user to set Emacs' `exec-path' and $PATH
+;; from the shell path, so that `shell-command', `compile' and the
+;; like work as expected.
+
+;; Installation:
+
+;; ELPA packages are available on Marmalade and Melpa. Alternatively, place
+;; this file on a directory in your `load-path', and explicitly require it.
+
+;; Usage:
+;;
+;; (require 'exec-path-from-shell) ;; if not using the ELPA package
+;; (exec-path-from-shell-initialize)
+;;
+;; If you use your Emacs config on other platforms, you can instead
+;; make initialization conditional as follows:
+;;
+;; (when (and window-system (eq system-type 'darwin))

Isn't the following equivalent and more efficient, because the form is really only evaluated if running in a window on OS X?

(eval-after-load 'ns-win #'(exec-path-from-shell-initialize))
@purcell Owner
purcell added a note

Neat. There's no library called "ns-win" in Emacs 24, though, so even if it works for you on a different version of Emacs, I don't think that expression is quite as general.

I'm also not sure if efficiency is really a concern in this case. :-)

-Steve

@purcell I have ns-win in my homebrewed Emacs 24.2.

@purcell Owner
purcell added a note

Then you're very lucky! ;-)

I don't have it in my recently-built-from-source Emacs 24.2.4.

In the meantime, I've changed the suggested conditional to:

 (when (memq window-system '(ns mac))
   (exec-path-from-shell-initialize))

@purcell Interesting… what library provides mac-option-modifier and friends then?

@purcell Owner
purcell added a note

Ah - it's there, but not on the load-path, so M-x find-library can't find it. And the eval-after-load block doesn't seem to trigger for that library either.

In any case, that file is not present in the Carbon flavour of Emacs, so its presence is not a universal indicator of a Mac window system.

@purcell I'll use your conditional then. But I doubt that anyone is still using Carbon Emacs ;)

@purcell Owner
purcell added a note

I hope they're not, but you never know... :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+;; (exec-path-from-shell-initialize))
+;;
+;; To copy the values of other environment variables, you can use
+;; `exec-path-from-shell-copy-env', e.g.
+;;
+;; (exec-path-from-shell-copy-env "PYTHONPATH")
+
+;;; Code:
+
+(defun exec-path-from-shell-getenv (name)
+ (replace-regexp-in-string
+ "[ \t\n]*$" ""
+ (shell-command-to-string (format "$SHELL --login -i -c 'echo $%s'" name))))
+
+(defun exec-path-from-shell-copy-env (name)
+ "Set the environment variable with `NAME' to match the value seen in the user's shell."
+ (interactive "sCopy value of which environment variable from shell? ")
+ (setenv name (exec-path-from-shell-getenv name)))
+
+(defun exec-path-from-shell-initialize ()
+ "Set the PATH environment variable and `exec-path' to match that seen in the user's shell."
+ (interactive)
+ (let ((path-from-shell (exec-path-from-shell-getenv "PATH")))
+ (setenv "PATH" path-from-shell)
+ (setq exec-path (split-string path-from-shell path-separator))))
+
+
+(provide 'exec-path-from-shell)
+
+;; Local Variables:
+;; coding: utf-8
+;; indent-tabs-mode: nil
+;; mangle-whitespace: t
+;; require-final-newline: t;; eval: (checkdoc-minor-mode 1)
+;; End:
+
+;;; exec-path-from-shell.el ends here
@lunaryorn

Isn't the following equivalent and more efficient, because the form is really only evaluated if running in a window on OS X?

(eval-after-load 'ns-win #'(exec-path-from-shell-initialize))
@purcell

Neat. There's no library called "ns-win" in Emacs 24, though, so even if it works for you on a different version of Emacs, I don't think that expression is quite as general.

I'm also not sure if efficiency is really a concern in this case. :-)

-Steve

@lunaryorn

@purcell I have ns-win in my homebrewed Emacs 24.2.

@purcell

Then you're very lucky! ;-)

I don't have it in my recently-built-from-source Emacs 24.2.4.

In the meantime, I've changed the suggested conditional to:

 (when (memq window-system '(ns mac))
   (exec-path-from-shell-initialize))
@lunaryorn

@purcell Interesting… what library provides mac-option-modifier and friends then?

@purcell

Ah - it's there, but not on the load-path, so M-x find-library can't find it. And the eval-after-load block doesn't seem to trigger for that library either.

In any case, that file is not present in the Carbon flavour of Emacs, so its presence is not a universal indicator of a Mac window system.

@lunaryorn

@purcell I'll use your conditional then. But I doubt that anyone is still using Carbon Emacs ;)

@purcell

I hope they're not, but you never know... :-)

Please sign in to comment.
Something went wrong with that request. Please try again.