Emacs initialization and load-path - emacs

I need some help understanding Emacs initialization and load-path variable construction.
So, there is the init file .emacs (or .emacs.d/init.el) file in $HOME, that is loaded first, and at the point this file is about to be read, load-path already contains directories from /etc, /usr/*, e.g. directories from the Emacs distribution itself.
After loading the init file is there any standard Emacs initialization files, that scan through .emacs.d and adds subdirectories it finds there?
The Emacs manual says something about subdirs.el in the first Emacs initialization step (https://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html#Startup-Summary), but it happens before loading the init file and I do not understand the language used:
It adds subdirectories to load-path, by running the file named subdirs.el in each directory in the list.
In which "the list"?

In this step "the list" is actually the preloaded installation values in load-path. The rest of the points are clear in the steps performed. For instance, some Debian/Ubuntu distributions add some system-wide configuration files in /etc/emacsXX, and this is hard coded in the source code when he package is compiled as some of the initial paths in load-path.

After loading the init file is there any standard Emacs initialization files, that scan through .emacs.d and adds subdirectories it finds there?
In general, no -- Emacs will not automatically add arbitrary subdirectories to your load-path (and nor would you want it to).
This does happen for some particular subdirectories, however.
As of Emacs 24 the in-built package manager will automatically add your installed ELPA package directories to the load-path after your init file has been evaluated.
(And/or when package-initialize is called explicitly, if you do that.)
By default your ELPA packages live under ~/.emacs.d/elpa/

Related

How to mask an already installed Emacs package?

I am using Emacs 24 in an work environment where I cannot modify what are outside of my personal folder.
I want to install a particular package, but there is already an older version of this package installed outside of my personal folder. I have to install it manually, so I added the package folder path to 'load-path' and required it myself in init.el file. But still, after the startup, when I check the version, it showed that the version is still the older version which is loaded from a place outside of my personal folder.
My question is how can I mask that older package? In another word, how can I choose to load my version instead?
The key is to modify the the load-path variable at the very beginning of your init.el file.
add-to-list adds to the front of a list. For example, this is how I load my version of org:
(add-to-list 'load-path "~/.emacs.d/org-mode/lisp")
I also suggest that you inspect the contents of the variable (use Meta-x describe-variable). This will inform you what directories are scanned first.
Be warned, sometimes mixing packages creates weird issues. If this happens, be patient and try one package at a time.
Addendum: as Drew mentioned below, emacs will try to find a package to load
in each of the directories in the load-path, starting from its head.
So the order of the directories in it matter.
--dmg

emacs el-get does not load packages

Using Emacs 24.3 on OS X, I have setup el-get as described. I am able to install, remove, and init packages using the el-get-* commands.
However, none of the packages ever actually load. The simple example I use is for the package 'ascii-table'. I do the following:
M-x el-get-install ascii-table
M-x el-get-init ascii-table
But when I do
M-x ascii-table
Emacs says it is not found. If I explicitly eval the ascii-table.el file that was downloaded by el-get, it works as expected.
Is there something I must do, after installing a package, to actually use the package? Or do I still need to put the necessary load-file or whatever in my init.el file to load the packages?
It sounds like, from the el-get documentation, that there was nothing else that needed to be done.
You can instruct el-get to require features from a package by adding the property features to the package's recipe file. From the documentation (do C-hvel-get-sourcesRET)
:features
List of features el-get will `require' for you.
For your particular case do M-xel-get-find-recipe-fileRETascii-tableRET, this open ascii-table's recipe file for you, then add the following to the recipe
:features (ascii-table)
The full recipe will be
(:name ascii-table
:auto-generated t
:type emacswiki
:description "simple ASCII table"
:website "https://raw.github.com/emacsmirror/emacswiki.org/master/ascii-table.el"
:features (ascii-table))
My advice would be not edit the original recipe but keep this in your personal recipes folder to avoid any conflicts when updating el-get.
That said you can always manually load a package, see #Drew's comment
Is el-get supposed to load libraries? I doubt it.
To load a library, put (require 'FEATURE-NAME) in your init file, where FEATURE is the feature provided by the library. If it does not provide any feature, then use the file name instead (between " chars).

Custom init file for GnuEmacs [duplicate]

I often come across the following popular emacs builds:
graphene
prelude
emacs-live
Currently I'm running a custom configuration, but I'd like to experiment with these builds without clobbering my current ~/.emacs.d.
Here's some background on my current installation:
I installed Emacs via Homebrew, so it's located here: /usr/local/Cellar/emacs/HEAD/Emacs.app
My current version of emacs is:
GNU Emacs 24.3.50.1 (i386-apple-darwin13.0.0, NS apple-appkit-1265.00)
Basically, here's what I'd like to know:
What's the easiest way to switch between these builds as well as my current custom configuration?
Given my current setup, is it possible to start multiple emacs sessions, each with their respective configuration/buffers?
(Edit: I've wrapped this approach up into a shell script which I've added to the EmacsWiki.)
I'd be inclined to use the $HOME environment variable:
Firstly copy the 'distribution' (for want of a better term) into a sub-directory .emacs.d of a directory which will serve as the replacement $HOME for that distribution. i.e. /path/to/(distribution)/.emacs.d:
$ git clone https://github.com/bbatsov/prelude.git ~/emacs/prelude/.emacs.d
$ git clone https://github.com/overtone/emacs-live.git ~/emacs/emacs-live/.emacs.d
Then you can start emacs using env to set the HOME environment variable locally for that command:
$ env HOME=$HOME/emacs/prelude emacs
$ env HOME=$HOME/emacs/emacs-live emacs
They shouldn't interact with each other, so you can run them together and have multiple side-by-side emacs instances, each using a different configuration.
I see that graphene is actually an ELPA package, so it has no init.el file and needs to be installed via the package manager; but you can still use the same technique to install it in a separate clean configuration: Simply make a similar directory structure to the others, then create an init.el file (e.g. ~/emacs/graphene/.emacs.d/init.el) containing the code from the graphene installation instructions, then run emacs (e.g. env HOME=$HOME/emacs/graphene emacs), and finish the remainder of the installation instructions.
The down-side to this technique is that Emacs won't see all your other dot files (because it will be looking in $HOME), and so running other processes from within Emacs won't necessarily work as normal; but that's not likely to be a huge issue if you're just experimenting, and you can always symlink or copy the bits you need.
You may even prefer it that way -- the benefit is that if anything in the distribution you're trialing writes files to the home directory, it's not going to clobber your real files.
This may also be a useful approach when upgrading Emacs to a new release (if you can run both the old and the new versions side by side) as you could set up a copy of your existing config to use with the new Emacs until you're convinced everything is working, and you can edit the new config without the risk of breaking your existing one. Or flip that around, and instead keep the original config in the new/alternate location, in case you need it as a back-up.
You can symlink ~/.emacs.d, this is what I do
1) Try to keep my emacs configuration ~/.emacs.d oriented i.e. all the config files should live in that folder. For example I use workgroups2, by default it stores workgroup configuration in ~/.emacs_workgroups but I have configured it to store configuration in ~/.emacs.d/workgroups, so my entire emacs configuration is in just one folder.
2) Then I have an ~/emacs_configs folder where all config folders (basically a folder with a init.el and rest of the configuration) live, so my personal config folder will be ~/emacs_configs/iqbal, a prelude distribution will be in ~/emacs_configs/prelude
3) Then finally I symlink ~/.emacs.d to the configuration I actually want to use, eg. to use my configuration I will do ln -s ~/emacs_configs/iqbal .emacs.d. If you want to tryout some configuration just copy the configuration folder to ~/emacs_configs/whatever_name and change the symlink
Hope this helps
I create ~/.emacs.1.d/init.el file , and give it content:
(setq user-emacs-directory "~/.emacs.1.d/")
then , start emacs like this emacs -q -l ~/.emacs.1.d/init.el , now emacs used new configration.
success!!
-q is means skip the default configration ~/.emacs.d/init.el
-l is means load new configration
You can do this with chemacs2. This is the primary (only?) usecase of chemacs2.

How to start up emacs with different configurations

I often come across the following popular emacs builds:
graphene
prelude
emacs-live
Currently I'm running a custom configuration, but I'd like to experiment with these builds without clobbering my current ~/.emacs.d.
Here's some background on my current installation:
I installed Emacs via Homebrew, so it's located here: /usr/local/Cellar/emacs/HEAD/Emacs.app
My current version of emacs is:
GNU Emacs 24.3.50.1 (i386-apple-darwin13.0.0, NS apple-appkit-1265.00)
Basically, here's what I'd like to know:
What's the easiest way to switch between these builds as well as my current custom configuration?
Given my current setup, is it possible to start multiple emacs sessions, each with their respective configuration/buffers?
(Edit: I've wrapped this approach up into a shell script which I've added to the EmacsWiki.)
I'd be inclined to use the $HOME environment variable:
Firstly copy the 'distribution' (for want of a better term) into a sub-directory .emacs.d of a directory which will serve as the replacement $HOME for that distribution. i.e. /path/to/(distribution)/.emacs.d:
$ git clone https://github.com/bbatsov/prelude.git ~/emacs/prelude/.emacs.d
$ git clone https://github.com/overtone/emacs-live.git ~/emacs/emacs-live/.emacs.d
Then you can start emacs using env to set the HOME environment variable locally for that command:
$ env HOME=$HOME/emacs/prelude emacs
$ env HOME=$HOME/emacs/emacs-live emacs
They shouldn't interact with each other, so you can run them together and have multiple side-by-side emacs instances, each using a different configuration.
I see that graphene is actually an ELPA package, so it has no init.el file and needs to be installed via the package manager; but you can still use the same technique to install it in a separate clean configuration: Simply make a similar directory structure to the others, then create an init.el file (e.g. ~/emacs/graphene/.emacs.d/init.el) containing the code from the graphene installation instructions, then run emacs (e.g. env HOME=$HOME/emacs/graphene emacs), and finish the remainder of the installation instructions.
The down-side to this technique is that Emacs won't see all your other dot files (because it will be looking in $HOME), and so running other processes from within Emacs won't necessarily work as normal; but that's not likely to be a huge issue if you're just experimenting, and you can always symlink or copy the bits you need.
You may even prefer it that way -- the benefit is that if anything in the distribution you're trialing writes files to the home directory, it's not going to clobber your real files.
This may also be a useful approach when upgrading Emacs to a new release (if you can run both the old and the new versions side by side) as you could set up a copy of your existing config to use with the new Emacs until you're convinced everything is working, and you can edit the new config without the risk of breaking your existing one. Or flip that around, and instead keep the original config in the new/alternate location, in case you need it as a back-up.
You can symlink ~/.emacs.d, this is what I do
1) Try to keep my emacs configuration ~/.emacs.d oriented i.e. all the config files should live in that folder. For example I use workgroups2, by default it stores workgroup configuration in ~/.emacs_workgroups but I have configured it to store configuration in ~/.emacs.d/workgroups, so my entire emacs configuration is in just one folder.
2) Then I have an ~/emacs_configs folder where all config folders (basically a folder with a init.el and rest of the configuration) live, so my personal config folder will be ~/emacs_configs/iqbal, a prelude distribution will be in ~/emacs_configs/prelude
3) Then finally I symlink ~/.emacs.d to the configuration I actually want to use, eg. to use my configuration I will do ln -s ~/emacs_configs/iqbal .emacs.d. If you want to tryout some configuration just copy the configuration folder to ~/emacs_configs/whatever_name and change the symlink
Hope this helps
I create ~/.emacs.1.d/init.el file , and give it content:
(setq user-emacs-directory "~/.emacs.1.d/")
then , start emacs like this emacs -q -l ~/.emacs.1.d/init.el , now emacs used new configration.
success!!
-q is means skip the default configration ~/.emacs.d/init.el
-l is means load new configration
You can do this with chemacs2. This is the primary (only?) usecase of chemacs2.

Load plugin from specific location

In my computer I have an Emacs plugin installed with the Debian package system, but this plugin is obsolete and I'm trying to install it inside my home directory with package-install. I have installed a newer version, but if I check which version is loaded, the older one is.
I tried with load-file and the global path to the new version, but it still loads the old version.
How can I force the load of the new one? Please, imagine that I'm not the sysadmin of the computer and I cannot uninstall any software package.
When a library contains multiple files one can assume that a single main file will load the others as necessary; but if the directory isn't in the load-path then it won't be able to load them (or at least not those versions), so load-file on its own isn't going to do the trick.
I don't make much use of package.el myself, but I'd really have thought that it would manage the load-path such that it took precedence over anything in site-lisp (which is presumably where the debian package is installing things.)
Try running emacs --no-site-lisp and check that the correct version of the library is loaded. If you don't want anything from the site libraries, then that might even be your solution.
If that works, then check the load-path variable after starting Emacs normally. Unless an absolute path is given, Emacs will look at those directories in sequence, and use the first one which matches. I am guessing that for some reason your site-lisp directory is appearing before the one created by package.el.
Or perhaps the package didn't install correctly at all.
That all said, in Emacs 24.3 at least (package-initialize) is called automatically and I don't think you should need to manually load anything. Check the package-load-list variable.
Edit:
On that last note, refer to cannot open load dired-details.
At the time I hadn't noticed that Emacs doesn't initialize packages until after the user init file has loaded, so you generally will need to initialize them manually in your init file.
Try this
(defun please-load-my-stuff ()
(interactive)
(load "PATH-TO-STUFF/STUFF))
When having access to init, put just form "(load ...)" there.
If more than one file is needed, load-path must be set also that way - before load, so the other required files are accessible.