How to mask an already installed Emacs package? - emacs

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

Related

Emacs packages, installing globally versus locally with elpa

I run linux and use different user names to segment different activities.
Using elpa, there are some packages that I would like to install so that they get loaded no matter who the user, there are packages that I would like to be loaded for only one user.
Org-mode for example is something I would want to be loaded by every user.
C++ related packages I might want for user client1, but not ruby packages.
I might want ruby related packages for user client2, but not C++ packages.
There might be a new package for C++ programming that I do not want to include in serious work but want to play with using user experimental.
It used to be that global stuff you put in site lisp and local stuff you put someplace in ~, but that doesn't seem to work with elpa.
package.el looks for installed packages along the package-directory-list path (additionally to package-user-dir which is where packages get installed).
So I'd recommend you arrange to have a "global" user. And then change all other users to include
(require 'package)
(push "/home/globaluser/.emacs.d/elpa" package-directory-list)
in their ~/.emacs. This way, any package that you want to install for all users should be installed by globaluser.
BTW, another way to attack the vector is to distinguish "installed" and "enabled". I.e. always install your packages globally, and then have each user tweak its package-load-list in order to disable specific packages.
Finally any package whose mere installation&enabling (where "enabling" means to load the package's own -autoloads.el) ends up interfering with normal work is a bug (in my book), so yet another solution is to just install and enable all packages globally. And if the C++-using-user gets annoyed by some ruby-related packages, then file a bug report to the maintainer of the ruby-related package.

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

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.

Delete built-in packages in Emacs

Is it possible to remove built-in Emacs packages like "tetris"? They can't be marked to be deleted in package list as of 24.1. It would be nice to have a minimal installation of Emacs - even though barely useful - by deleting some or all built-in packages. Is it possible to do somehow, and will this ability added in future?
Emacs should start and be useable even if the whole lisp directory is empty (note that we rarely/never test it, so I don't guarantee that it'll work, but at least in principle it should and if it doesn't you should report it with M-x report-emacs-bug). So feel free to remove any and all packages in there you don't find useful, in order to create a trimmed-down version of Emacs.
You could just remove the elc files of all of the packages you want.
For example, in the version of emacs located in the ubuntu repository the tetris package is located in:
/usr/share/emacs/23.3/lisp/play/tetris.elc
If you move or remove it, emacs will continue to work, but you won't be able to play tetris anymore.
You might want to inspect the package--builtins variable. That said - there is little sense in removing any packages installed via package.el since package.el extracts and loads automatically only a package's autoloads - therefore having many installed packages doesn't result in any significant overhead. I'm quite certain that removing built-in packages will never be a feature of package.el.