Can .emacs read environment variables? - emacs

I wanted to load some files from a shell environment variable.
Can we check an environment variable in .emacs?

Yes, use the getenv function, e.g. (getenv "my-var").

Related

looking for help in configuring .emacs file for python (python.el),

My emacs version is 24.5, using in built python. I have written these lines in my .emacs for it:
(require 'python)
(setq python-shell-interpreter "C:/Python34")
The problem is none of the commands (when I am trying to run test.py) are working. I have tried several commands named like
M-x python-shell-*
and they all return
"wrong type argument:arrayp, nil".
What I am doing wrong?
What am I supposed to do?
What should be ideal configuration (.emacs)?
Further info:
Python 3.4 installed at C:/
Emacs at C:/Program Files/
$HOME is C:/user/akk/appdata/roaming/
That variable is for the Python interpreter, not the Python directory.
I don't have a Windows machine to test on, but if you update your configuration to point to the actual binary (possibly C:/Python34/python.exe?) you should find that it works.
According to the mode documentation in the top of python.el, you can set this on windows like (change Python27 to Python34 for your use case:
(setq python-shell-interpreter "C:\\Python27\\python.exe")

Emacs, bash, bashrc, functions and paths

Usually I use my .bashrc file to load some functions for my bash environment. When I call these functions (that I created based on some frameworks I use). So, I play around with variables such as PATH and PYTHONPATH when I use the functions depending on the environment I'm working on.
So far so well with the terminal. The problem is that when I use emacs these functions and these environmental variables that I activate with my functions, they don't exist. .bashrc is not read by emacs, and therefore I don't have the functions loaded by .bashrc don't work. I would like them to work.
Any Ideas?
The issue might be that emacs, as many other programs you run, reads your login shell rc files, such as ~/.bash_login or ~/.profile, but not ~/.bashrc, where as your terminal also reads you user shell rc file: ~/.bashrc.

What exactly is the difference between PATH (as set by setenv) and exec-path in GNU Emacs?

Well, the title has it all. I used to (setenv "PATH" "whatever:$PATH" t) to be able to call things (in fact, one thing - ConTeXt, from within AUCTeX) from Emacs. Just a while ago I learned about exec-path. Should I use it instead?
While setenv actually sets the environment (and affect (modifies) what executed programs from this emacs will see as an environment), exec-path tells emacs where to look for executables, but programs run from this emacs won't see their PATH changed.
Changing the environment with setenv does not change how the current Emacs searchs for executables, as it uses exec-path. To achieve that and make child processes executed by this Emacs to have the $PATH changed, you have to set both exec-path and $PATH.

Defining environment variables in Linux for Emacs access

On Macs, defining environment variables in the environment.plist will allow you to use environment variables in Emacs.app. On Linux, is there such an equivalent?
I don't want to use the environment variables in one of the shell or terminal emulators but also for find-file (C-x C-f), shell-command (C-!), etc. and I have a lot of paths defined as environment variables that would be helpful here. For instance, finding a file with find-file can be $WORK/projectname and so on.
I suppose the most straightforward way is to use setenv within .emacs, but as I have a lot of such variables it would be better if I could define it once in an external file and have Emacs read it in.
Edit: Sorry for the confusion. This question is specifically addressing issue of Emacs access, as variables defined in ~/.bashrc is not available to Emacs until shell, eshell, or term is invoked.
here a script which defines several environment variables, read by Emacs in batch mode
http://bazaar.launchpad.net/~python-mode-devs/python-mode/python-mode/view/head:/test/python-mode-tests.sh
from lisp getting $HOME for example use (getenv "HOME")
To be able to access the variables in your .bashrc you need to launch emacs from a bash shell. If you just click on an icon then the .bashrc is not read and you won't have access to your variables.
If you absolutely cannot launch emacs from a bash shell, find an init file that is loaded by your desktop environment. In my case it is .xsession. Any variable I export in it will be available to emacs.
To access environment variable use getenv.
If you define environment variables in ~/.bashrc they are available in the user shell for all commands.
The right syntax is:
export VARIABLE="value"
You can edit your .bashrc in your home directory, where you can add your own aliases, define environment variables and add paths for your custom scripts.

Setting Racket Geiser Emacs Path

I'm trying to get Geiser's REPL to work in Emacs, but it doesn't seem to be able to find Racket.
racket is on my path, but anytime I type
run-geiser
followed by
racket
it complains:
Unable to start REPL: Searching for program: no such file or directory, racket
I read in the Geiser docs that I may have to manually tell Geiser where to find racket, but I can't tell where to configure this property of Geiser.
Thanks for your help.
Ok, so I added:
(setq geiser-racket-binary "/home/user/racket/bin/racket")
to my .emacs file after loading geiser.el.
I was expecting a configuration file somewhere to set this.
Thanks.
I know this is an old question, but for future people having a hard time getting it to find the Racket executable despite it being in your path, you can simply use the executable-find function.
This searches your path and returns the absolute path to the executable, which is what the geiser-racket-binary function wants. So this is an alternative to explicitly setting the absolute path:
(setq geiser-racket-binary (executable-find "Racket"))
In Windows, adding the location of the Racket executable to the "path" environment variable which is part of Windows will allow Geiser/Emacs to find the Racket Executable.