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"))
Related
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.
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.
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
According to the Emacs documentation, Directory Variables apply to all files below a directory that contains an .dir-locals.el file.
How can I, in that file, set a variable to the full path that contains the file? For example:
((nil . ((indent-tabs-mode . t)
(my-project-path **THIS_DIRECTORY**))))
I asked myself the same question and found no solution on the web, so I think this answer may help. Actually, it turns out we can reuse dir-locals-find-file to get the directory containing the .dir-locals.el file. So here's what I found for, e.g, setting up an aspell personal dictionary dedicated to a whole directory:
((nil . ((eval . (setq ispell-personal-dictionary
(expand-file-name
".aspell_words"
(file-name-directory
(let ((d (dir-locals-find-file ".")))
(if (stringp d) d (car d))))))))))
Also, it seems entries are evaluated in the order they are specified, so the following code should work:
((nil . ((eval . (set (make-local-variable 'my-project-path)
(file-name-directory
(let ((d (dir-locals-find-file ".")))
(if (stringp d) d (car d))))))
(eval . (message "Project directory set to `%s'." my-project-path)))))
Emacs will complain about unsafe local variables (due to the eval construct), yet one can still permanently mark it safe.
Update: Since Emacs ≥ 26.3 (and maybe older versions as well), it appears that one needs to use (dir-locals-find-file "./") instead of (dir-locals-find-file ".").
I think (file-name-directory (or load-file-name buffer-file-name)) should give you the directory path.
See Link
Edit: Except it won't, because any eval expressions are evaluated in the context of the buffer whose variables are being hacked.
In my case, I wanted to locate a file that was relative to my current working directory for my repository, and the .dir-locals.el file was checked into the root, so a file "local" to the .dir-locals.el was also a file "local" to the project root.
pajato0's answer above worked for some cases, but it was also breaking other modes (like magit). I got around the issue by using the projectile package's projectile-project-root function to find my the base path for me:
((nil . ((eval . (setq cmake-ide-build-dir
(concat (projectile-project-root) "/build-make"))
))))
I've found the locate-dominating-file procedure, which comes out-of-the-box with Emacs, useful to retreive the current directory of a known file. The example below sets the guix-directory variable to the topmost directory of the project containing a .dir-locals.el file.
((nil . ((eval . (setq guix-directory
(locate-dominating-file default-directory
".dir-locals.el"))))))
It's not a safe .dir-locals.el setting, due to relying on eval, but it gets the job done.
In case it still matters, to the OP or some other, I would suggest you create a function to generate the .dir-locals.el file. Then one could write something like:
(let ((path default-directory)
file)
(setq file (format "%s/.dir-locals.el" path))
(with-temp-buffer
(insert (format "((nil . ((indent-tabs-mode . t)
(my-project-path \"%s\"))))" path))
(when (file-writable-p file)
(write-region (point-min)
(point-max)
file))))
to be executed within the project home directory.
hack-local-variables is the main function for processing all local variables, and it calls hack-dir-local-variables to deal with the .dir-locals.el file (or a dir local class variable, if you're not using that file).
The code for establishing the directory is not isolated in its own function, so we'll have to copy it out into a new function (this from GNU Emacs 24.0.95.1):
(defun my-dir-locals-dir ()
"Return the directory local variables directory.
Code taken from `hack-dir-local-variables'."
(let ((variables-file (dir-locals-find-file (or (buffer-file-name) default-directory)))
(dir-name nil))
(cond
((stringp variables-file)
(setq dir-name (file-name-directory variables-file)))
((consp variables-file)
(setq dir-name (nth 0 variables-file))))
dir-name))
If you are working on *nix, you might get the work directory by the following elisp code,
(defun get-working-directory ()
(getenv "PWD))
Btw, I have to mentioned that, (shell-command "pwd") will result in the directory where file (which is corresponding to the buffer you are currently editing).
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.