So I've finally decided to learn Lisp. I'm reading Practical Common Lisp and I'm using Lispbox (not the one the book recommends - it's no longer available, but it seems this is suitable nonetheless).
So far in my career I have managed to avoid wresting with emacs, but I guess that part of my life is over :-) Actually, I'm kind of excited - this is a brand new world.
When saving .lisp files, the out-of-the-box setup dumps these files into the lispbox-0.7 folder (which is also the LISPBOX_HOME env.var). My math teacher taught me, "If you don't know what you're doing, at least do it neatly." So I want to at least keep my work in a nice tidy folder. I can specify the full path on saving/loading. But can I tell (lispbox|emacs|whatever) to use a different folder by default?
If it matters: I will likely use the Windows version more often, but I also have a setup on Ubuntu.
I have looked at this and this and this. I tried adding these to the .emacs file (one at a time):
(setq default-directory "C:/Work/lisp/")
(cd "C:/Work/lisp/")
To open the .emacs file I used C-x C-f~/.emacs
If I try changing the LispBox shortcut's "Start in" property, it fails to load at all.
M-xcd c:/work/lisp does work, but I have to do it every time I launch LispBox
What I'm doing in the meantime: I've created a separate lisp folder beside the lispbox-0.7 folder. That way I can prepend ../lisp/ before any filename. This isn't so bad, especially with the tab auto-complete.
Found it!
The reason modifying .emacs wasn't working is because of the lispbox.bat file. It has this line:
%EMACS% --no-init-file --no-site-file --eval=%TO_EVAL%
So took out the two "no" parameters, leaving this...
%EMACS% --eval=%TO_EVAL%
...and it worked.
This worried me, though. Why would the default not want to load the .emacs file? I guess once I understand all of this better I'll have an answer. Until then, I restored the above, the changed this line...
set TO_EVAL="(progn (load \"lispbox\") (slime))"
...to this...
set TO_EVAL="(progn (load \"lispbox\") (slime) (cd \"C:/work/lisp/\"))"
Now I'm happy.
I know nothing about Lisp Box, and not all of what you describe is clear to me. But here goes.
It sounds like you are looking for a way to make c:/work/lisp the default directory when you start Emacs. For that, using an MS Windows shortcut, putting that folder in the Start in field does indeed accomplish that. But you speak of a LispBox shortcut's Start in. If by that you just mean an Emacs shortcut, then it should work.
But of course you need to use Windows syntax for the folder - not c:/work/lisp, but c:\work\lisp.
Is that what the problem was?
The Windows shortcut is a Windows thing. Emacs is different: it accepts / as a folder separator.
Tip: If that solves your problem, you might also want to start Emacs in Dired mode on that same folder, that is, if that folder is the one you will use a lot. To do that, add that folder at the end of the command line - again, using Windows syntax, but between double-quotes:
c:\your\path\to\runemacs.exe "c:\work\lisp"
Try starting lispbox.bat from the directory you want to save files to. For example, from the OS command prompt:
cd c:\work\lisp
path-to-bat-file\lispbox.bat
You can also cd to c:\work\lisp in listbox.bat before it executes Emacs. For Linux it looks like this in lispbox.sh:
#!/bin/bash
if [ "${0:0:2}" = "./" ]; then
export LISPBOX_HOME=`pwd`/../../..
else
export LISPBOX_HOME=`dirname $0`/../../..
fi
cd ~/work/lisp
export SBCL_HOME=${LISPBOX_HOME}/sbcl-1.0.42/lib/sbcl
exec ${LISPBOX_HOME}/Emacs.app/Contents/MacOS/Emacs --no-init-file --no-site-file --eval='(progn (load "lispbox") (slime))'
Related
I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?
Do I have to create it myself? If so, under what specific directory does it go?
Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:
Where do I put my init file?
On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by Lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
If the environment variable HOME is set, use the directory it indicates.
If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
If C:\.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.
There's further information at HOME and Startup Directories on MS-Windows.
It should be stored in the variable user-init-file. Use C-H v user-init-file RET to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET
Open the file like this in Emacs for Windows:
C-x C-f ~/.emacs
More information in the Emacs Wiki
On my Vista box it's in C:\Users\<USER>\AppData\Roaming\
Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs and create the file.
It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.
Also, you may want to do more than just access the .emacs init file, but you may want to know where it is, i.e., its pathname.
To get at this there are two methods:
Easy way: type Ctrl + H V user-init-file Return
Slightly trickier way:
You can find out where your system is storing its own .emacs file by:
Click options and scroll down to "Set Default Font..."
Change the font setting and click okay
On the options menu, go down to "Save Options"
When the options are saved, the system saves its .emacs file,
and you can read the file path in the minibuffer at the bottom of the Emacs screen
In Windows 7 put your init.el file in C:\Users\user-name\AppData\Roaming\.emacs.d\, where user-name is your user/login folder.
Take care so your init.el file won't be named init.el.txt. This is something Windows does if you create your file with some editor like Notepad.
On versions of Emacs on Windows above 22, it seems to have moved to
~/.emacs.d/init.el
, ~ being the value of your environment variable HOME (see Control Panel → System → Advanced → Environment variables).
The file itself might not exist. In that case just create it.
You must create an emacs initialization file. One is not automatically created.
I had a similar issue and this answer tracks down what I did.
My issue was my ~/.emacs.el file was not loading. Strange because this has always worked for me.
This question/answer helped me but I had to put my init file in the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el because this is apparently the default behavior on Windows.
To troubleshoot this, I ran the following in the emacs *scratch* buffer.
user-emacs-directory
"~/.emacs.d/"
When I saw user-emacs-directory was ~/.emacs.d, I simply moved my .emacs.el file to %USERPROFILE%\.emacs.d\init.el. But this still didn't work.
I continued with expand-file-name as shown below:
(expand-file-name user-emacs-directory)
"c:/Users/pats/AppData/Roaming/.emacs.d/"
Got to love how Windows works. (not) So I moved my emacs.el file to the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el and this worked. The file was now being read. But I got other errors because my initialization file loaded other (personal emacs) files (in ~/myenv/emacs/*.el.
Warning (initialization): An error occurred while loading ‘c:/Users/pats/AppData/Roaming/.emacs.d/init.el’:
Hum... Seems like all my files ~/myenv/emacs/*.el would need to be moved in order for this to work but I didn't want to do that. Then I realized that because the HOME environment variable was not set, emacs was performing its default behavior.
SOLUTION
Once I set my windows HOME environment variable to %USERPROFILE% everything began to work like it has for the past 25 years. :-)
To set the HOME environment variable, I typed WindowsKey+"edit environment variables for your account" to open the Environment Variables dialog box, and entered HOME=%USERPROFILE%.
Now my emacs initialization file .emacs.el is is back to its rightful place $HOME/.emacs.el and not in %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
To be fair, if Windows had just one place to put files for user installed packages the solution of making HOME=%USERPROFILE\AppData\Roaming might be acceptable, but because some applications use %USERPROFILE%, some use %USERPROFILE\AppData\Roaming and others use %USERPROFILE\AppData\Local it just makes it difficult to know where to find your configuration files.
I prefer having everything in my %USERPROFILE% or $HOME directory.
Another similar question was here:
Emacs init.el file doesn't load
As kanja answered, the path to this file is stored in the user-init-file variable (or if no init file exists, the variable contains the default value for where to create it).
So regardless of which of the possible init file names you are using, and which directory it is in, you should be able to visit your init file with:
M-: (find-file user-init-file) RET
Or display its full path in the echo area with:
M-: (expand-file-name user-init-file) RET
On Emacs 23 and Windows 7 it only works if you set:
HKCU\SOFTWARE\GNU\Emacs\HOME
After Emacs 27.1, emacs has started respecting the $XDG_CONFIG_HOME. The init file or the init directory can now be found in $XDG_CONFIG_HOME/emacs/init.el.
In Windows $XDG_CONFIG_HOME could translate to %LOCALAPPDATA%.
In any case you can use the following emacs variables to find out the location of the your initialization file by M-x eval-expression
user-init-file
or the emacs configuration directory
user-emacs-directory
I've found that Emacs 22 will occasionally open either "C:\Documents and Settings\username\Application Data\.emacs", or just "C:\Documents and Settings\username\.emacs" on my XP machine. I haven't found an explanation for why it occasionally changes it's mind.
~ will always point to whatever the current instance of emacs thinks is HOME, but kanja's tip (C-h v user-init-file) will always tell you what ~/.emacs actually maps to.
On Windows 8.1, if Emacs is started from Windows Explorer, a shortcut or from cmd console it uses C:\Users\<USER>\AppData\Roaming.emacs init file. When I start Emacs from PowerShell, Emacs looks for its init file in C:\Users\<USER> folder. The fix to this issue was to set the HOME user environment variable (Control Panel\System and Security\System->Advanced system settings->Advanced->Environment variables) to C:\Users\<USER>. After this change, no matter how I start Emacs, it uses the same init file (see the accepted answer of this question)
On Windows XP it's:
C:\Documents and Settings\yourusernamehere\Application Data\
There is a list of directories based on your Windows version and extra information:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
For WIndows7& Emacs26.3:
if HOME environment is set, then the .emacs file should be in that folder.
otherwise, it should be in c:\.
In both cases, if .emacs is not there, _emacs should be used.
This is because we cannot create .emacs file according to the windows file naming rules.(but we can download or copy it from somewhere else).
I have emacs24 and emacs25 on my machine. I want to use spacemacs with emacs24 and keep emacs25...well...as emacs. When I install spacemacs my ~/.emacs and ~/.emacs.d are changed. Both emacs start using spacemacs, which I do not want. Is there a way to have a spacemacs and an emacs at the same time. Tried looking for a solution and came across a solution to keep separate config files. But how to make emacs look for a specific config file. By the way if you still haven't guessed...I'm a noob.
At one level, this is quite easy to do. However, at another, there can be some
complications, depending on what you really want to do.
Emacs supports a command line switch -l to tell emacs where to find the config
file. So, from a very simple perspective, you could just create two wrapper
scripts my-spacemacs.sh and my-plainemacs.sh and inside them have the scripts
call emacs with a specific -l /path/to/config. You can pass $* to pick up other
command line arguments if you want.
The potential problem with this approach is that emacs will still use .emacs.d
to store all sorts of other information, including possibly elpa packages and
this could cause problems. To be safer, it is better to keep things completely
separate.
If you don't need to run both versions at the same time, the easy solution is to
have to separate directories, such as ~/.spacemacs-emacs.d and ~/plain-emacs.d
and then have a sym link called .emacs.d which points to whichever of the
versions you want to run. The two main problems with this approach is that you
need to reset the symbolic link whenever you want to change emacs flavors and
this won't work if you want to run both versions at the same time.
I guess we really need to know about your actual use case - why do you need two
different configurations? Knowing this could help identify a better approach.
As an example, I use org mode and babel to manage my emacs config. I have a
number of different versions and a simple script which I can run to generate
whichever init.el file I want from the different org files. I have a minimal.org
file, which has the most minimal emacs configuration I can bare and I have my
standard init.org which generates my working init.el and then I have an
experimental.org which is used to generate an init.el file which I use for
experimenting with new configurations or packages. It is trivial to switch
configurations, but I never need to run two different configurations at the same
time.
I often like to check out some of the other pre-cooked emacs setups, like
spacemacs, prelude, etc. for these, I just grab the current git version and use
a symbolic link to point .emacs.d at the root fo the git repo I want to
experiment with.
you can also use the following approach:
create a directory ~/spacemacs.
extract/copy the spacemacs .emacs.d into ~/spacemacs (so that it is ~/spacemacs/.emacs.d).
create a desktop link called Spacemacs (or menu entry) and enter the following command:
HOME=$HOME/spacemacs emacs
You can also start spacemacs from the shell with this command.
This way, you can run vanilla emacs and spacemacs simultaneously, each with its own configuration directory and elpa repository. The only disadvantage might be that you need to change a directory level upward to reach your real home directory, not the „fake” one set via the variable.
btw, this is how I run several emacs versions and configurations, as needed for diverse stuff.
The best solution seems to be using chemacs: https://github.com/plexus/chemacs
I have my emacs.d folder located at:
C:\Users\<loggedin_user>\AppData\Roaming\.emacs.d
In this folder, I have my init.el file but it is not being picked up by emacs.
Is there another step I am missing, do I need to set an environment variable or something?
When I enter C-x d ~/ RET I end up at
C:\Users\<loggedin_user>\AppData\Roaming\
If I move the init.el file there, it is still not picked up. I have a deliberate error in the file that is not causing emacs to crash when it is opened.
Most likely you have an old ~/.emacs file somewhere else which Emacs ends up using in preference to the other one.
You probably want to check the value of user-init-file which will tell you which file Emacs ended up using as "the ~/.emacs file".
I suggest you report this as a bug, requesting that when several files are found as possible init file, Emacs should not just pick the first and ignore the others but should at least emit a warning about the fact that it ignored the others.
This is tricky on Windows 10 but I solved since I was suffering from same issue.
I created an Environment Variable called HOME with the path C:/user/<username> in the box "User variables for " create a new one
Just open with double click any file that is by default opened with Emacs and it will take few seconds to load then take changed on the init.el
create an init.el with just one line of code like:set-background-color "honeydew"
to test this, first before doing something more complex.
Hope That It Helps!
On Windows, Emacs is started with some Properties defined, found when you right-click the executable on your windows system. There you can define the
execution-directory, e.g. "C:\Users\loggedin_user\" (in parantheses)
where emacs executes
and looks for the .xemacs (.emacs) directory, where it find its init.el. (I had to create an .emacs File in my Windows Home Directory, which is defined in the Windows HOME Environment)
And where you can define the startup instructions (like (setenv "HOME" "c:/Users/Username/") ) etc.
If you configure that, the next time, emacs starts from the directory, you defined, with the initialisation-file
Windows 10 and Emacs 27.1 could not find .emacs.d: one more possibility, in my case %HOME% was set like HOME=%HOMEDRIVE%%HOMEPATH%. This redirection seems not to work and emacs was using literally C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% for searching .emacs.d. I did not dare to edit %HOME% but created link:
C:\Users\username> cd %HOME%
You perhaps need to remove some files in C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% which emacs already created.
Create link:
C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH%> mklink /d .emacs.d ..\.emacs.d
Currently my .emacs file is found in /home
So is my .emacs.d folder and I suppose some other files like diary, notes etc will be created in this folder.
I find this really messy and I want all my emacs related files(including the .emacs) and folders in a single folder, say /home/EmacsHome
How do I do that in Ubuntu 12.04? In windows I did this by setting an environment variable HOME to the path of EmacsHome. But, in Ubuntu, the HOME variable will be used for several other programs as well, so I dont want to change that.
Emacs already supports a config directory for holding everything Emacs-related: ~/.emacs.d. Just use that.
Rename ~/.emacs to ~/.emacs.d/init.el, and you're virtually done.
If you have any other emacs-specific files outside of that directory, you might need to set a variable here or there to relocate them, or simply rename the file -- these days the defaults tend to automatically be within ~/.emacs.d, but an older filename in the home directory might still take precedence.
e.g.: the bookmarks file used to be ~/.emacs.bmk but if you haven't customized the variable then you can simply rename it to ~/.emacs.d/bookmarks. See C-h f locate-user-emacs-file RET and M-x find-variable RET bookmark-default-file RET for details.
If you're not sure how to proceed for any given file(s), you could just update the question with the details.
And as Alberto Zaccagni said, just create a symlink if you want an alternative name to access the directory. Although personally I would suggest retaining ~/.emacs.d as the real directory, and making the alternative name the link, like so:
ln -s ~/.emacs.d /home/EmacsHome
You could create a symbolic link to them, like so
ln -s /home/EmacsHome ~/.emacs.d
The first argument is the folder where you want the folders to be, the second one is where emacs usually looks for its configuration files, so with this approach you can put the folder wherever you like.
This works for OSX, so perhaps for you too . . . just change the paths to whatever suits your needs. The user-emacs-directory is where you would set the equivalent of .emacs.d. I have everything related to Emacs in my user-emacs-directory. If you use package manager, the elpa directory would be automatically crated there also.
(setq default-directory "~/.0.data/")
(setq user-emacs-directory "~/.0.data/.0.emacs/")
(setq diary-file "~/emacs/diary")
There's also another solution:
cd your-directory
HOME=$PWD emacs -L .
taken from https://github.com/capitaomorte/yasnippet#important-note-regarding-bug-reporting
I have decided to check out Emacs, and I liked it very much. Now, I'm using the Emacs Starter Kit, which sort of provides better defaults and some nice customizations to default install of Emacs.
I have customized it a little, added some stuff like yasnippet, color-themes, unbound, and other stuff. I've set up a github repository where I keep all of the customizations so I can access them from multiple places or in case something goes bad and I lose my .emacs.d directory.
All of this is very nice, but there is a problem: Emacs takes about 1-2 seconds to load. AFAIK I can compile individual .el files with M-x byte-compile-file to .elc, and it works. But there are a lot of .el files, and I wonder if there is a way to compile them all with a simple command or something, to speed up the loading of Emacs. My Emacs is not always open, and I open and close it quite frequently, especially after I've set it up as a default editor for edit command in Total Commander to get used to it faster (yeah, windows xp here).
My Emacs version is 22.3. And yes, the default Emacs installation without any customizations fires up instantly.
I am not sure which version is preferred when loading, the .el or compiled .elc one by the way O.o
So, is there an elisp command or Emacs command line switch to make Emacs byte-compile everything in .emacs.d directory?
C-u 0 M-x byte-recompile-directory
will compile all the .el files in the directory and in all subdirectories below.
The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.
To automatically byte compile everything that needs byte compiling each time I start emacs, I put the following after my changes to load-path at the top of my .emacs file:
(byte-recompile-directory (expand-file-name "~/.emacs.d") 0)
Surprisingly, it doesn't add much to my startup time (unless something needs to be compiled).
To speed up my emacs, I first identified the slow parts using profile-dotemacs.el and then replaced them with autoloads.
You can use the --batch flag to recompile from the command line.
To recompile all, do
emacs --batch --eval '(byte-recompile-directory "~/.emacs.d")'
or to recompile a single file as from a Makefile,
emacs --batch --eval '(byte-compile-file "your-elisp-file.el")'
This is swaying a bit from the question, but to solve the problem of loading slowly you can use the new daemon feature in Emacs 23.
"If you have a lot of support packages,
emacs startup can be a bit slow.
However, emacs 23 brings emacs
--daemon, which enables you to start emacs in the background (for example
when you log in). You can instantly
pop up new emacs windows (frames) with
emacsclient. Of course, you could
already have an emacs 'server' in
older versions, but being able to
start it in the background makes this
a much nicer solution"
From http://emacs-fu.blogspot.com/2009/07/emacs-23-is-very-near.html
The command I use is M-x byte-force-recompile RET, it then asks the directory so, for example, I give it ~/.emacs.d/elpa/. It then recompiles everything in there, usually no need to delete .elc files first or mess with it in other ways.
For my using spacemacs, the command is spacemacs/recompile-elpa. The command byte-recompile-directory does not compile any file.