PATH and exec-path set, but emacs does not find executable - emacs

My .emacs contains
(setenv "PATH" (concat ".:/usr/texbin:/opt/local/bin" (getenv "PATH")))
(setq exec-path (append exec-path '(".:/usr/texbin:/opt/local/bin")))
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
(require 'tex-site)
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
/usr/texbin is where latex/pdflatex/.. are located.
/opt/local/bin/ is where gs can be found.
And yet when I run preview-at-point, which apparently needs both latex and gs, I get
Preview-DviPS finished at Thu Dec 22 11:25:46
DviPS sentinel: Searching for program: No such file or directory, gs
which means that latex could be found all right, but not gs.
I am not sure whether setting exec-path is necessary, perhaps PATH is enough, but I've set it as a debugging measure.
Why can emacs not find gs even though the directory it's in is in both PATH and exec-path?

If you're setting $PATH inside your Emacs, you might well be on OS X. GUI applications are not started via your shell, so they see different environment variables.
Here's a trick which I use to ensure the $PATH inside Emacs is the same one I see if I fire up a terminal (but see "update" below):
(defun set-exec-path-from-shell-PATH ()
"Set up Emacs' `exec-path' and PATH environment variable to match that used by the user's shell.
This is particularly useful under Mac OSX, where GUI apps are not started from a shell."
(interactive)
(let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
Then simply call the set-exec-path-from-shell-PATH function, perhaps from your Emacs init file. I keep that code on github, BTW.
Update: this code has now been improved and published as an elisp library called exec-path-from-shell; installable packages are available in MELPA.

Try replacing the second line with this:
(setq exec-path (append exec-path '("/usr/texbin" "/opt/local/bin")))

I hit a similar problem, but with a correct PATH, including trailing ´:´. It turned out the internal emacs shell program was missing, resulting in a ´Searching for program: No such file or directory´ message.
Fixed with
(setq shell-file-name "bash").

It appears you're missing a path separator : at the end of your path string.

Related

Change location of .ido.last history file in Emacs on Windows

Using Emacs with ido mode enabled on Windows, Emacs tries to save a history file .ido.last when exiting. The file is located in C:/.ido.last, but it fails with a permission denied message. This is strange since I actually have access to that folder. However:
Is there a command to change the directory where the .ido.last file gets saved?
Short answer: (setq ido-save-directory-list-file "/some/file/name").
Long answer:
I keep all the little files that remember Emacs's state in a single directory under the user-emacs-directory. I'm not sure what this is on Windows, but I think it's C:\Users\<username>\Application Data\.emacs.d\. On Unix, it's ~/.emacs.d/. The variable user-emacs-directory should be defined by Emacs, no need to set it.
(setq emacs-persistence-directory (concat user-emacs-directory "persistence/"))
(unless (file-exists-p emacs-persistence-directory)
(make-directory emacs-persistence-directory t))
(setq ido-save-directory-list-file (concat emacs-persistence-directory
"ido-last"))
You may want to look at the no-littering package, which sets better default locations for files like this.

Adding binary path to emacs $PATH

I tried the following:
(setenv "PATH" (concat (getenv "PATH") ":~/mybin"))
(setq exec-path (append exec-path '(":~/mybin")))
But that never worked. I tried M-! and typing one of the binary names and that gave "unknown command" also when doing M-x compile with the binary name same result. M-x compile then echo $PATH gave the path without my ~/mybin folder in it.
I am on solaris. What am I doing wrong?
: is not needed for exec-path. exec-path is list of directory paths.
And you should use absolute paths. You should fix as below.
(setenv "PATH" (concat (getenv "PATH") ":" (expand-file-name "~/mybin")))
(setq exec-path (append exec-path (list (expand-file-name "~/mybin")))
I recommend you to use exec-path-from-shell for setting PATH to Emacs.
It provides functions which get environment variables from your login shell and set them to Emacs. It is easy to share environment variables between Emacs and shell.
An emacs $PATH doesn't exist. $PATH is a shell variable. Emacs and shell have different name-spaces.
However - as Emacs might read and set $PATH via getenv, setenv - seems no way than looking into the library which access it made.
I'd preferred going with exec-path than.
For examples doing this:
(add-to-list 'exec-path "FULL_PATH_TO_BIN"))

change .emacs file's location

I am working on windows xp
I stored emacs in usb
I want to carry the .emacs file as well as binary files
what I tried are
(setenv “HOME” (format "%s" (getenv "emacspath")))
(setenv “HOME” (format "%s/" (getenv "emacspath")))
It seems works if I eval-expression in emacs
After setenv, I could notice setting env is works well by (getenv "home")
but I put the (setenv "home" (format "%s/" (getenv "emacspath")))
in "site-start.el" file in "site-lisp" folder, starting emacs says "Symbol's value as variable is void: "HOME"
Any ideas?
An easier way - just create a batch file on your USB drive where you can set all env variables you need. Then start emacs.exe from the batch.
For example if you want to run SBCL add the following lines to your batch
rem SBCL_HOME is required for SBCL
set SBCL_HOME=%utils%\Lisp\sbcl\1.0.29
set SBCL_RUN=%SBCL_HOME%\sbcl.exe
set SBCL_OPTIONS=--noinform
How about using default.el either as a symlink or as a simple elisp pinter to your file:
(load-file "/path/to/usb/.emacs")
Add following code to a file (e.g. c:/.emacs).
;; This function must be at begin
(defun zxy-relocate-dotemacs ()
"Relocate .emacs file"
(interactive)
(with-temp-buffer
(let (print-level print-length)
(insert (format "(load-file \"%s\")" load-file-name))
(if (file-exists-p "~/.emacs")
(message "[zxy] Don't need relocate .emacs file!")
(progn
(message "[zxy] Relocate .emacs file.")
(write-file "~/.emacs"))))))
(zxy-relocate-dotemacs)
;; Your configuration here
Open emacs and M-x load-file c:/.emacs.
Then it will relocate .emacs to c:/.emacs.
I use this when I copy my emacs to a new computer.
More information please visit my blog abuot emacs.
http://coordinate.sinaapp.com/?cat=3

P4CONFIG with emacs

I would like to see examples of how to setup perforce, using the config file functionality where emacs is used as the diff and merge programs (P4DIFF and P4MERGE settings). Even better if this is on Windows.
I'm also struggling with getting the P4EDITOR to work correctly when using emacsclientw, specifically specifying the alternate-editor functionality.
Any tips, suggestions, example configs are very welcome.
Here's a different trick I used to use. It adds a few command line options to emacs so that you can do diffs and merges in a new emacs instance (again using ediff).
;; -diff
(defun command-line-diff (switch)
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))
;; -merge
(defun command-line-merge (switch)
(let ((base (pop command-line-args-left))
(sccs (pop command-line-args-left))
(mine (pop command-line-args-left))
(merg (pop command-line-args-left)))
(ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))
Just put that in your .emacs file. Then you can set your P4DIFF program to be emacs -diff and your P4MERGE program to be emacs -merge.
I'm assuming you're already using p4.el.
Here's a function that will allow you to set your p4-client-config easily:
(defun p4-go (config)
(interactive
(list (read-file-name "P4 Config file: "
(concat (getenv "HOME") "/etc/perforce/")
""
t)))
(p4-set-client-config (expand-file-name config))
t)
Then I just run M-x p4-go <RET> conf <RET>.
My ~/etc/perforce/conf file looks like:
P4CLIENT=ewarmenhoven-ppd
P4PORT=perforce.netflix.com:1666
P4USER=ewarmenhoven
P4EDITOR=emacsclient
P4DIFF=diff -dupU8
P4MERGE=~/bin/emerge
The emerge merge program is just a short little shell script that calls emacsclient appropriately:
#!/bin/bash
base=$1
sccs=$2
mine=$3
merg=$4
emacsclient -e "(ediff-merge-files-with-ancestor \"$base\" \"$sccs\" \"$mine\" () \"$merg\")"
emacsclient "$merg"
If you're using cygwin it should work just fine.
For doing diffs, if it's running from the shell then I want the output in the shell, hence just using normal diff. If it's not, I use p4-ediff, which is bound to C-x p - by default.
The awesome answer by Eric doesn't work properly in latest emacs because of welcome screen. In order to hide the welcome screen (so that you may get the diff properly) please refer Unable to hide welcome screen in Emacs.
Another nifty setting which opens the diff in regular vertical mode is setting the below config variable
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ediff-split-window-function (quote split-window-horizontally)))

Erlang emacs mode - setting outdir

Does anyone know how to configure Erlang emacs mode so that compiling a buffer [C-c C-k] writes the beam file to the ebin directory rather than the current directory ?
Thanks!
You might want to have a look to this thread on the Erlang Questions Mailing List:
http://www.erlang.org/pipermail/erlang-questions/2007-August/028367.html
Moreover, you should be able to compile your file in debug mode:
C-u C-c C-k
The erlang-compile command should support prefix arguments. You might want to have a look to:
http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Command-Arguments.html
If you set up your directory structure like so:
/
/src/
/ebin/
and place your module (e.g. "my_file.erl") in the "/src/" directory then compile it (C-c C-k) then Emacs should automatically put the beam into the "/ebin/" directory.
However, if your module isn't in a directory named "/src/" (or if the "ebin" directory is missing) the beam will be dropped alongside the source file.
To see exactly how this works take a peek at $ERL_TOP/lib/tools/emacs/erlang.el and search for "ebin". Here's what you'll find:
(defun inferior-erlang-compile-outdir ()
"Return the directory to compile the current buffer into."
(let* ((buffer-dir (directory-file-name
(file-name-directory (buffer-file-name))))
(parent-dir (directory-file-name
(file-name-directory buffer-dir)))
(ebin-dir (concat (file-name-as-directory parent-dir) "ebin"))
(buffer-dir-base-name (file-name-nondirectory
(expand-file-name
(concat (file-name-as-directory buffer-dir)
".")))))
(if (and (string= buffer-dir-base-name "src")
(file-directory-p ebin-dir))
(file-name-as-directory ebin-dir)
(file-name-as-directory buffer-dir))))
Not sure when this goody was added, but it was in OTP_R13B03 and it works for me in R14B03.