emacs el-get does not load packages - emacs

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).

Related

use-package does not download packages

I don't quite get the use-package package. I thought of it as a replacement of the older require statement in config files but on github it reads
This loads in the package XYZ, but only if XYZ is available on your system
So do I have to ensure that I have the package before?
Because sometimes it seems, all I need is the use-package statement for a fresh Emacs install to get the dependency.
Please clarify.
I think the point is to let you share your init.el across systems and simply have it ignore packages which are not available on any particular system.
It also appears to allow you to specify, but defer the evaluation of, your own customizations for any package you use until the package is actually loaded, so unlike require, it doesn't force you to load a package you are not going to use in this session.
There is a facility for requiring a package to be installed if it's not installed; look for the :ensure keyword and the use-package-always-ensure configuration variable in the documentation.

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

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.

How to save a list of all the installed packages in Emacs 24?

I am using prelude as a base Emacs configuration.
I have installed lots of packages from the package manager, and I want to use my settings on another machine.
I don't want to carry the installed packages and also I don't want to create a list manually.
What is the way of saving a list all the installed packages into prelude-package.el or any other file so that when I take this configuration to my other machine, they automatically get installed there on first use?
You can get a list of currently installed packages (excluding built in packages) from the variable package-activated-list. To automatically install them on startup, see this question: how to automatically install emacs packages by specifying a list of package names?
More specifically, if you do C-h v package-activated-list, copy the value shown, and insert it as the value of prelude-packages, emacs will automatically ensure those packages are installed on start up.
The canonical method is the best (described by ataylor). Here is a more clumsy method.
M-x list-packages. C-s installed till you find the first row of installed package. Start selecting with C-SPC. Go down till you reach built-in packages. Copy with M-w. C-x b for new buffer. Paste with C-y.C-x C-s to save file.
The only advantage that I see is this is a tad more descriptive — it shows a short description of your packages; which is useful when you install some packages and forget about them.
As mentioned at how to automatically install emacs packages by specifying a list of package names?, it would be better to also record the version of the package you need. In order to do so, you can use the following function:
(defun list-packages-and-versions ()
"Returns a list of all installed packages and their versions"
(mapcar
(lambda (pkg)
`(,pkg ,(package-desc-version
(cadr (assq pkg package-alist)))))
package-activated-list))
That will give you a list of (NAME VERSION) pairs. Unfortunately, I haven't been able to find a way to install a specific version of a package. It seems package.el always grabs the latest available. What I'm doing now is:
(defun install-packages-with-specific-versions (package-version-list)
"Install the packages in the given list with specific versions.
PACKAGE-VERSION-LIST should be a list of (NAME VERSION) lists,
where NAME is a symbol identifying the package and VERSION is
the minimum version to install."
(package-download-transaction
(package-compute-transaction () package-version-list)))
I've written a longer function to install packages matching the exact version number, but it fails because package.el by default only retrieves the latest versions available for each package. gist
As described above, using emacs normal mode. Here another the evil-mode way of doing it:
M-x list-packages; /installed (they will be highlighted); v (for visual-mode); j (to select them); y (to copy them); open a new buffer and paste them.

el-get in a portable emacs configuration solution

el-get goes a long way in helping achieve a portable emacs configuration setup. The idea is to declare the packages you want in the emacs config file, push that file to a repo, and pull it on all the computers where you want an identical emacs configuration. This is how the code might look in elisp:
(setq my-packages (append '(el-get switch-window yasnippet ...)
(mapcar 'el-get-source-name el-get-sources)))
(el-get 'sync my-packages)
el-get will make sure that the packages get automatically installed and properly initialized. However, my understanding is that when you dereference a package, it doesn't get uninstalled. And if you uninstall it manually, you'll have to do it across all the computers, also manually. In other words, el-get goes only half the way in achieving a truly portable solution. My question is if anybody has written elisp code that will uninstall the packages just by dereferencing them in init.el? Or whether I should look elsewhere for a fully portable declarative dependency management solution for emacs?
I'm answering myself here because in the end I opted for an alternate solution.
phils' answer is still valid, but I found it troublesome to have the .emacs.d directory under version control, and to be fair I didn't want to bother with fake submodules.
What I did instead: I contacted el-get's maintainer, Dimitri, and presented him with the problem.
Dimitri said:
I could see us adding an el-get-cleanup function that you would have to call with the current list of packages and that would el-get-remove any package already installed locally but not on the provided list.
(el-get-cleanup my-packages)
You could then use that from your user-init-file if you want to, or do
that as a routine every now and then.
With his guidance, I then wrote the function in question.
(defun el-get-cleanup (packages)
"Remove packages not explicitly declared"
(let* ((packages-to-keep (el-get-dependencies (mapcar 'el-get-as-symbol packages)))
(packages-to-remove (set-difference (mapcar 'el-get-as-symbol
(el-get-list-package-names-with-status
"installed")) packages-to-keep)))
(mapc 'el-get-remove packages-to-remove)))
Ah, the joys of open source...
(See also my blog post)
You should use el-get in conjunction with some form of version control. That provides the portability, so that when you remove a package and commit the result to your repository, the package will also be uninstalled for the other instances once they have pulled those changes.
If you are leaving the package files to el-get to manage, then those files may still exist on the other copies after the package is removed from one instance but, provided that el-get's status and autoload files are in your repo, I think the state of each package should be correct.
Personally, I recommend committing all files to your repository after installing a package. That way when you remove a package, commit the changes, and pull those changes from another instance, both copies are in the same state.
Moreover, I would never trust the availability, consistency, or permanence of a remote source when it comes to setting up a new instance of my Emacs configuration -- the act of cloning my repository is all that should be required to obtain a working system.
So: use el-get for installing and updating packages, and use version control to make it portable.